-
Notifications
You must be signed in to change notification settings - Fork 2
pr-changelog-check: Add reusable PR changelog check workflow #16
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
+101
−0
Merged
Changes from all commits
Commits
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
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,99 @@ | ||
| name: PR Changelog Check | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| base-ref: | ||
| description: 'Base branch reference for diff comparison' | ||
| required: true | ||
| type: string | ||
| pr-number: | ||
| description: 'Pull request number' | ||
| required: true | ||
| type: number | ||
| outputs: | ||
| has_breaking: | ||
| description: 'Whether the PR contains breaking changes' | ||
| value: ${{ jobs.pr-changelog-check.outputs.has_breaking }} | ||
|
|
||
| jobs: | ||
| pr-changelog-check: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| pull-requests: write | ||
| outputs: | ||
| has_breaking: ${{ steps.changelog-check.outputs.has_breaking }} | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 # Needed for diff mode | ||
| persist-credentials: false | ||
|
|
||
| # Resolve the ref of this reusable workflow so we can checkout the | ||
| # actions repo at the exact version the caller requested. | ||
| - name: Get workflow ref | ||
| id: workflow-ref | ||
| uses: cockroachdb/actions/get-workflow-ref@v0 | ||
| with: | ||
| workflow_name: cockroachdb/actions/.github/workflows/pr-changelog-check.yml | ||
|
|
||
| - name: Checkout actions repo | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| repository: cockroachdb/actions | ||
| ref: ${{ steps.workflow-ref.outputs.ref }} | ||
| path: actions-repo | ||
| persist-credentials: false | ||
|
|
||
| - name: Validate Changelog | ||
| id: changelog-check | ||
| uses: ./actions-repo/changelog-check | ||
| with: | ||
| check-mode: diff | ||
| base-ref: ${{ inputs.base-ref }} | ||
|
|
||
| - name: Find existing changelog comments | ||
| id: find-comments | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| cids="$(gh api "repos/${GITHUB_REPOSITORY}/issues/${{ inputs.pr-number }}/comments" \ | ||
| --jq '[.[] | select((.body | contains("<!-- changelog-change-status -->")) and .user.login == "github-actions[bot]") | .id] | join(" ")')" | ||
|
|
||
| echo "comment-ids=$cids" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Comment on breaking changes | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| PR_NUMBER: ${{ inputs.pr-number }} | ||
| COMMENT_IDS: ${{ steps.find-comments.outputs.comment-ids }} | ||
| HAS_BREAKING: ${{ steps.changelog-check.outputs.has_breaking }} | ||
| run: | | ||
| set -euo pipefail | ||
| marker='<!-- changelog-change-status -->' | ||
|
|
||
| if [[ "$HAS_BREAKING" == "true" ]]; then | ||
| msg='**This PR contains breaking changes.** Please ensure this is intentional and properly documented.' | ||
| else | ||
| msg='No breaking changes detected.' | ||
| fi | ||
|
|
||
| body_content="${marker}"$'\n'"${msg}" | ||
|
|
||
| if [[ -n "${COMMENT_IDS:-}" ]]; then | ||
| # Update all existing comments with the marker | ||
| for cid in $COMMENT_IDS; do | ||
| gh api -X PATCH "repos/${GITHUB_REPOSITORY}/issues/comments/${cid}" --raw-field "body=${body_content}" | ||
| done | ||
| else | ||
| # Create a new comment if none exist | ||
| gh api -X POST "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" --raw-field "body=${body_content}" | ||
| fi | ||
|
|
||
| - name: Fail if invalid | ||
| if: steps.changelog-check.outputs.is_valid != 'true' | ||
| run: | | ||
| echo "::error::CHANGELOG validation failed. Please fix the CHANGELOG.md format." | ||
| exit 1 | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to make
has_breakingan output because in the case of the SDK specifically, we also want to post a comment on the associated CC API PR. This behavior is not a requirement in the case of the ccloud-private repo. By returning thehas_breakingvalue, the caller can decide if it wants to take action or not