diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bf244dc..a257c7a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,38 +24,20 @@ jobs: linux: name: Linux runs-on: ubuntu-latest - strategy: - matrix: - git: - - "2.27.0" # latest - - "2.25.1" # Ubuntu LTS 20.04 focal - - "2.20.1" # Debian buster - - "2.17.1" # Ubuntu LTS 18.04 bionic steps: - name: Check out code uses: actions/checkout@v3 - name: Install Nix uses: cachix/install-nix-action@v22 - name: Run tests - run: | - git_attr="git_$(echo "$GIT_VERSION" | sed -e 's/\./_/g')" - nix shell ".#$git_attr" '.#default.go' --command \ - go test \ - -mod=readonly \ - -v \ - -race \ - ./... - env: - GIT_VERSION: ${{ matrix.git }} + run: nix flake check - name: Build binary run: nix develop --command release/build.bash gg - if: matrix.git == '2.27.0' - name: Upload binary uses: actions/upload-artifact@v3 with: name: Linux binary path: gg - if: matrix.git == '2.27.0' mac: name: macOS runs-on: macOS-latest @@ -65,16 +47,7 @@ jobs: - name: Install Nix uses: cachix/install-nix-action@v22 - name: Run tests - run: | - git_attr="git_$(echo "$GIT_VERSION" | sed -e 's/\./_/g')" - nix shell ".#$git_attr" '.#default.go' --command \ - go test \ - -mod=readonly \ - -v \ - -race \ - ./... - env: - GIT_VERSION: "2.27.0" + run: nix flake check - name: Build binary run: nix develop --command release/build.bash gg - name: Upload binary diff --git a/default.nix b/default.nix index 21eaccb..55b4bac 100644 --- a/default.nix +++ b/default.nix @@ -8,6 +8,7 @@ , git , pandoc , commit ? null +, doCheck ? false }: let @@ -47,6 +48,17 @@ in buildGoModule { pandoc --standalone --to man misc/gg.1.md -o misc/gg.1 ''; + inherit doCheck; + checkFlags = [ "-race" ]; + checkPhase = '' + runHook preCheck + export GOFLAGS=''${GOFLAGS//-trimpath/} + + buildGoDir test ./... + + runHook postCheck + ''; + postInstall = '' wrapProgram $out/bin/gg --suffix PATH : ${git}/bin installManPage misc/gg.1 diff --git a/flake.nix b/flake.nix index 330f4e5..2a7aab0 100644 --- a/flake.nix +++ b/flake.nix @@ -14,6 +14,15 @@ gitPackages = (pkgs.lib.attrsets.filterAttrs (k: _: pkgs.lib.strings.hasPrefix "git_" k) gg-git.packages.${system}); + + inherit (pkgs.lib.attrsets) mapAttrs' nameValuePair optionalAttrs; + + mkCheck = git: self.packages.${system}.default.override { + inherit git; + doCheck = true; + }; + + gitChecks = mapAttrs' (name: git: nameValuePair ("with_" + name) (mkCheck git)) gitPackages; in { packages = gitPackages // { @@ -29,15 +38,19 @@ }; devShells.default = pkgs.mkShell { + inputsFrom = [ self.packages.${system}.default ]; + packages = [ pkgs.git pkgs.go-tools # static check pkgs.gotools # stringer, etc. pkgs.python3 - - self.packages.${system}.default.go ]; }; + + checks = { + default = mkCheck pkgs.git; + } // optionalAttrs pkgs.hostPlatform.isLinux gitChecks; } ); }