Skip to content

Commit b47065b

Browse files
committed
ci: add nix hash workflow
1 parent ee9a5ca commit b47065b

3 files changed

Lines changed: 135 additions & 61 deletions

File tree

.github/workflows/go-ci.yml

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ name: Go CI
22

33
on:
44
push:
5-
branches: [master]
5+
branches:
6+
- '**'
67
pull_request:
7-
branches: [master]
8+
branches:
9+
- '**'
810

911
concurrency:
1012
group: go-ci-${{ github.ref }}
1113
cancel-in-progress: true
1214

1315
jobs:
14-
lint-and-test:
15-
runs-on: ubuntu-latest
16-
16+
lint:
17+
name: Lint
18+
runs-on: ubuntu-24.04
1719
steps:
1820
- name: Checkout
1921
uses: actions/checkout@v4
@@ -31,13 +33,49 @@ jobs:
3133
exit 1
3234
fi
3335
36+
- name: Run go vet
37+
run: go vet ./...
38+
3439
- name: Run golangci-lint
3540
uses: golangci/golangci-lint-action@v7
3641
with:
3742
version: v2.1
3843

39-
- name: Test
44+
test:
45+
name: Test
46+
runs-on: ubuntu-24.04
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@v4
50+
51+
- name: Set up Go
52+
uses: actions/setup-go@v5
53+
with:
54+
go-version-file: go.mod
55+
56+
- name: Run tests
4057
run: go test -v ./...
4158

59+
- name: Run tests with race detector
60+
run: go test -race ./...
61+
62+
- name: Generate coverage report
63+
run: go test -coverprofile=coverage.out ./...
64+
65+
- name: Display coverage
66+
run: go tool cover -func=coverage.out
67+
68+
build:
69+
name: Build
70+
runs-on: ubuntu-24.04
71+
steps:
72+
- name: Checkout
73+
uses: actions/checkout@v4
74+
75+
- name: Set up Go
76+
uses: actions/setup-go@v5
77+
with:
78+
go-version-file: go.mod
79+
4280
- name: Build
43-
run: go build -v ./cmd/cli
81+
run: make

.github/workflows/nix.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Update Vendor Hash
2+
3+
on:
4+
push:
5+
paths:
6+
- "go.mod"
7+
- "go.sum"
8+
branches:
9+
- master
10+
workflow_dispatch:
11+
12+
jobs:
13+
update-vendor-hash:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Install Nix
22+
uses: cachix/install-nix-action@v31
23+
24+
- name: Update vendorHash in flake.nix
25+
run: |
26+
set -euo pipefail
27+
28+
# Try to build and capture the expected hash from error message
29+
echo "Attempting nix build to get new vendorHash..."
30+
if output=$(nix build .#dgop 2>&1); then
31+
echo "Build succeeded, no hash update needed"
32+
exit 0
33+
fi
34+
35+
# Extract the expected hash from the error message
36+
new_hash=$(echo "$output" | grep -oP "got:\s+\K\S+" | head -n1)
37+
38+
if [ -z "$new_hash" ]; then
39+
echo "Could not extract new vendorHash from build output"
40+
echo "Build output:"
41+
echo "$output"
42+
exit 1
43+
fi
44+
45+
echo "New vendorHash: $new_hash"
46+
47+
# Get current hash from flake.nix
48+
current_hash=$(grep -oP 'vendorHash = "\K[^"]+' flake.nix)
49+
echo "Current vendorHash: $current_hash"
50+
51+
if [ "$current_hash" = "$new_hash" ]; then
52+
echo "vendorHash is already up to date"
53+
exit 0
54+
fi
55+
56+
# Update the hash in flake.nix
57+
sed -i "s|vendorHash = \"$current_hash\"|vendorHash = \"$new_hash\"|" flake.nix
58+
59+
# Verify the build works with the new hash
60+
echo "Verifying build with new vendorHash..."
61+
nix build .#dgop
62+
63+
echo "vendorHash updated successfully!"
64+
65+
- name: Commit and push vendorHash update
66+
run: |
67+
set -euo pipefail
68+
69+
if ! git diff --quiet flake.nix; then
70+
git config user.name "github-actions[bot]"
71+
git config user.email "github-actions[bot]@users.noreply.github.com"
72+
73+
git add flake.nix
74+
git commit -m "flake: update vendorHash for go.mod changes"
75+
76+
for attempt in 1 2 3; do
77+
if git push; then
78+
echo "Successfully pushed vendorHash update"
79+
exit 0
80+
fi
81+
echo "Push attempt $attempt failed, pulling and retrying..."
82+
git pull --rebase
83+
sleep $((attempt*2))
84+
done
85+
86+
echo "Failed to push after retries" >&2
87+
exit 1
88+
else
89+
echo "No changes to flake.nix"
90+
fi

.github/workflows/test.yml

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

0 commit comments

Comments
 (0)