Skip to content

Commit

Permalink
all: use nix flake check for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
zombiezen committed Dec 3, 2023
1 parent 678f6a3 commit 0f2eb4f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
31 changes: 2 additions & 29 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
, git
, pandoc
, commit ? null
, doCheck ? false
}:

let
Expand Down Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 // {
Expand All @@ -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;
}
);
}

0 comments on commit 0f2eb4f

Please sign in to comment.