diff options
-rw-r--r-- | default.nix | 54 | ||||
-rwxr-xr-x | scripts/assert-nixfmt.sh | 16 | ||||
-rwxr-xr-x | scripts/assert-shellcheck.sh | 6 | ||||
-rwxr-xr-x | scripts/assert-terraform.sh | 10 | ||||
-rwxr-xr-x | scripts/assert-todos.sh | 43 | ||||
-rwxr-xr-x | tests.sh | 11 |
6 files changed, 106 insertions, 34 deletions
diff --git a/default.nix b/default.nix index 039119f..ae37a1f 100644 --- a/default.nix +++ b/default.nix @@ -1,37 +1,23 @@ -let pkgs = import <nixpkgs> { }; -in rec { - utils = import ./utils.nix { - pkgs = pkgs; - src = pkgs.nix-gitignore.gitignoreSource [ ] ./.; - baseName = "vps"; +let + niv-sources = import ./nix/sources.nix; + pkgs = import niv-sources.nixpkgs { }; + src = pkgs.nix-gitignore.gitignoreSource [ "!.git" ] ./.; + projectBuildInputs = with pkgs; [ + ]; +in { + test = pkgs.stdenv.mkDerivation { + inherit src; + name = "vps-test"; + phases = [ "unpackPhase" "buildPhase" ]; + buildInputs = projectBuildInputs; + buildPhase = '' + patchShebangs . + ./tests.sh + touch $out + ''; }; - subtasks = rec { - formatTerraform = utils.baseTask.overrideAttrs (baseAttrs: { - name = "${baseAttrs.name}-format-terraform"; - buildInputs = baseAttrs.buildInputs ++ [ pkgs.terraform ]; - buildPhase = '' - terraform fmt -check=true -diff=true || { - echo "Terraform files are unformatted. To fix it, run:" - echo " terraform fmt" - exit 1 - } - touch $out - ''; - }); - shellBuildInputs = with pkgs; [ - gitMinimal - git-crypt - gettext - terraform-providers.vultr - terraform - ]; + shell = pkgs.mkShell { + name = "vps-shell"; + buildInputs = projectBuildInputs; }; - test = utils.test [ - (utils.shellcheck null) - (utils.fixme null) - (utils.shellEnvironmentBuild subtasks.shellBuildInputs) - (utils.formatNix null) - subtasks.formatTerraform - ]; - shell = utils.shellEnvironment subtasks.shellBuildInputs; } diff --git a/scripts/assert-nixfmt.sh b/scripts/assert-nixfmt.sh new file mode 100755 index 0000000..7a68fa9 --- /dev/null +++ b/scripts/assert-nixfmt.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" +cd ../ + +format() { + nix_file="${1}" + diff <(nixfmt < "${nix_file}") "${nix_file}" || { + echo "The file '${nix_file}' is unformatted. To fix it, run:" + echo " nixfmt ${nix_file}" + exit 1 + } +} +export -f format + +find . -type f -name '*.nix' -print0 | xargs -0 -I% bash -c "format %" diff --git a/scripts/assert-shellcheck.sh b/scripts/assert-shellcheck.sh new file mode 100755 index 0000000..e24c29c --- /dev/null +++ b/scripts/assert-shellcheck.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" +cd ../ + +git ls-files | grep '\.sh$' | xargs shellcheck diff --git a/scripts/assert-terraform.sh b/scripts/assert-terraform.sh new file mode 100755 index 0000000..8f03d7f --- /dev/null +++ b/scripts/assert-terraform.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" +cd ../ + +terraform fmt -check=true -diff=true || { + echo "Terraform files are unformatted. To fix it, run:" + echo " terraform fmt" + exit 1 +} diff --git a/scripts/assert-todos.sh b/scripts/assert-todos.sh new file mode 100755 index 0000000..c3139d1 --- /dev/null +++ b/scripts/assert-todos.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" +cd ../ + +# shellcheck disable=2046 +if grep -R FIXME $(git ls-files) | grep -v '^TODOs.org' | grep -v '^.git/' | grep -v '^scripts/assert-todos.sh'; then + echo "Found dangling FIXME markers on the project." + echo "You should write them down properly on TODOs.org." + exit 1 +fi + +contains-element() { + local e match="$1" + shift + for e; do [[ "$e" == "$match" ]] && return 0; done + return 1 +} + +KNOWN_IDS=() +has_error=0 +# shellcheck disable=2013 +for todo in $(sed -e '/^\* Tasks$/,/^\* Improvements$/!d' TODOs.org | grep -nE '^\*\* .*$' | cut -d: -f1); do + if grep -E '^\*\* (CANCELLED|DONE)' <(sed "${todo}q;d" TODOs.org) > /dev/null; then + ID_OFFSET=3 + else + ID_OFFSET=2 + fi + ID="$(sed "$((todo+ID_OFFSET))q;d" TODOs.org)" + if grep '^:CUSTOM_ID: .*$' <(echo "$ID") > /dev/null; then + if contains-element "$ID" "${KNOWN_IDS[@]}"; then + echo "Duplicated ID: $ID" + has_error=1 + else + KNOWN_IDS+=("$ID") + fi + else + echo "Missing ID for TODO in line $todo" + has_error=1 + fi +done + +exit "$has_error" diff --git a/tests.sh b/tests.sh new file mode 100755 index 0000000..0260b47 --- /dev/null +++ b/tests.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")" + +set -x + +./scripts/assert-nixfmt.sh +./scripts/assert-shellcheck.sh +./scripts/assert-todos.sh + +./scripts/assert-terraform.sh |