Skip to content

Commit df8f1c1

Browse files
maru-avarkuris
andauthored
feat: Add just task runner to ensure reproducibility of CI (#1345)
As a follow-on to #1319, this PR introduces the [just](https://github.com/casey/just) command runner to ensure the new CI ffi-nix CI job can be trivially reproduced locally. --------- Co-authored-by: Ron Kuris <[email protected]>
1 parent fc48a6d commit df8f1c1

File tree

7 files changed

+177
-18
lines changed

7 files changed

+177
-18
lines changed

.github/check-license-headers.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
"cliff.toml",
5454
"clippy.toml",
5555
"**/tests/compile_*/**",
56+
"justfile",
57+
"scripts/run-just.sh",
5658
],
5759
}
5860
]

.github/workflows/ci.yaml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,10 @@ jobs:
251251
- uses: actions/checkout@v4
252252
- uses: DeterminateSystems/nix-installer-action@786fff0690178f1234e4e1fe9b536e94f5433196 #v20
253253
- uses: DeterminateSystems/magic-nix-cache-action@565684385bcd71bad329742eefe8d12f2e765b39 #v13
254-
- name: Test build equivalency between Nix and Cargo
255-
run: bash -x ./ffi/test-build-equivalency.sh
256-
- name: Test Go FFI bindings
257-
working-directory: ffi
258-
# - cgocheck2 is expensive but provides complete pointer checks
259-
# - use hash mode ethhash since the flake builds with `--features ethhash,logger`
260-
# - run golang outside a nix shell to validate viability without the env setup performed by a nix shell
261-
run: |
262-
GOLANG="nix run $PWD#go"
263-
cd result/ffi
264-
GOEXPERIMENT=cgocheck2 TEST_FIREWOOD_HASH_MODE=ethhash ${GOLANG} test ./...
265-
shell: bash
254+
- name: Check that FFI flake is up-to-date
255+
run: ./scripts/run-just.sh check-ffi-flake
256+
- name: Test nix build of Golang FFI bindings
257+
run: ./scripts/run-just.sh test-ffi-nix
266258

267259
firewood-ethhash-differential-fuzz:
268260
needs: build

ffi/flake.lock

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

ffi/flake.nix

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,25 @@
116116
program = "${go}/bin/go";
117117
};
118118

