diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2980b92..3d9c4ac 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -33,10 +33,9 @@ jobs: run: docker build -t bootstrap-script-test-fish -f ./bootstrap-test.Dockerfile . --build-arg SHELL_VAR=fish - name: Run bats-fish test via devbox run: docker run bootstrap-script-test-fish bats test/bootstrap-agnostic.bats test/bootstrap-fish.bats - nix-flake-check: + check-linting-and-formatting: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Install Nix - uses: DeterminateSystems/nix-installer-action@main - - run: nix flake check --keep-going --print-build-logs + - uses: jetpack-io/devbox-install-action@v0.7.0 + - run: devbox run lint diff --git a/README.md b/README.md index 5b08603..4189168 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,13 @@ Devbox is something we're trialing internally, we need some plugins. So putting This repo is public as it's only used to configure open source software, there will likely be a bit of company specific stuff in here but nothing sensitive. Once we're happy with there plugins we'll attempt to upstream them as appropriate. + +# Formatting and linting + +```sh +# check formatting and linting +devbox run lint + +# autofix (where possible) formatting and linting +devbox run lint:fix +``` diff --git a/devbox.json b/devbox.json index 94014d7..acdcf73 100644 --- a/devbox.json +++ b/devbox.json @@ -14,6 +14,18 @@ ], "shell": { "scripts": { + "lint": [ + "nixpkgs-fmt --check . &", + "statix check --ignore .devbox &", + "shellcheck **/*.{sh,bats} &", + "shfmt --diff **/*.{sh,bats} &", + "wait" + ], + "lint:fix": [ + "nixpkgs-fmt .", + "statix fix --ignore .devbox", + "shfmt --write **/*.{sh,bats}" + ], "test": [ "devbox run test-bash", "devbox run test-zsh", diff --git a/flake.nix b/flake.nix index 285f038..c2fbdb1 100644 --- a/flake.nix +++ b/flake.nix @@ -10,46 +10,11 @@ flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { system = "${system}"; config.allowUnfree = true; }; - - # common parts of making derivations for flake checks - # from: https://msfjarvis.dev/posts/writing-your-own-nix-flake-checks/ - mkCheck = { name, nativeBuildInputs, checkPhase }: pkgs.stdenvNoCC.mkDerivation { - inherit name nativeBuildInputs checkPhase; - src = ./.; - dontBuild = true; - doCheck = true; - installPhase = '' - mkdir "$out" - ''; - }; in { # set formatter binary for `nix fmt` command formatter = pkgs.nixpkgs-fmt; - checks = { - nix-formatting = mkCheck { - name = "nix-formatting"; - nativeBuildInputs = [ pkgs.nixpkgs-fmt ]; - checkPhase = "nixpkgs-fmt --check ."; - }; - nix-linting = mkCheck { - name = "nix-linting"; - nativeBuildInputs = [ pkgs.statix ]; - checkPhase = "statix check"; - }; - shell-linting = mkCheck { - name = "shell-linting"; - nativeBuildInputs = [ pkgs.shellcheck ]; - checkPhase = "shellcheck **/*.{sh,bash,bats}"; - }; - shell-formatting = mkCheck { - name = "shell-formatting"; - nativeBuildInputs = [ pkgs.shfmt ]; - checkPhase = "shfmt --write **/*.{sh,bash,bats}"; - }; - }; - packages = { mongodb-4_4 = pkgs.callPackage ./packages/mongodb-4_4.nix { }; dynamodb_local = pkgs.callPackage ./packages/dynamodb_local.nix { };