|
| 1 | +name: AI Changelog (Claude) |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + tag_name: |
| 7 | + description: 'Release tag to enrich' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + id-token: write |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: ai-changelog-${{ inputs.tag_name }} |
| 17 | + cancel-in-progress: true |
| 18 | + |
| 19 | +jobs: |
| 20 | + ai-changelog: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + env: |
| 23 | + ANTHROPIC_BASE_URL: ${{ secrets.ANTHROPIC_BASE_URL }} |
| 24 | + ANTHROPIC_CUSTOM_HEADERS: ${{ secrets.ANTHROPIC_CUSTOM_HEADERS }} |
| 25 | + |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: Get previous tag |
| 32 | + id: prev_tag |
| 33 | + run: | |
| 34 | + CURRENT_TAG='${{ inputs.tag_name }}' |
| 35 | + PREV_TAG=$(git describe --tags --abbrev=0 "${CURRENT_TAG}^" 2>/dev/null || echo '') |
| 36 | + echo "current_tag=$CURRENT_TAG" >> "$GITHUB_OUTPUT" |
| 37 | + echo "previous_tag=$PREV_TAG" >> "$GITHUB_OUTPUT" |
| 38 | +
|
| 39 | + - name: Generate enhanced changelog with Claude Code Action |
| 40 | + uses: anthropics/claude-code-action@v1 |
| 41 | + env: |
| 42 | + GH_TOKEN: ${{ github.token }} |
| 43 | + with: |
| 44 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} |
| 46 | + prompt: | |
| 47 | + Generate an enhanced changelog for release ${{ inputs.tag_name }}. |
| 48 | +
|
| 49 | + IMPORTANT: |
| 50 | + - This workflow is triggered via workflow_dispatch because claude-code-action does not support push events. |
| 51 | + - Use the existing release-please notes as a starting point, but rewrite for clarity and context. |
| 52 | +
|
| 53 | + **Step 1: Collect data** |
| 54 | +
|
| 55 | + Get release-please's generated changelog: |
| 56 | + ```bash |
| 57 | + gh release view "${{ inputs.tag_name }}" --json body -q .body > /tmp/release-please-changelog.txt |
| 58 | + cat /tmp/release-please-changelog.txt |
| 59 | + ``` |
| 60 | +
|
| 61 | + Get all commits with full messages (not just titles): |
| 62 | + ```bash |
| 63 | + PREV_TAG='${{ steps.prev_tag.outputs.previous_tag }}' |
| 64 | + if [ -n "$PREV_TAG" ]; then |
| 65 | + git log "$PREV_TAG...${{ inputs.tag_name }}" --pretty=format:"### Commit: %s%n%b%n---" | head -c 50000 > /tmp/commits.txt |
| 66 | + else |
| 67 | + git log "${{ inputs.tag_name }}" --pretty=format:"### Commit: %s%n%b%n---" | head -c 50000 > /tmp/commits.txt |
| 68 | + fi |
| 69 | + cat /tmp/commits.txt |
| 70 | + ``` |
| 71 | +
|
| 72 | + Get merged PRs with descriptions: |
| 73 | + ```bash |
| 74 | + PREV_TAG='${{ steps.prev_tag.outputs.previous_tag }}' |
| 75 | + if [ -n "$PREV_TAG" ]; then |
| 76 | + PREV_DATE=$(git log -1 --format=%aI "$PREV_TAG" 2>/dev/null || echo "2024-01-01T00:00:00Z") |
| 77 | + else |
| 78 | + PREV_DATE="2024-01-01T00:00:00Z" |
| 79 | + fi |
| 80 | +
|
| 81 | + gh pr list \ |
| 82 | + --repo ${{ github.repository }} \ |
| 83 | + --state merged \ |
| 84 | + --json number,title,body,mergedAt \ |
| 85 | + --limit 50 \ |
| 86 | + --search "merged:>=$PREV_DATE" \ |
| 87 | + --jq '.[] | "## PR #\(.number): \(.title)\n\(.body)\n---\n"' > /tmp/prs.txt 2>/dev/null || echo "No PRs found" > /tmp/prs.txt |
| 88 | + cat /tmp/prs.txt |
| 89 | + ``` |
| 90 | +
|
| 91 | + Get diff statistics and file list: |
| 92 | + ```bash |
| 93 | + PREV_TAG='${{ steps.prev_tag.outputs.previous_tag }}' |
| 94 | + if [ -n "$PREV_TAG" ]; then |
| 95 | + git diff "$PREV_TAG...${{ inputs.tag_name }}" --shortstat > /tmp/stats.txt |
| 96 | + git diff "$PREV_TAG...${{ inputs.tag_name }}" --name-only | head -c 50000 > /tmp/files.txt |
| 97 | + else |
| 98 | + git log --shortstat --oneline | head -1 > /tmp/stats.txt |
| 99 | + git show --name-only --pretty='' "${{ inputs.tag_name }}" | head -c 50000 > /tmp/files.txt |
| 100 | + fi |
| 101 | + cat /tmp/stats.txt |
| 102 | + echo "\n--- Files changed (truncated) ---" |
| 103 | + cat /tmp/files.txt |
| 104 | + ``` |
| 105 | +
|
| 106 | + **Step 2: Generate enhanced changelog** |
| 107 | +
|
| 108 | + Using the data above (release-please changelog, commit messages, PR descriptions, stats): |
| 109 | +
|
| 110 | + 1. Use release-please's changelog as the base structure, but rewrite entries with more context. |
| 111 | + 2. Prefer PR descriptions over commit titles when available (more accurate intent). |
| 112 | + 3. Add "What/Why/Impact" for each meaningful change. |
| 113 | + 4. Group by product area where possible (Frontend, Worker/API, Sandbox/Containers, Docs, Tooling). |
| 114 | + 5. Include PR numbers for traceability (e.g. "(#123)"). |
| 115 | + 6. Keep it concise: 1-2 bullets per PR unless truly major. |
| 116 | + 7. No emojis in the changelog. |
| 117 | +
|
| 118 | + Format: |
| 119 | + ```markdown |
| 120 | + ## Release ${{ inputs.tag_name }} |
| 121 | +
|
| 122 | + ### Highlights |
| 123 | + - 2-4 bullets: biggest user-visible improvements |
| 124 | +
|
| 125 | + ### Changes |
| 126 | +
|
| 127 | + #### Frontend |
| 128 | + - ... |
| 129 | +
|
| 130 | + #### Worker / API |
| 131 | + - ... |
| 132 | +
|
| 133 | + #### Sandbox / Containers |
| 134 | + - ... |
| 135 | +
|
| 136 | + #### Tooling / CI |
| 137 | + - ... |
| 138 | +
|
| 139 | + #### Documentation |
| 140 | + - ... |
| 141 | +
|
| 142 | + ### Breaking Changes |
| 143 | + - If any, include migration notes |
| 144 | +
|
| 145 | + ### Statistics |
| 146 | + - Include git diff shortstat |
| 147 | + - Mention top-level areas touched (from file list) |
| 148 | + ``` |
| 149 | +
|
| 150 | + **Step 3: Save the enhanced changelog** |
| 151 | + ```bash |
| 152 | + cat > /tmp/enhanced-changelog.md << 'CHANGELOG_EOF' |
| 153 | + [PASTE YOUR GENERATED CHANGELOG HERE] |
| 154 | + CHANGELOG_EOF |
| 155 | + ``` |
| 156 | +
|
| 157 | + **Step 4: Update the release** |
| 158 | + ```bash |
| 159 | + gh release edit "${{ inputs.tag_name }}" --notes-file /tmp/enhanced-changelog.md |
| 160 | + echo "Release notes updated successfully" |
| 161 | + ``` |
| 162 | +
|
| 163 | + claude_args: | |
| 164 | + --allowed-tools "Bash(gh release view:*),Bash(gh release edit:*),Bash(gh pr list:*),Bash(git log:*),Bash(git diff:*),Bash(git show:*),Bash(cat:*),Bash(echo:*),Bash(head:*)" |
| 165 | + --max-turns 20 |
| 166 | + --model claude-opus-4-5-20251101 |
| 167 | +
|
| 168 | + - name: Verify changelog updated |
| 169 | + if: always() |
| 170 | + env: |
| 171 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 172 | + run: | |
| 173 | + TAG_NAME='${{ inputs.tag_name }}' |
| 174 | + echo "Verifying release notes for $TAG_NAME..." |
| 175 | + gh release view "$TAG_NAME" --json body -q .body | head -20 |
| 176 | + echo "Changelog verification complete" |
0 commit comments