Skip to content

Commit cfd0283

Browse files
committed
ci: verify cookbook sha
1 parent 01a9f23 commit cfd0283

3 files changed

Lines changed: 270 additions & 126 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Verify Cookbook Pin
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "src/commands/forge.rs"
7+
- "scripts/bump-cookbook.sh"
8+
workflow_dispatch:
9+
10+
env:
11+
CARGO_TERM_COLOR: always
12+
13+
jobs:
14+
verify:
15+
name: Resolve pinned cookbook ref
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v6
19+
with:
20+
submodules: recursive
21+
- uses: dtolnay/rust-toolchain@stable
22+
- uses: Swatinem/rust-cache@v2
23+
- uses: taiki-e/install-action@nextest
24+
25+
# Online test: fetches the pinned COOKBOOK_REF, parses
26+
# registry.yaml, and asserts every recipe directory exists. Catches
27+
# a bad SHA paste before users hit it at runtime.
28+
- run: cargo nextest run --run-ignored only -E 'test(cookbook_pin_resolves)'

scripts/bump-cookbook.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
# Bump the cookbook SHA pinned in src/commands/forge.rs.
3+
#
4+
# Usage:
5+
# scripts/bump-cookbook.sh # bump to current main HEAD
6+
# scripts/bump-cookbook.sh <ref> # bump to a branch / tag / full SHA
7+
#
8+
# Does NOT commit. Prints a compare URL so the diff between old and new
9+
# cookbook content is one click away.
10+
11+
set -euo pipefail
12+
13+
REPO="steel-dev/steel-cookbook"
14+
FORGE_FILE="src/commands/forge.rs"
15+
REF="${1:-main}"
16+
17+
cd "$(git rev-parse --show-toplevel)"
18+
19+
if [[ ! -f "$FORGE_FILE" ]]; then
20+
echo "error: $FORGE_FILE not found" >&2
21+
exit 1
22+
fi
23+
24+
# Resolve <ref> via remote refs. If REF is already a 40-char SHA,
25+
# ls-remote returns nothing — use it directly.
26+
NEW_SHA="$(git ls-remote "https://github.com/$REPO.git" "$REF" 2>/dev/null | awk '{print $1; exit}')"
27+
if [[ -z "$NEW_SHA" ]]; then
28+
if [[ "$REF" =~ ^[a-f0-9]{40}$ ]]; then
29+
NEW_SHA="$REF"
30+
else
31+
echo "error: could not resolve '$REF' to a SHA in $REPO" >&2
32+
exit 1
33+
fi
34+
fi
35+
36+
OLD_SHA="$(awk -F'"' '/^const COOKBOOK_REF: &str =/ {print $2; exit}' "$FORGE_FILE")"
37+
38+
if [[ -z "$OLD_SHA" ]]; then
39+
echo "error: could not find COOKBOOK_REF declaration in $FORGE_FILE" >&2
40+
exit 1
41+
fi
42+
43+
if [[ "$OLD_SHA" == "$NEW_SHA" ]]; then
44+
echo "Already at $NEW_SHA. Nothing to do."
45+
exit 0
46+
fi
47+
48+
# Anchor the substitution to the const line so no other occurrence
49+
# of OLD_SHA elsewhere in the file can be hit.
50+
TMP="$(mktemp)"
51+
trap 'rm -f "$TMP"' EXIT
52+
sed "/^const COOKBOOK_REF/ s/$OLD_SHA/$NEW_SHA/" "$FORGE_FILE" > "$TMP"
53+
mv "$TMP" "$FORGE_FILE"
54+
55+
echo "Bumped $REPO:"
56+
echo " old: $OLD_SHA"
57+
echo " new: $NEW_SHA"
58+
echo
59+
echo "Compare: https://github.com/$REPO/compare/$OLD_SHA...$NEW_SHA"
60+
echo
61+
echo "Next: cargo nextest run --run-ignored only -E 'test(cookbook_pin_resolves)'"

0 commit comments

Comments
 (0)