diff --git a/.github/workflows/release-on-main.yml b/.github/workflows/release-on-main.yml index 82ec1be..1c664af 100644 --- a/.github/workflows/release-on-main.yml +++ b/.github/workflows/release-on-main.yml @@ -60,7 +60,8 @@ jobs: REPO="${OWNER_REPO#*/}" if [ "$LAST_TAG" = "v0.0.0" ]; then - START_DATE="1970-01-01T00:00:00Z" + # No prior release — look back 30 days instead of all time + START_DATE=$(date -u -d '30 days ago' '+%Y-%m-%dT%H:%M:%SZ') else START_DATE=$(git log -1 --format=%cI "$LAST_TAG") fi @@ -78,20 +79,22 @@ jobs: if [ "$COUNT" -eq 0 ]; then echo "has_changes=false" >> "$GITHUB_OUTPUT" - echo "pr_context=[]" >> "$GITHUB_OUTPUT" + echo '[]' > /tmp/pr_context.json exit 0 fi - jq '[.[] | {number, title, body, labels: [.labels[].name], user: .user.login, merged_at, html_url}]' /tmp/merged_prs.json > /tmp/pr_context.json + jq '[.[] | {number, title, body: (.body // "" | .[:200]), labels: [.labels[].name], user: .user.login, merged_at, html_url}]' /tmp/merged_prs.json > /tmp/pr_context.json + + # Cap at 50 most recent PRs for the Claude prompt to keep payload reasonable + jq '[ sort_by(.merged_at) | reverse | .[:50] | reverse | .[] ]' /tmp/pr_context.json > /tmp/pr_context_capped.json + echo "has_changes=true" >> "$GITHUB_OUTPUT" - echo "pr_context=$(jq -c . /tmp/pr_context.json)" >> "$GITHUB_OUTPUT" - name: Decide release bump with Claude Sonnet id: decide if: steps.prs.outputs.has_changes == 'true' env: ANTHROPIC_API_KEY: ${{ secrets.CI_ANTHROPIC_KEY }} - PR_CONTEXT: ${{ steps.prs.outputs.pr_context }} LAST_TAG: ${{ steps.last_tag.outputs.last_tag }} run: | set -euo pipefail @@ -123,14 +126,14 @@ jobs: --arg system "You are precise and must output strict JSON only." \ --arg prompt "$PROMPT" \ --arg last_tag "$LAST_TAG" \ - --argjson prs "$PR_CONTEXT" \ + --slurpfile prs /tmp/pr_context_capped.json \ '{ model: $model, max_tokens: 700, temperature: 0, system: $system, messages: [ - {role: "user", content: ($prompt + "\n\nLast release tag: " + $last_tag + "\n\nPRs:\n" + ($prs|tojson))} + {role: "user", content: ($prompt + "\n\nLast release tag: " + $last_tag + "\n\nPRs:\n" + ($prs[0]|tojson))} ] }' > /tmp/anthropic-payload.json @@ -227,7 +230,6 @@ jobs: id: changelog if: steps.bump.outputs.tag != '' env: - PR_CONTEXT: ${{ steps.prs.outputs.pr_context }} TAG: ${{ steps.bump.outputs.tag }} DECISION: ${{ steps.decide.outputs.decision }} REASON: ${{ steps.decide.outputs.reason }} @@ -241,7 +243,7 @@ jobs: echo "Reason: ${REASON}" echo echo "### Merged PRs" - jq -r '.[] | "- #\(.number) \(.title) (@\(.user)) — \(.html_url)"' <<< "$PR_CONTEXT" + jq -r '.[] | "- #\(.number) \(.title) (@\(.user)) — \(.html_url)"' /tmp/pr_context.json } > /tmp/release-notes.md echo "notes_path=/tmp/release-notes.md" >> "$GITHUB_OUTPUT"