Skip to content

Commit 870cc53

Browse files
committed
ci: run build, test, lint and format as nix flake checks
Adopt kradalby/flake-checks: flake.nix exposes build, gotest, golangci-lint and formatting checks over one shared, fileset-filtered source set, and nix-checks.yml gates each with nix build .#checks.<system>.<name>. Drop test.yml and lint.yml — gotestsum, golangci-lint and prettier are now those checks. golangci-lint runs full-tree; Go formatting stays in it while formatting adds prettier.
1 parent 7c87c7f commit 870cc53

5 files changed

Lines changed: 195 additions & 124 deletions

File tree

.github/workflows/lint.yml

Lines changed: 0 additions & 75 deletions
This file was deleted.

.github/workflows/nix-checks.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Nix Flake Checks
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }}
13+
cancel-in-progress: true
14+
15+
# Each job only runs `nix build .#checks.<system>.<name>`; the check logic lives
16+
# in flake.nix via the flake-checks library. The fileset-filtered checks hit the
17+
# hestia cache when their inputs are unchanged, so no changed-files gating.
18+
permissions:
19+
contents: read
20+
21+
jobs:
22+
build:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
26+
- uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main
27+
- uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main
28+
- name: build
29+
run: nix build -L .#checks.x86_64-linux.build
30+
31+
gotest:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
35+
- uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main
36+
- uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main
37+
- name: gotest
38+
run: nix build -L .#checks.x86_64-linux.gotest
39+
40+
golangci-lint:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
44+
- uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main
45+
- uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main
46+
- name: golangci-lint
47+
run: nix build -L .#checks.x86_64-linux.golangci-lint
48+
49+
formatting:
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
53+
- uses: NixOS/nix-installer-action@6b8548fe06acfb0155a50ab5d561accb215764cc # main
54+
- uses: Mic92/hestia/action@ff07bb902a9968ac0c3d0e51d90a606662a375d8 # main
55+
- name: formatting
56+
run: nix build -L .#checks.x86_64-linux.formatting

.github/workflows/test.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

flake.lock

Lines changed: 78 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
# once it ships go_1_26 >= 1.26.4.
1010
nixpkgs.url = "github:NixOS/nixpkgs/staging-next-26.05";
1111
flake-utils.url = "github:numtide/flake-utils";
12+
# Reusable Go flake checks (build/test/lint/format); CI runs them via
13+
# `nix build .#checks.<system>.<name>` instead of bespoke per-tool steps.
14+
flake-checks.url = "github:kradalby/flake-checks";
15+
flake-checks.inputs.nixpkgs.follows = "nixpkgs";
1216
};
1317

1418
outputs =
1519
{ self
1620
, nixpkgs
1721
, flake-utils
22+
, flake-checks
1823
, ...
1924
}:
2025
let
@@ -176,6 +181,58 @@
176181
contents = [ pkgs.headscale ];
177182
config.Entrypoint = [ (pkgs.headscale + "/bin/headscale") ];
178183
};
184+
185+
# Go flake checks from the flake-checks library. CI gates on
186+
# `nix build .#checks.<system>.<name>`; the logic lives here, not in
187+
# bespoke workflow steps. Linux-only: parts of the tree are
188+
# Linux-specific and the pure unit subset is validated by CI.
189+
fc = flake-checks.lib;
190+
common = {
191+
inherit pkgs;
192+
root = ./.;
193+
pname = "headscale";
194+
version = headscaleVersion;
195+
vendorHash = (builtins.fromJSON (builtins.readFile ./flakehashes.json)).vendor.sri;
196+
goPkg = pkgs.go_1_26;
197+
# //go:embed targets and test-read files outside the default whitelist.
198+
embedDirs = [ ./hscontrol/assets ./hscontrol/db/schema.sql ./config-example.yaml ];
199+
extraSrc = [
200+
./hscontrol/testdata
201+
./hscontrol/types/testdata
202+
./hscontrol/db/testdata
203+
./hscontrol/policy/v2/testdata
204+
];
205+
};
206+
goChecks = {
207+
build = fc.goBuild (common // { subPackages = [ "cmd/headscale" ]; });
208+
209+
# The pure unit subset. ./integration (Docker) and
210+
# ./hscontrol/servertest (binds loopback sockets) are dropped from the
211+
# test set but kept in source so cmd/hi and friends still compile;
212+
# TestPostgres* needs a server (the SQLite equivalents still run).
213+
# CGO off matches the build.
214+
gotest = fc.goTest (common // {
215+
testExclude = [ "/integration" "/hscontrol/servertest" ];
216+
goSkip = [ "TestPostgres" ];
217+
testEnv = "export CGO_ENABLED=0";
218+
});
219+
220+
# Full-tree golangci-lint (golines, gofumpt, etc.); uses the overlay's
221+
# golangci-lint built against the pinned Go.
222+
golangci-lint = fc.goLint common;
223+
224+
# nixpkgs-fmt + prettier, excluding generated output. goFmt = "off":
225+
# Go formatting (golines, gofumpt) is enforced by the golangci-lint
226+
# check, not treefmt. prettierExts matches the old prettier-lint glob
227+
# (no json: testdata fixtures are hand-formatted).
228+
formatting = fc.goFormat (common // {
229+
goFmt = "off";
230+
prettier = true;
231+
prettierExts = [ "ts" "js" "md" "yaml" "yml" "sass" "css" "scss" "html" ];
232+
# Mirror .prettierignore (docs/ are mkdocs-flavoured; gen/ generated).
233+
fmtExclude = [ ./gen ./docs ];
234+
});
235+
};
179236
in
180237
{
181238
# `nix develop`
@@ -221,6 +278,9 @@
221278

222279
checks = {
223280
headscale = pkgs.testers.nixosTest (import ./nix/tests/headscale.nix);
224-
};
281+
}
282+
# The Go build/test checks are gated to Linux: parts of the tree are
283+
# Linux-specific and the pure unit subset is validated by CI.
284+
// pkgs.lib.optionalAttrs pkgs.stdenv.isLinux goChecks;
225285
});
226286
}

0 commit comments

Comments
 (0)