|
| 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