|
| 1 | +name: PR Changelog Check |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + base-ref: |
| 7 | + description: 'Base branch reference for diff comparison' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + pr-number: |
| 11 | + description: 'Pull request number' |
| 12 | + required: true |
| 13 | + type: number |
| 14 | + outputs: |
| 15 | + has_breaking: |
| 16 | + description: 'Whether the PR contains breaking changes' |
| 17 | + value: ${{ jobs.pr-changelog-check.outputs.has_breaking }} |
| 18 | + |
| 19 | +jobs: |
| 20 | + pr-changelog-check: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + permissions: |
| 23 | + actions: read |
| 24 | + contents: read |
| 25 | + pull-requests: write |
| 26 | + outputs: |
| 27 | + has_breaking: ${{ steps.changelog-check.outputs.has_breaking }} |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v6 |
| 30 | + with: |
| 31 | + fetch-depth: 0 # Needed for diff mode |
| 32 | + persist-credentials: false |
| 33 | + |
| 34 | + # Resolve the ref of this reusable workflow so we can checkout the |
| 35 | + # actions repo at the exact version the caller requested. |
| 36 | + - name: Get workflow ref |
| 37 | + id: workflow-ref |
| 38 | + uses: cockroachdb/actions/get-workflow-ref@v0 |
| 39 | + with: |
| 40 | + workflow_name: cockroachdb/actions/.github/workflows/pr-changelog-check.yml |
| 41 | + |
| 42 | + - name: Checkout actions repo |
| 43 | + uses: actions/checkout@v6 |
| 44 | + with: |
| 45 | + repository: cockroachdb/actions |
| 46 | + ref: ${{ steps.workflow-ref.outputs.ref }} |
| 47 | + path: actions-repo |
| 48 | + persist-credentials: false |
| 49 | + |
| 50 | + - name: Validate Changelog |
| 51 | + id: changelog-check |
| 52 | + uses: ./actions-repo/changelog-check |
| 53 | + with: |
| 54 | + check-mode: diff |
| 55 | + base-ref: ${{ inputs.base-ref }} |
| 56 | + |
| 57 | + - name: Find existing changelog comments |
| 58 | + id: find-comments |
| 59 | + env: |
| 60 | + GH_TOKEN: ${{ github.token }} |
| 61 | + run: | |
| 62 | + cids="$(gh api "repos/${GITHUB_REPOSITORY}/issues/${{ inputs.pr-number }}/comments" \ |
| 63 | + --jq '[.[] | select((.body | contains("<!-- changelog-change-status -->")) and .user.login == "github-actions[bot]") | .id] | join(" ")')" |
| 64 | +
|
| 65 | + echo "comment-ids=$cids" >> "$GITHUB_OUTPUT" |
| 66 | +
|
| 67 | + - name: Comment on breaking changes |
| 68 | + env: |
| 69 | + GH_TOKEN: ${{ github.token }} |
| 70 | + PR_NUMBER: ${{ inputs.pr-number }} |
| 71 | + COMMENT_IDS: ${{ steps.find-comments.outputs.comment-ids }} |
| 72 | + HAS_BREAKING: ${{ steps.changelog-check.outputs.has_breaking }} |
| 73 | + run: | |
| 74 | + set -euo pipefail |
| 75 | + marker='<!-- changelog-change-status -->' |
| 76 | +
|
| 77 | + if [[ "$HAS_BREAKING" == "true" ]]; then |
| 78 | + msg='**This PR contains breaking changes.** Please ensure this is intentional and properly documented.' |
| 79 | + else |
| 80 | + msg='No breaking changes detected.' |
| 81 | + fi |
| 82 | +
|
| 83 | + body_content="${marker}"$'\n'"${msg}" |
| 84 | +
|
| 85 | + if [[ -n "${COMMENT_IDS:-}" ]]; then |
| 86 | + # Update all existing comments with the marker |
| 87 | + for cid in $COMMENT_IDS; do |
| 88 | + gh api -X PATCH "repos/${GITHUB_REPOSITORY}/issues/comments/${cid}" --raw-field "body=${body_content}" |
| 89 | + done |
| 90 | + else |
| 91 | + # Create a new comment if none exist |
| 92 | + gh api -X POST "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" --raw-field "body=${body_content}" |
| 93 | + fi |
| 94 | +
|
| 95 | + - name: Fail if invalid |
| 96 | + if: steps.changelog-check.outputs.is_valid != 'true' |
| 97 | + run: | |
| 98 | + echo "::error::CHANGELOG validation failed. Please fix the CHANGELOG.md format." |
| 99 | + exit 1 |
0 commit comments