Skip to content

Commit 3fbee1e

Browse files
committed
build: add support for multiple go versions
Add support for building and testing with multiple Go versions: Flake changes: - Refactored package and test derivations into reusable functions - Added go-jsonschema-go124 and go-jsonschema-go125 packages - Added tests-go124 and tests-go125 check derivations - Extracted cleanSrc for code deduplication GitHub Actions workflow: - Added matrix strategy to test Go 1.24 and 1.25 - Split workflow into test-go-versions and qa jobs - Upload coverage only from Go 1.25 tests - Fail-fast disabled to test all versions This ensures compatibility across supported Go versions and catches version-specific issues early in CI.
1 parent 9500de8 commit 3fbee1e

File tree

2 files changed

+75
-60
lines changed

2 files changed

+75
-60
lines changed

.github/workflows/nix.yaml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ concurrency:
1212
group: ${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}
1313
cancel-in-progress: true
1414
jobs:
15-
qa:
15+
test-go-versions:
1616
runs-on: ubuntu-24.04
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
go-version: ['124', '125']
1721
steps:
1822
- name: Checkout
19-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
23+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcf5dd907a8 # v5
2024
- name: Install Nix
2125
uses: cachix/install-nix-action@v30
2226
with:
@@ -26,14 +30,31 @@ jobs:
2630
uses: cachix/cachix-action@v15
2731
with:
2832
name: devenv
29-
- name: Check Nix flake formatting
30-
run: nix fmt -- --check .
31-
- name: Run Nix flake checks
32-
run: nix flake check --print-build-logs --show-trace
33-
- name: Build package
34-
run: nix build --print-build-logs
33+
- name: Build with Go 1.${{ matrix.go-version }}
34+
run: nix build .#go-jsonschema-go${{ matrix.go-version }} --print-build-logs
35+
- name: Test with Go 1.${{ matrix.go-version }}
36+
run: nix build .#tests-go${{ matrix.go-version }} --print-build-logs
3537
- name: Upload coverage to Codecov
38+
if: matrix.go-version == '125'
3639
uses: codecov/codecov-action@v5
3740
with:
3841
files: ./result/coverage.out
3942
fail_ci_if_error: false
43+
qa:
44+
runs-on: ubuntu-24.04
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcf5dd907a8 # v5
48+
- name: Install Nix
49+
uses: cachix/install-nix-action@v30
50+
with:
51+
extra_nix_config: |
52+
accept-flake-config = true
53+
- name: Setup Cachix
54+
uses: cachix/cachix-action@v15
55+
with:
56+
name: devenv
57+
- name: Check Nix flake formatting
58+
run: nix fmt -- --check .
59+
- name: Run Nix flake checks
60+
run: nix flake check --print-build-logs --show-trace

