Skip to content

Commit 0630d4e

Browse files
authored
Merge branch 'master' into jh/fix-thunk-projection
2 parents 503b616 + e23e477 commit 0630d4e

3 files changed

Lines changed: 64 additions & 25 deletions

File tree

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,86 @@
11
#!/usr/bin/env bash
2-
set -xeuo pipefail
2+
set -euo pipefail
33

44
# Kup relies on cachix registry k-framework-binary.
55
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"
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+
CHECK_PACKAGES=(kmir kmir.rust)
1122

1223
SUMMARY="${GITHUB_STEP_SUMMARY:-/dev/stdout}"
1324

1425
{
1526
echo "## Cachix Publish Summary"
1627
echo "CACHE: $CACHE"
17-
echo "OUT: $OUT"
18-
echo "KEY: $KEY"
28+
echo "OWNER_REPO: $OWNER_REPO"
29+
echo "REV: $REV"
30+
echo "SYSTEM: $SYSTEM"
31+
echo "PACKAGES: ${CHECK_PACKAGES[*]}"
1932
} >> "$SUMMARY"
2033

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"
34+
# Verify push + pin together for each package. Both can become visible with delay.
2535
PIN_VISIBILITY_TIMEOUT_SECONDS=120 # 2 minutes
2636
PIN_VISIBILITY_INTERVAL_SECONDS=5 # 5 seconds
2737
PIN_VISIBILITY_ATTEMPTS=$((PIN_VISIBILITY_TIMEOUT_SECONDS / PIN_VISIBILITY_INTERVAL_SECONDS))
2838
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
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+
3160
PIN_STATUS="pin-ok"
32-
else
33-
PIN_STATUS="pin-missing"
34-
fi
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
3567

36-
echo "push-http: ${PUSH_STATUS}" >> "$SUMMARY"
37-
echo "pin-status: ${PIN_STATUS}" >> "$SUMMARY"
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
3875

39-
if [ "$PUSH_STATUS" = "200" ] && [ "$PIN_STATUS" = "pin-ok" ]; then
40-
echo "cachix-status: push-and-pin-ok" >> "$SUMMARY"
76+
if [ "$ALL_OK" = "1" ]; then
77+
echo "cachix-status: push-and-pin-ok-for-all-packages" >> "$SUMMARY"
4178
exit 0
4279
fi
4380

44-
echo "cachix-check-attempt-${i}: not-ready, retrying in ${PIN_VISIBILITY_INTERVAL_SECONDS}s" >> "$SUMMARY"
81+
echo "cachix-check-attempt-${i}: not-ready, retrying in ${PIN_VISIBILITY_INTERVAL_SECONDS}s"
4582
sleep "$PIN_VISIBILITY_INTERVAL_SECONDS"
4683
done
4784

48-
echo "cachix-status: push-or-pin-missing-after-${PIN_VISIBILITY_TIMEOUT_SECONDS}s" >> "$SUMMARY"
85+
echo "cachix-status: push-or-pin-missing-after-${PIN_VISIBILITY_TIMEOUT_SECONDS}s-for-at-least-one-package" >> "$SUMMARY"
4986
exit 1

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ jobs:
167167
env:
168168
CACHIX_AUTH_TOKEN: '${{ secrets.CACHIX_PRIVATE_KFB_TOKEN }}'
169169
GC_DONT_GC: '1'
170+
OWNER_REPO: '${{ github.repository }}'
171+
REV: '${{ github.sha }}'
170172
with:
171173
packages: jq
172174
script: |

.github/workflows/test-cachix-pin.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ jobs:
1515
steps:
1616
- name: 'Check out code'
1717
uses: actions/checkout@v4
18-
with:
19-
ref: ${{ inputs.ref }}
2018

2119
- name: 'Verify cachix publish and pin'
2220
uses: workflow/nix-shell-action@v3
2321
env:
2422
CACHIX_AUTH_TOKEN: '${{ secrets.CACHIX_PRIVATE_KFB_TOKEN }}'
2523
GC_DONT_GC: '1'
24+
OWNER_REPO: '${{ github.repository }}'
25+
REV: '${{ inputs.ref }}'
2626
with:
2727
packages: jq
2828
script: bash .github/scripts/check-cachix-pin.sh

0 commit comments

Comments
 (0)