Skip to content

Commit e754f29

Browse files
authored
Fix Cachix after automated Nix refresh merges (ilysenko#1055)
* Fix Cachix after automated Nix refresh merges * Restrict Cachix backfills to main
1 parent 7d4049b commit e754f29

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

.github/workflows/cachix.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- main
77
paths:
88
- flake.nix
9+
workflow_dispatch: {}
910

1011
permissions:
1112
contents: read
@@ -22,6 +23,7 @@ env:
2223
jobs:
2324
detect-codex-dmg-hash:
2425
name: Detect Codex DMG hash change
26+
if: github.event_name != 'workflow_dispatch' || github.ref == 'refs/heads/main'
2527
runs-on: ubuntu-latest
2628
outputs:
2729
changed: ${{ steps.codex-dmg-hash.outputs.changed }}
@@ -35,6 +37,7 @@ jobs:
3537
- name: Compare Codex DMG hashes
3638
id: codex-dmg-hash
3739
env:
40+
EVENT_NAME: ${{ github.event_name }}
3841
BEFORE_SHA: ${{ github.event.before }}
3942
run: |
4043
set -euo pipefail
@@ -46,7 +49,10 @@ jobs:
4649
previous_flake="$(mktemp)"
4750
trap 'rm -f "$previous_flake"' EXIT
4851
49-
if [ "$BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
52+
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
53+
changed=true
54+
previous_hash=manual-backfill
55+
elif [ "$BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
5056
changed=true
5157
previous_hash=missing
5258
else

.github/workflows/update-codex-hash.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,12 @@ jobs:
138138
git config user.email "actions@github.com"
139139
git checkout -B "$REFRESH_BRANCH"
140140
git add "${pin_paths[@]}"
141+
# GITHUB_TOKEN already suppresses branch push workflows. Do not add
142+
# a skip marker: squash merges copy it to main and suppress Cachix.
141143
git commit \
142144
-m "fix(nix): refresh upstream Nix pins${CODEX_VERSION:+ for $CODEX_VERSION}" \
143145
-m "Refreshed Codex.dmg SRI hash to $CODEX_DMG_HASH and synced codexVersion / electronVersion / native-module pins to the current upstream DMG." \
144146
-m "Verified all ChatGPT Desktop Nix package outputs against the refreshed DMG." \
145-
-m "[skip ci]" \
146147
-m "Source-Main-SHA: $EXPECTED_MAIN_SHA" \
147148
-m "Upstream-DMG-SHA256: $DMG_SHA256"
148149
git push --force-with-lease origin "$REFRESH_BRANCH"

docs/nix.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,5 @@ When a merge to `main` changes the pinned `Codex.dmg` hash, the `Populate
280280
Cachix` workflow builds the default package, feature-specific package variants,
281281
the watchdog feature check, and `.#installer`. It uploads and garbage-collects
282282
each output before starting the next one so the hosted runner does not retain
283-
every large app variant at once.
283+
every large app variant at once. Maintainers can dispatch the workflow manually
284+
to backfill the current `main` pin after a skipped or interrupted run.

scripts/ci/cachix-workflow.test.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,29 @@ const workflow = fs.readFileSync(
77
path.resolve(__dirname, "../../.github/workflows/cachix.yml"),
88
"utf8",
99
);
10+
const updateHashWorkflow = fs.readFileSync(
11+
path.resolve(__dirname, "../../.github/workflows/update-codex-hash.yml"),
12+
"utf8",
13+
);
1014

11-
test("Cachix population runs only for an actual Codex DMG hash change", () => {
15+
test("Cachix automatic population runs only for an actual Codex DMG hash change", () => {
1216
assert.match(workflow, /paths:\n\s+- flake\.nix/);
1317
assert.doesNotMatch(workflow, /schedule:/);
14-
assert.doesNotMatch(workflow, /workflow_dispatch:/);
18+
assert.match(workflow, /workflow_dispatch:/);
1519
assert.match(workflow, /id: codex-dmg-hash/);
20+
assert.match(workflow, /if: github\.event_name != 'workflow_dispatch' \|\| github\.ref == 'refs\/heads\/main'/);
21+
assert.match(workflow, /EVENT_NAME: \$\{\{ github\.event_name \}\}/);
1622
assert.match(workflow, /BEFORE_SHA: \$\{\{ github\.event\.before \}\}/);
23+
assert.match(workflow, /if \[ "\$EVENT_NAME" = "workflow_dispatch" \]; then\n\s+changed=true/);
1724
assert.match(workflow, /read-flake-hash "codexDmg = pkgs\.fetchurl \{" "hash = "/);
1825
assert.match(workflow, /if: needs\.detect-codex-dmg-hash\.outputs\.changed == 'true'/);
1926
});
2027

28+
test("Nix refresh commits allow post-merge workflows to run", () => {
29+
assert.doesNotMatch(updateHashWorkflow, /\[skip ci\]/);
30+
assert.match(updateHashWorkflow, /gh workflow run ci\.yml/);
31+
});
32+
2133
test("Cachix population pushes each output before collecting the Nix store", () => {
2234
assert.match(workflow, /skipPush: true/);
2335
assert.match(workflow, /nix build "\$output"[\s\S]*--print-out-paths/);

0 commit comments

Comments
 (0)