Skip to content

Commit 3becd2c

Browse files
committed
feat(ci): Automatically update Nix hashes
Signed-off-by: Steffen Vogel <[email protected]>
1 parent 195b424 commit 3becd2c

File tree

4 files changed

+160
-20
lines changed

4 files changed

+160
-20
lines changed

.github/workflows/build.yaml

+65-6
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,77 @@ on:
1111
- main
1212
pull_request:
1313

14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
permissions:
19+
contents: write
20+
1421
jobs:
15-
builds:
16-
runs-on: ubuntu-latest
22+
nix-update:
23+
name: Update Nix hashes
24+
runs-on: ubuntu-24.04
1725

1826
steps:
1927
- name: Checkout
2028
uses: actions/checkout@v4
21-
22-
- name: Install Nix
23-
uses: cachix/install-nix-action@v30
2429
with:
25-
github_access_token: ${{ secrets.GITHUB_TOKEN }}
30+
ref: ${{ github.event.pull_request.head.ref }}
31+
fetch-depth: 0
32+
token: ${{ secrets.PAT }}
33+
34+
- name: Setup Nix
35+
uses: DeterminateSystems/nix-installer-action@v16
36+
37+
- name: Setup Nix cache
38+
uses: DeterminateSystems/magic-nix-cache-action@v8
39+
40+
- name: Setup Git
41+
run: |
42+
git config --global user.name 'github-actions[bot]'
43+
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
44+
45+
- name: Update version and vendor hashes in Nix derivation
46+
id: nix-update-hashes
47+
run: |
48+
nix develop .#ci --command sh <<'EOF'
49+
nix-update --flake gose
50+
EOF
51+
52+
git diff --quiet || echo "changed=true" >> "$GITHUB_OUTPUT"
53+
54+
- name: Commit changes
55+
id: git-commit
56+
if: steps.nix-update-hashes.outputs.changed == 'true'
57+
run: |
58+
LAST_AUTHOR=$(git log -1 --pretty=format:"%ae")
59+
RENOVATE_AUTHOR="29139614+renovate[bot]@users.noreply.github.com"
60+
61+
if [ "${LAST_AUTHOR}" = "${RENOVATE_AUTHOR}" ]; then
62+
git commit --all --amend --no-edit
63+
git push --force
64+
else
65+
git commit --all --signoff --message "fix(nix): Update version and hashes"
66+
git push
67+
fi
68+
69+
70+
build:
71+
name: Build
72+
runs-on: ubuntu-24.04
73+
needs:
74+
- nix-update
75+
76+
steps:
77+
- name: Checkout
78+
uses: actions/checkout@v4
79+
80+
- name: Setup Nix
81+
uses: DeterminateSystems/nix-installer-action@v16
82+
83+
- name: Setup Nix cache
84+
uses: DeterminateSystems/magic-nix-cache-action@v8
2685

2786
- name: Run Nix build
2887
run: nix build

default.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ buildGoModule {
3030

3131
vendorHash = "sha256-U/umJ6McCuD0HARVMj1JXHOpVxcph16z7Y7i47Nf3cg=";
3232

33-
CGO_ENABLED = 0;
33+
env.CGO_ENABLED = 0;
3434

3535
postInstall = ''
3636
mv $out/bin/cmd $out/bin/gose

flake.lock

+68-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+26-10
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
inputs = {
77
flake-utils.url = "github:numtide/flake-utils";
88
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
9+
nix-update = {
10+
url = "github:Mic92/nix-update";
11+
inputs = {
12+
nixpkgs.follows = "nixpkgs";
13+
};
14+
};
915
};
1016

1117
outputs =
1218
{
1319
self,
1420
flake-utils,
1521
nixpkgs,
22+
nix-update,
1623
}:
1724
flake-utils.lib.eachDefaultSystem (
1825
system:
@@ -22,17 +29,26 @@
2229
};
2330
in
2431
{
25-
devShell = pkgs.mkShell {
26-
inputsFrom = [
27-
self.packages.${system}.default
28-
];
32+
devShells = with pkgs; {
33+
default = mkShell {
34+
inputsFrom = [
35+
self.packages.${system}.default
36+
];
2937

30-
packages = with pkgs; [
31-
golangci-lint
32-
reuse
33-
nodejs_22
34-
goreleaser
35-
];
38+
packages = with pkgs; [
39+
golangci-lint
40+
reuse
41+
nodejs_22
42+
goreleaser
43+
];
44+
};
45+
46+
ci = mkShell {
47+
packages = [
48+
nix-update.packages.${system}.nix-update
49+
goreleaser
50+
];
51+
};
3652
};
3753

3854
packages = rec {

0 commit comments

Comments
 (0)