flake.nix

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,27 @@
2323
config,
2424
pkgs,
2525
...
26-
}: {
27-
packages = {
28-
go-jsonschema = pkgs.buildGoModule {
26+
}: let
27+
cleanSrc = pkgs.lib.cleanSourceWith {
28+
src = ./.;
29+
filter = path: type:
30+
!(pkgs.lib.hasSuffix "go.work" path)
31+
&& !(pkgs.lib.hasSuffix "go.work.sum" path);
32+
};
33+
34+
makePackage = goPackage: let
35+
buildGoModule = pkgs.buildGoModule.override {go = goPackage;};
36+
in
37+
buildGoModule {
2938
pname = "go-jsonschema";
3039
version = "0.0.0-dev";
31-
32-
src = pkgs.lib.cleanSourceWith {
33-
src = ./.;
34-
filter = path: type:
35-
!(pkgs.lib.hasSuffix "go.work" path)
36-
&& !(pkgs.lib.hasSuffix "go.work.sum" path);
37-
};
38-
40+
src = cleanSrc;
3941
vendorHash = "sha256-CBxxloy9W9uJq4l2zUrp6VJlu5lNCX55ks8OOWkHDF4=";
40-
4142
subPackages = ["."];
42-
4343
ldflags = [
4444
"-s"
4545
"-w"
4646
];
47-
4847
meta = with pkgs.lib; {
4948
description = "Generate Go types from JSON Schema";
5049
homepage = "https://github.com/atombender/go-jsonschema";
@@ -53,21 +52,13 @@
5352
};
5453
};
5554

56-
default = config.packages.go-jsonschema;
57-
};
58-
59-
checks = {
60-
go-jsonschema-tests = pkgs.buildGoModule {
55+
makeTests = goPackage: let
56+
buildGoModule = pkgs.buildGoModule.override {go = goPackage;};
57+
in
58+
buildGoModule {
6159
name = "go-jsonschema-tests";
62-
src = pkgs.lib.cleanSourceWith {
63-
src = ./.;
64-
filter = path: type:
65-
!(pkgs.lib.hasSuffix "go.work" path)
66-
&& !(pkgs.lib.hasSuffix "go.work.sum" path);
67-
};
68-
60+
src = cleanSrc;
6961
vendorHash = "sha256-CBxxloy9W9uJq4l2zUrp6VJlu5lNCX55ks8OOWkHDF4=";
70-
7162
buildPhase = ''
7263
export HOME=$TMPDIR
7364
@@ -83,40 +74,43 @@
8374
echo "Generating coverage report..."
8475
go tool covdata textfmt -i=./coverage/tests,./coverage/pkg -o coverage.out
8576
'';
86-
8777
installPhase = ''
8878
mkdir -p $out
8979
cp coverage.out $out/ || true
9080
echo "All tests passed successfully with coverage" > $out/test-results
9181
'';
9282
};
83+
in {
84+
packages = {
85+
go-jsonschema-go124 = makePackage pkgs.go_1_24;
86+
go-jsonschema-go125 = makePackage pkgs.go;
87+
default = makePackage pkgs.go;
88+
};
9389

94-
lint-golang = pkgs.buildGoModule {
95-
name = "lint-golang";
96-
src = pkgs.lib.cleanSourceWith {
97-
src = ./.;
98-
filter = path: type:
99-
!(pkgs.lib.hasSuffix "go.work" path)
100-
&& !(pkgs.lib.hasSuffix "go.work.sum" path);
90+
checks = {
91+
tests-go124 = makeTests pkgs.go_1_24;
92+
tests-go125 = makeTests pkgs.go;
93+
94+
lint-golang = let
95+
buildGoModule = pkgs.buildGoModule.override {go = pkgs.go;};
96+
in
97+
buildGoModule {
98+
name = "lint-golang";
99+
src = cleanSrc;
100+
vendorHash = "sha256-CBxxloy9W9uJq4l2zUrp6VJlu5lNCX55ks8OOWkHDF4=";
101+
nativeBuildInputs = [pkgs.golangci-lint];
102+
buildPhase = ''
103+
export HOME=$TMPDIR
104+
golangci-lint -v run --color=always --config=.rules/.golangci.yml ./...
105+
golangci-lint -v run --color=always --config=.rules/.golangci.yml tests/*.go
106+
golangci-lint -v run --color=always --config=.rules/.golangci.yml tests/helpers/*.go
107+
'';
108+
installPhase = ''
109+
mkdir -p $out
110+
echo "Go linting passed" > $out/result
111+
'';
101112
};
102113

103-
vendorHash = "sha256-CBxxloy9W9uJq4l2zUrp6VJlu5lNCX55ks8OOWkHDF4=";
104-
105-
nativeBuildInputs = [pkgs.golangci-lint];
106-
107-
buildPhase = ''
108-
export HOME=$TMPDIR
109-
golangci-lint -v run --color=always --config=.rules/.golangci.yml ./...
110-
golangci-lint -v run --color=always --config=.rules/.golangci.yml tests/*.go
111-
golangci-lint -v run --color=always --config=.rules/.golangci.yml tests/helpers/*.go
112-
'';
113-
114-
installPhase = ''
115-
mkdir -p $out
116-
echo "Go linting passed" > $out/result
117-
'';
118-
};
119-
120114
lint-dockerfile = pkgs.stdenv.mkDerivation {
121115
name = "lint-dockerfile";
122116
src = ./.;

0 commit comments

Comments
 (0)