Skip to content

Commit 4c74101

Browse files
committed
Fixing cachix push and pin functionality broken by their cloudflare going unresponsive when using push and pin.
1 parent 7d503d9 commit 4c74101

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Kup relies on cachix registry k-framework-binary.
5+
CACHE="k-framework-binary"
6+
OWNER_REPO="${OWNER_REPO:-$(git remote get-url origin | sed -E 's#(git@github.com:|https://github.com/)##; s#\.git$##')}"
7+
REV="${REV:-${GITHUB_SHA:-$(git rev-parse HEAD)}}"
8+
UNAME_S="$(uname -s)"
9+
UNAME_M="$(uname -m)"
10+
case "${UNAME_S}-${UNAME_M}" in
11+
Linux-x86_64) SYSTEM="x86_64-linux" ;;
12+
Linux-aarch64 | Linux-arm64) SYSTEM="aarch64-linux" ;;
13+
Darwin-x86_64) SYSTEM="x86_64-darwin" ;;
14+
Darwin-arm64) SYSTEM="aarch64-darwin" ;;
15+
*)
16+
echo "Unsupported platform: ${UNAME_S}-${UNAME_M}" >&2
17+
exit 1
18+
;;
19+
esac
20+
PIN_API_URL="https://app.cachix.org/api/v1/cache/${CACHE}/pin"
21+
# Must match every attribute passed to `kup publish … .#…` for this cache.
22+
CHECK_PACKAGES=(k k.openssl.secp256k1 k.openssl.procps.secp256k1)
23+
24+
SUMMARY="${GITHUB_STEP_SUMMARY:-/dev/stdout}"
25+
26+
{
27+
echo "## Cachix publish pin check"
28+
echo "CACHE: $CACHE"
29+
echo "OWNER_REPO: $OWNER_REPO"
30+
echo "REV: $REV"
31+
echo "SYSTEM: $SYSTEM"
32+
echo "PACKAGES: ${CHECK_PACKAGES[*]}"
33+
} >> "$SUMMARY"
34+
35+
PIN_VISIBILITY_TIMEOUT_SECONDS=120
36+
PIN_VISIBILITY_INTERVAL_SECONDS=5
37+
PIN_VISIBILITY_ATTEMPTS=$((PIN_VISIBILITY_TIMEOUT_SECONDS / PIN_VISIBILITY_INTERVAL_SECONDS))
38+
for i in $(seq 1 "$PIN_VISIBILITY_ATTEMPTS"); do
39+
PIN_JSON="$(curl -fsSL "${PIN_API_URL}?q=${REV}")"
40+
ALL_OK=1
41+
42+
for PKG in "${CHECK_PACKAGES[@]}"; do
43+
KEY="github:${OWNER_REPO}/${REV}#packages.${SYSTEM}.${PKG}"
44+
STORE_PATH="$(
45+
echo "$PIN_JSON" \
46+
| jq -r --arg k "$KEY" 'map(select(.name == $k)) | first | (.lastRevision.storePath // .storePath // .store_path // .path // "")'
47+
)"
48+
if [ -z "$STORE_PATH" ]; then
49+
PIN_STATUS="pin-missing"
50+
PUSH_STATUS="000"
51+
ALL_OK=0
52+
{
53+
echo "key-${PKG}: ${KEY}"
54+
echo "pin-status-${PKG}: ${PIN_STATUS}"
55+
echo "push-http-${PKG}: ${PUSH_STATUS}"
56+
}
57+
continue
58+
fi
59+
60+
PIN_STATUS="pin-ok"
61+
HASH="$(basename "$STORE_PATH" | cut -d- -f1)"
62+
PUSH_NARINFO_URL="https://${CACHE}.cachix.org/${HASH}.narinfo"
63+
PUSH_STATUS="$(curl -sS -o /dev/null -w '%{http_code}' "$PUSH_NARINFO_URL")" || PUSH_STATUS="000"
64+
if [ "$PUSH_STATUS" != "200" ]; then
65+
ALL_OK=0
66+
fi
67+
68+
{
69+
echo "key-${PKG}: ${KEY}"
70+
echo "store-path-${PKG}: ${STORE_PATH}"
71+
echo "pin-status-${PKG}: ${PIN_STATUS}"
72+
echo "push-http-${PKG}: ${PUSH_STATUS}"
73+
}
74+
done
75+
76+
if [ "$ALL_OK" = "1" ]; then
77+
echo "cachix-status: push-and-pin-ok-for-all-packages" >> "$SUMMARY"
78+
exit 0
79+
fi
80+
81+
echo "cachix-check-attempt-${i}: not-ready, retrying in ${PIN_VISIBILITY_INTERVAL_SECONDS}s"
82+
sleep "$PIN_VISIBILITY_INTERVAL_SECONDS"
83+
done
84+
85+
echo "cachix-status: push-or-pin-missing-after-${PIN_VISIBILITY_TIMEOUT_SECONDS}s-for-at-least-one-package" >> "$SUMMARY"
86+
exit 1

.github/workflows/release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ jobs:
8484
env:
8585
CACHIX_AUTH_TOKEN: '${{ secrets.CACHIX_PRIVATE_KFB_TOKEN }}'
8686
GC_DONT_GC: '1'
87+
OWNER_REPO: ${{ github.repository }}
88+
REV: ${{ github.sha }}
8789
with:
8890
packages: jq
8991
script: |
@@ -96,6 +98,9 @@ jobs:
9698
kup publish --verbose k-framework-binary .#k.openssl.secp256k1 --keep-days 180
9799
kup publish --verbose k-framework-binary .#k.openssl.procps.secp256k1 --keep-days 180
98100
101+
# kup/cachix pin visibility can be flaky; verify pins and narinfo via public API
102+
bash .github/scripts/check-cachix-pin.sh
103+
99104
cachix-release-dependencies:
100105
name: 'k-framework cachix release'
101106
strategy:

0 commit comments

Comments
 (0)