Skip to content

Commit 8554764

Browse files
committed
ci: add Claude-based version bump analysis for every push
Add scripts/analyze-bump.sh that sends the diff and commit log to Claude Haiku to determine the appropriate semver bump (major/minor/patch). Wired into semantic-release via @semantic-release/exec analyzeCommitsCmd. The commit-analyzer still handles conventional commits; Claude acts as a second opinion and ensures non-conventional commits also trigger a release. semantic-release picks the highest bump from both. Falls back to "patch" if ANTHROPIC_API_KEY is missing or the call fails.
1 parent fcf4fdd commit 8554764

3 files changed

Lines changed: 63 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
id: semantic
4444
env:
4545
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
4647
run: |
4748
BEFORE_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "none")
4849
npx semantic-release

.releaserc.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
]
1515
}
1616
],
17+
[
18+
"@semantic-release/exec",
19+
{
20+
"analyzeCommitsCmd": "bash scripts/analyze-bump.sh",
21+
"prepareCmd": "sed -i 's/VERSION = \"[^\"]*\"/VERSION = \"${nextRelease.version}\"/' src/UintQuantizationLib.sol"
22+
}
23+
],
1724
[
1825
"@semantic-release/release-notes-generator",
1926
{ "preset": "conventionalcommits" }
@@ -22,12 +29,6 @@
2229
"@semantic-release/changelog",
2330
{ "changelogFile": "CHANGELOG.md" }
2431
],
25-
[
26-
"@semantic-release/exec",
27-
{
28-
"prepareCmd": "sed -i 's/VERSION = \"[^\"]*\"/VERSION = \"${nextRelease.version}\"/' src/UintQuantizationLib.sol"
29-
}
30-
],
3132
[
3233
"@semantic-release/github",
3334
{ "successComment": false }

scripts/analyze-bump.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Called by @semantic-release/exec as analyzeCommitsCmd.
5+
# Asks Claude to determine the semantic version bump from the diff.
6+
# Falls back to "patch" if the API key is missing or the call fails.
7+
8+
if [ -z "${ANTHROPIC_API_KEY:-}" ]; then
9+
echo "patch"
10+
exit 0
11+
fi
12+
13+
# Comparison base: last release tag, or the repo root for the first release
14+
if [ -n "${LAST_RELEASE_GIT_TAG:-}" ]; then
15+
BASE="$LAST_RELEASE_GIT_TAG"
16+
else
17+
BASE=$(git rev-list --max-parents=0 HEAD)
18+
fi
19+
20+
COMMIT_LOG=$(git log "$BASE"..HEAD --pretty=format:"- %s" 2>/dev/null || echo "- initial release")
21+
DIFF_STAT=$(git diff "$BASE"..HEAD --stat 2>/dev/null | tail -30 || echo "no diff")
22+
SOL_DIFF=$(git diff "$BASE"..HEAD -- '*.sol' 2>/dev/null | head -200 || echo "no diff")
23+
24+
PROMPT="You are a semantic versioning expert for a Solidity library (uint-quantization-lib).
25+
26+
Rules:
27+
- major: breaking changes to the consumer-facing API (renamed functions, changed signatures, renamed/removed errors, changed type definitions)
28+
- minor: new features (new functions, new error types, new capabilities)
29+
- patch: bug fixes, docs, CI/CD, tests, internal refactoring, performance improvements
30+
31+
Respond with exactly one word: major, minor, or patch.
32+
33+
Commits since v${LAST_RELEASE_VERSION:-0.0.0}:
34+
${COMMIT_LOG}
35+
36+
Changed files:
37+
${DIFF_STAT}
38+
39+
Solidity diff (truncated):
40+
${SOL_DIFF}"
41+
42+
RESPONSE=$(curl -sf --max-time 30 \
43+
-H "x-api-key: $ANTHROPIC_API_KEY" \
44+
-H "anthropic-version: 2023-06-01" \
45+
-H "content-type: application/json" \
46+
"https://api.anthropic.com/v1/messages" \
47+
-d "$(jq -n --arg prompt "$PROMPT" '{
48+
model: "claude-haiku-4-5-20251001",
49+
max_tokens: 10,
50+
messages: [{ role: "user", content: $prompt }]
51+
}')" 2>/dev/null) || { echo "patch"; exit 0; }
52+
53+
BUMP=$(echo "$RESPONSE" | jq -r '.content[0].text' 2>/dev/null | tr '[:upper:]' '[:lower:]' | grep -oE 'major|minor|patch' | head -1)
54+
55+
echo "${BUMP:-patch}"

0 commit comments

Comments
 (0)