Skip to content

Commit 8647b3a

Browse files
authored
Merge pull request #16 from IntentProof/add-source-ref
Add SOURCE_REF and CI tuple bookkeeping check
2 parents 4ef01d2 + 04c56b2 commit 8647b3a

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

scripts/check-source-ref.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
# Fail when SOURCE_REF does not match the current commit (tuple bookkeeping).
3+
set -euo pipefail
4+
5+
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
6+
cd "$ROOT"
7+
8+
if [[ ! -f SOURCE_REF ]]; then
9+
echo "SKIP: SOURCE_REF not present yet (add when bumping the ecosystem tuple)."
10+
exit 0
11+
fi
12+
13+
HEAD="$(git rev-parse HEAD)"
14+
REF="$(tr -d '[:space:]' < SOURCE_REF)"
15+
if ! echo "$REF" | grep -qE '^[0-9a-f]{40}$'; then
16+
echo "Invalid SOURCE_REF: must be a 40-character lowercase git SHA" >&2
17+
exit 1
18+
fi
19+
20+
if [[ "$HEAD" == "$REF" ]]; then
21+
echo "PASS: SOURCE_REF matches HEAD ($HEAD)."
22+
exit 0
23+
fi
24+
25+
if git merge-base --is-ancestor "$REF" "$HEAD" 2>/dev/null; then
26+
echo "FAIL: HEAD ($HEAD) is ahead of SOURCE_REF ($REF)" >&2
27+
echo "Bump SOURCE_REF to HEAD and update spec pins/matrix for the tuple." >&2
28+
exit 1
29+
fi
30+
31+
echo "FAIL: SOURCE_REF ($REF) is not an ancestor of HEAD ($HEAD)" >&2
32+
exit 1

0 commit comments

Comments
 (0)