Skip to content

Commit 72f5df2

Browse files
authored
Fix/cachix pin no response (#950)
Something I have been noticing when testing pin and push with kup / cachix is we get a failure on 'cachix pin' and it times out after 120 seconds, and then a few minutes later the pin shows up. The workaround here may likely be just wait and keep trying for a few more minutes to determine if it actually did fail or if the error we're getting from cachix is a false failure. -- This very much seems to be the case.
1 parent 6368cf5 commit 72f5df2

3 files changed

Lines changed: 82 additions & 2 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
set -xeuo pipefail
3+
4+
# Kup relies on cachix registry k-framework-binary.
5+
CACHE="k-framework-binary"
6+
OWNER_REPO="$(git remote get-url origin | sed -E 's#(git@github.com:|https://github.com/)##; s#\.git$##')"
7+
REV="$(git rev-parse HEAD)"
8+
# Get the output of the nix build for kmir.
9+
OUT="$(nix build --no-link --json ".#kmir" | jq -r '.[0].outputs.out')"
10+
KEY="github:${OWNER_REPO}/${REV}#kmir"
11+
12+
SUMMARY="${GITHUB_STEP_SUMMARY:-/dev/stdout}"
13+
14+
{
15+
echo "## Cachix Publish Summary"
16+
echo "CACHE: $CACHE"
17+
echo "OUT: $OUT"
18+
echo "KEY: $KEY"
19+
} >> "$SUMMARY"
20+
21+
# Verify push + pin together. Both can become visible with some delay.
22+
HASH="$(basename "$OUT" | cut -d- -f1)"
23+
PUSH_NARINFO_URL="https://${CACHE}.cachix.org/${HASH}.narinfo"
24+
PIN_API_URL="https://app.cachix.org/api/v1/cache/${CACHE}/pin"
25+
PIN_VISIBILITY_TIMEOUT_SECONDS=120 # 2 minutes
26+
PIN_VISIBILITY_INTERVAL_SECONDS=5 # 5 seconds
27+
PIN_VISIBILITY_ATTEMPTS=$((PIN_VISIBILITY_TIMEOUT_SECONDS / PIN_VISIBILITY_INTERVAL_SECONDS))
28+
for i in $(seq 1 "$PIN_VISIBILITY_ATTEMPTS"); do
29+
PUSH_STATUS="$(curl -sS -o /dev/null -w '%{http_code}' "$PUSH_NARINFO_URL")" || PUSH_STATUS="000"
30+
if curl -fsSL "$PIN_API_URL" | jq -e --arg k "$KEY" 'any(.[]; .name == $k)' > /dev/null; then
31+
PIN_STATUS="pin-ok"
32+
else
33+
PIN_STATUS="pin-missing"
34+
fi
35+
36+
echo "push-http: ${PUSH_STATUS}" >> "$SUMMARY"
37+
echo "pin-status: ${PIN_STATUS}" >> "$SUMMARY"
38+
39+
if [ "$PUSH_STATUS" = "200" ] && [ "$PIN_STATUS" = "pin-ok" ]; then
40+
echo "cachix-status: push-and-pin-ok" >> "$SUMMARY"
41+
exit 0
42+
fi
43+
44+
echo "cachix-check-attempt-${i}: not-ready, retrying in ${PIN_VISIBILITY_INTERVAL_SECONDS}s" >> "$SUMMARY"
45+
sleep "$PIN_VISIBILITY_INTERVAL_SECONDS"
46+
done
47+
48+
echo "cachix-status: push-or-pin-missing-after-${PIN_VISIBILITY_TIMEOUT_SECONDS}s" >> "$SUMMARY"
49+
exit 1

.github/workflows/release.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ jobs:
171171
packages: jq
172172
script: |
173173
export PATH="$(nix build github:runtimeverification/kup --no-link --json | jq -r '.[].outputs | to_entries[].value')/bin:$PATH"
174-
kup publish k-framework-binary .#kmir --keep-days 180
175-
kup publish k-framework-binary .#kmir.rust --keep-days 180
174+
kup publish k-framework-binary .#kmir --keep-days 180 || true
175+
kup publish k-framework-binary .#kmir.rust --keep-days 180 || true
176+
177+
# Cachix has not been responding to 'cachix pin' requests made under the hood by kup. So we need to manually verify the push and pin.
178+
.github/scripts/check-cachix-pin.sh
176179
177180
- name: 'On failure, delete drafted release'
178181
if: failure()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: 'Test Cachix Pin'
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ref:
7+
description: 'Git ref (tag or SHA) of an existing release to verify'
8+
required: true
9+
type: string
10+
11+
jobs:
12+
verify-cachix-pin:
13+
name: 'Verify Cachix Pin'
14+
runs-on: [self-hosted, linux, normal]
15+
steps:
16+
- name: 'Check out code'
17+
uses: actions/checkout@v4
18+
with:
19+
ref: ${{ inputs.ref }}
20+
21+
- name: 'Verify cachix publish and pin'
22+
uses: workflow/nix-shell-action@v3
23+
env:
24+
CACHIX_AUTH_TOKEN: '${{ secrets.CACHIX_PRIVATE_KFB_TOKEN }}'
25+
GC_DONT_GC: '1'
26+
with:
27+
packages: jq
28+
script: bash .github/scripts/check-cachix-pin.sh

0 commit comments

Comments
 (0)