119+
apps.jq = {
120+
type = "app";
121+
program = "${pkgs.jq}/bin/jq";
122+
};
123+
124+
apps.just = {
125+
type = "app";
126+
program = "${pkgs.just}/bin/just";
127+
};
128+
119129
devShells.default = craneLib.devShell {
120130
inputsFrom = [ firewood-ffi ];
121131

122132
packages = with pkgs; [
123133
firewood-ffi
124-
rustToolchain
125134
go
135+
jq
136+
just
137+
rustToolchain
126138
];
127139

128140
shellHook = ''

ffi/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ go 1.24
44

55
// Changes to the toolchain version should be replicated in:
66
// - ffi/go.mod (here)
7-
// - ffi/flake.nix (update golang.url to a version of avalanchego's nix/go/flake.nix that uses the desired version)
7+
// - ffi/flake.nix (update golang.url to a version of avalanchego's nix/go/flake.nix that uses the desired version and run `just update-ffi-flake`)
88
// - ffi/tests/eth/go.mod
99
// - ffi/tests/firewood/go.mod
10+
// `just check-golang-version` validates that these versions are in sync and will run in CI as part of the ffi-nix job.
1011
toolchain go1.24.9
1112

1213
require (

justfile

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# List available recipes
2+
default:
3+
./scripts/run-just.sh --list
4+
5+
# Build ffi with nix
6+
build-ffi-nix: check-nix
7+
cd ffi && nix build
8+
9+
# Check if the git branch is clean
10+
check-clean-branch:
11+
#!/usr/bin/env bash
12+
set -euo pipefail
13+
14+
git add --all
15+
git update-index --really-refresh >> /dev/null
16+
17+
# Show the status of the working tree.
18+
git status --short
19+
20+
# Exits if any uncommitted changes are found.
21+
git diff-index --quiet HEAD
22+
23+
# Check if the FFI flake is up-to-date (requires clean git tree)
24+
check-ffi-flake: check-nix
25+
#!/usr/bin/env bash
26+
set -euo pipefail
27+
./scripts/run-just.sh update-ffi-flake
28+
./scripts/run-just.sh check-clean-branch
29+
30+
# Check if the golang version is set consistently (requires clean git tree)
31+
check-golang-version: check-nix
32+
#!/usr/bin/env bash
33+
set -euo pipefail
34+
35+
# Exit only at the end if any of the checks set FAILED=1
36+
FAILED=
37+
38+
cd ffi
39+
40+
TOOLCHAIN_VERSION=$(nix develop --command bash -c "go mod edit -json | jq -r '.Toolchain'")
41+
echo "toolchain version in ffi/go.mod is ${TOOLCHAIN_VERSION}"
42+
43+
ETH_TESTS_VERSION=$(nix develop --command bash -c "cd tests/eth && go mod edit -json | jq -r '.Toolchain'")
44+
echo "toolchain version in ffi/tests/eth/go.mod is ${ETH_TESTS_VERSION}"
45+
46+
if [[ "${TOOLCHAIN_VERSION}" != "${ETH_TESTS_VERSION}" ]]; then
47+
echo "❌ toolchain version in ffi/tests/eth/go.mod should be ${TOOLCHAIN_VERSION}"
48+
FAILED=1
49+
fi
50+
51+
FIREWOOD_TESTS_VERSION=$(nix develop --command bash -c "cd tests/firewood && go mod edit -json | jq -r '.Toolchain'")
52+
echo "toolchain version in ffi/tests/firewood/go.mod is ${FIREWOOD_TESTS_VERSION}"
53+
54+
if [[ "${TOOLCHAIN_VERSION}" != "${FIREWOOD_TESTS_VERSION}" ]]; then
55+
echo "❌ toolchain version in ffi/tests/firewood/go.mod should be ${TOOLCHAIN_VERSION}"
56+
FAILED=1
57+
fi
58+
59+
NIX_VERSION=$(nix run .#go -- version | awk '{print $3}')
60+
echo "golang provided by ffi/flake.nix is ${NIX_VERSION}"
61+
62+
if [[ "${TOOLCHAIN_VERSION}" != "${NIX_VERSION}" ]]; then
63+
echo "❌ golang provided by ffi/flake/nix should be ${TOOLCHAIN_VERSION}"
64+
echo "It will be necessary to update the golang.url in ffi/flake.nix to point to a SHA of"\
65+
"AvalancheGo whose nix/go/flake.nix provides ${TOOLCHAIN_VERSION}."
66+
fi
67+
68+
if [[ -n "${FAILED}" ]]; then
69+
exit 1
70+
fi
71+
72+
# Check if nix is installed
73+
check-nix:
74+
#!/usr/bin/env bash
75+
set -euo pipefail
76+
if ! command -v nix &> /dev/null; then
77+
echo "Error: 'nix' is not installed." >&2
78+
echo "" >&2
79+
echo "To install nix:" >&2
80+
echo " - Visit: https://github.com/DeterminateSystems/nix-installer" >&2
81+
echo " - Or run: curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install" >&2
82+
exit 1
83+
fi
84+
85+
# Run all checks of ffi built with nix
86+
test-ffi-nix: test-ffi-nix-build-equivalency test-ffi-nix-go-bindings
87+
88+
# Test ffi build equivalency between nix and cargo
89+
test-ffi-nix-build-equivalency: check-nix
90+
#!/usr/bin/env bash
91+
set -euo pipefail
92+
93+
echo "Testing ffi build equivalency between nix and cargo"
94+
95+
bash -x ./ffi/test-build-equivalency.sh
96+
97+
# Test golang ffi bindings using the nix-built artifacts
98+
test-ffi-nix-go-bindings: build-ffi-nix
99+
#!/usr/bin/env bash
100+
set -euo pipefail
101+
102+
echo "running ffi tests against bindings built by nix..."
103+
104+
cd ffi
105+
106+
# Need to capture the flake path before changing directories to
107+
# result/ffi because `result` is a nix store symlink so ../../
108+
# won't resolve to the ffi path containing the flake.
109+
FLAKE_PATH="$PWD"
110+
111+
# This runs golang outside a nix shell to validate viability
112+
# without the env setup performed by a nix shell
113+
GO="nix run $FLAKE_PATH#go"
114+
115+
cd result/ffi
116+
117+
# - cgocheck2 is expensive but provides complete pointer checks
118+
# - use hash mode ethhash since the flake builds with `--features ethhash,logger`
119+
GOEXPERIMENT=cgocheck2 TEST_FIREWOOD_HASH_MODE=ethhash ${GO} test ./...
120+
121+
# Ensure the FFI flake is up-to-date
122+
update-ffi-flake: check-nix
123+
#!/usr/bin/env bash
124+
set -euo pipefail
125+
cd ffi
126+
127+
echo "ensuring flake lock file is current for golang"
128+
nix flake update golang
129+
130+
echo "checking for a consistent golang verion"
131+
../scripts/run-just.sh check-golang-version

scripts/run-just.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if command -v just &> /dev/null; then
5+
exec just "$@"
6+
elif command -v nix &> /dev/null; then
7+
exec nix run nixpkgs#just -- "$@"
8+
else
9+
echo "Error: Neither 'just' nor 'nix' is installed." >&2
10+
echo "" >&2
11+
echo "Please install one of the following:" >&2
12+
echo "" >&2
13+
echo "Option 1 - Install just:" >&2
14+
echo " - Visit: https://github.com/casey/just#installation" >&2
15+
echo " - Or use cargo: cargo install just" >&2
16+
echo "" >&2
17+
echo "Option 2 - Install nix:" >&2
18+
echo " - Visit: https://github.com/DeterminateSystems/nix-installer" >&2
19+
echo " - Or run: curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install" >&2
20+
exit 1
21+
fi

0 commit comments

Comments
 (0)