Skip to content

Commit 33ab3bb

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

File tree

4 files changed

+163
-21
lines changed

4 files changed

+163
-21
lines changed

.github/workflows/build.yaml

+66-6
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,78 @@ 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+
VERSION=$(git describe --tags --abbrev=0)
50+
nix-update --flake --version $VERSION gose
51+
EOF
52+
53+
git diff --quiet || echo "changed=true" >> "$GITHUB_OUTPUT"
54+
55+
- name: Commit changes
56+
id: git-commit
57+
if: steps.nix-update-hashes.outputs.changed == 'true'
58+
run: |
59+
LAST_AUTHOR=$(git log -1 --pretty=format:"%ae")
60+
RENOVATE_AUTHOR="29139614+renovate[bot]@users.noreply.github.com"
61+
62+
if [ "${LAST_AUTHOR}" = "${RENOVATE_AUTHOR}" ]; then
63+
git commit --all --amend --no-edit
64+
git push --force
65+
else
66+
git commit --all --signoff --message "fix(nix): Update version and hashes"
67+
git push
68+
fi
69+
70+
71+
build:
72+
name: Build
73+
runs-on: ubuntu-24.04
74+
needs:
75+
- nix-update
76+
77+
steps:
78+
- name: Checkout
79+
uses: actions/checkout@v4
80+
81+
- name: Setup Nix
82+
uses: DeterminateSystems/nix-installer-action@v16
83+
84+
- name: Setup Nix cache
85+
uses: DeterminateSystems/magic-nix-cache-action@v8
2686

2787
- name: Run Nix build
2888
run: nix build

default.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
lib,
88
}:
99
let
10-
version = "0.8.0";
10+
version = "0.9.0";
1111

1212
frontend = buildNpmPackage {
1313
pname = "gose-frontend";
@@ -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

+27-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,27 @@
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+
nix-update.packages.${system}.nix-update
40+
golangci-lint
41+
reuse
42+
nodejs_22
43+
goreleaser
44+
];
45+
};
46+
47+
ci = mkShell {
48+
packages = [
49+
nix-update.packages.${system}.nix-update
50+
goreleaser
51+
];
52+
};
3653
};
3754

3855
packages = rec {

0 commit comments

Comments
 (0)