-
-
Notifications
You must be signed in to change notification settings - Fork 20
feat(changelog): Add changelog preview action and CLI command #669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
697b38f
feat: Add changelog preview GitHub Action
BYK be12666
ci: Add changelog preview workflow for testing
BYK 749a43b
ci: Fix changelog preview workflow for testing
BYK 0a77633
fix: Use commit-based highlighting instead of PR number
BYK de8d3ee
debug: Add verbose output to changelog preview workflow
BYK 3f80c2b
ci: Build craft from source for testing (changelog cmd not released)
BYK 4391678
fix: Generate changelog up to merge base and inject current PR
BYK f2aefe9
fix: Add GITHUB_TOKEN env for Craft API access
BYK 9647967
fix: Suppress stderr to hide node deprecation warning
BYK 06a9014
refactor: Remove --until flag, compute merge base from PR's base branch
BYK 4ea8507
feat: Make changelog-preview a reusable workflow
BYK e1756f3
fix: Add setup-node step for dogfooding
BYK 8f7e9d2
fix: Remove explicit secrets requirement from workflow_call
BYK 5aa67f1
refactor: Address PR review comments
BYK e5ecfc3
fix: Inline install logic in reusable workflow
BYK 324d340
refactor: Address additional PR review comments
BYK 5fab25c
refactor: Split changelog generation into raw data + serialization
BYK 491804b
refactor: Use base branch tip instead of merge-base
BYK 368750f
refactor: Separate RawChangelogData from ChangelogStats
BYK 2c0f6d8
refactor: Inline injectCurrentPR into generateChangelogWithHighlight
BYK 3adcf69
refactor: Clean sandwich approach for changelog with PR injection
BYK abbe627
feat: Display suggested version bump in changelog preview comment
BYK 5777299
style: Make version bump more prominent with its own header
BYK bd046e2
refactor: Move version bump to top-level header, use temp file for co…
BYK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| name: Changelog Preview | ||
|
|
||
| on: | ||
| # Allow this workflow to be called from other repositories | ||
| workflow_call: | ||
| inputs: | ||
| craft-version: | ||
| description: 'Version of Craft to use (tag or "latest")' | ||
| required: false | ||
| type: string | ||
| default: 'latest' | ||
|
|
||
| # Also run on PRs in this repository (for dogfooding) | ||
| # Includes 'edited' and 'labeled' to update when PR title/description/labels change | ||
| pull_request: | ||
| types: [opened, synchronize, reopened, edited, labeled] | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| preview: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| # Install Craft using the shared install action | ||
| # TODO: Change to @v2 or @master after this PR is merged | ||
| - name: Install Craft | ||
| uses: getsentry/craft/install@pull/669/head | ||
| with: | ||
| craft-version: ${{ inputs.craft-version || 'latest' }} | ||
|
|
||
| - name: Generate Changelog Preview | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| CRAFT_LOG_LEVEL: Warn | ||
| run: | | ||
| PR_NUMBER="${{ github.event.pull_request.number }}" | ||
|
|
||
| # Generate changelog with current PR injected and highlighted (JSON format) | ||
| echo "Running craft changelog --pr $PR_NUMBER --format json..." | ||
| RESULT=$(craft changelog --pr "$PR_NUMBER" --format json 2>/dev/null || echo '{"changelog":"","bumpType":null}') | ||
|
|
||
| # Extract fields from JSON | ||
| CHANGELOG=$(echo "$RESULT" | jq -r '.changelog // ""') | ||
| BUMP_TYPE=$(echo "$RESULT" | jq -r '.bumpType // "none"') | ||
|
|
||
| if [[ -z "$CHANGELOG" ]]; then | ||
| CHANGELOG="_No changelog entries will be generated from this PR._" | ||
| fi | ||
|
|
||
| # Format bump type for display | ||
| case "$BUMP_TYPE" in | ||
| major) BUMP_BADGE="🔴 **Major** (breaking changes)" ;; | ||
| minor) BUMP_BADGE="🟡 **Minor** (new features)" ;; | ||
| patch) BUMP_BADGE="🟢 **Patch** (bug fixes)" ;; | ||
| *) BUMP_BADGE="⚪ **None** (no version bump detected)" ;; | ||
| esac | ||
|
|
||
| # Build comment body using a temp file (safer than heredoc) | ||
| COMMENT_FILE=$(mktemp) | ||
| cat > "$COMMENT_FILE" << CRAFT_CHANGELOG_COMMENT_END | ||
| <!-- craft-changelog-preview --> | ||
| ## Suggested Version Bump | ||
|
|
||
| ${BUMP_BADGE} | ||
|
|
||
| ## 📋 Changelog Preview | ||
|
|
||
| This is how your changes will appear in the changelog. | ||
| Entries from this PR are highlighted with a left border (blockquote style). | ||
|
|
||
| --- | ||
|
|
||
| ${CHANGELOG} | ||
|
|
||
| --- | ||
|
|
||
| <sub>🤖 This preview updates automatically when you update the PR.</sub> | ||
| CRAFT_CHANGELOG_COMMENT_END | ||
|
|
||
| # Find existing comment with our marker | ||
| COMMENT_ID=$(gh api \ | ||
| "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" \ | ||
| --jq '.[] | select(.body | contains("<!-- craft-changelog-preview -->")) | .id' \ | ||
| | head -1) | ||
|
|
||
| if [[ -n "$COMMENT_ID" ]]; then | ||
| echo "Updating existing comment $COMMENT_ID..." | ||
| gh api -X PATCH \ | ||
| "repos/$GITHUB_REPOSITORY/issues/comments/$COMMENT_ID" \ | ||
| -F body=@"$COMMENT_FILE" | ||
| else | ||
| echo "Creating new comment..." | ||
| gh api -X POST \ | ||
| "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" \ | ||
| -F body=@"$COMMENT_FILE" | ||
| fi | ||
|
|
||
| rm -f "$COMMENT_FILE" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.