Skip to content

Add link to GH compare #277

Add link to GH compare

Add link to GH compare #277

# This workflow ensures that every pull request includes a relevant entry in the project's changelog.
#
# If no new entry is detected in the changelog, this workflow will
# fail and a comment will be posted to the pull request asking
# the author to address the issue. If the issue is resolved,
# the comment will be resolved as well. This behavior can
# be skipped by adding a `skip news` label to the PR...
#
name: Check release notes
on:
pull_request:
types: [ opened, synchronize, reopened, labeled, unlabeled ]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.issue.number || github.ref }}
cancel-in-progress: true
jobs:
check:
name: Check for entry in Changelog
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- uses: actions/checkout@v4
- name: Default MISSING_CHANGELOG_ENTRY to 1
run: echo 'MISSING_CHANGELOG_ENTRY=1' >> "$GITHUB_ENV"
- name: Skip news?
if: "contains(github.event.pull_request.labels.*.name, 'skip news')"
run: echo 'MISSING_CHANGELOG_ENTRY=0' >> "$GITHUB_ENV"
- name: Else, check for changelog entry
if: "!contains(github.event.pull_request.labels.*.name, 'skip news')"
run: |
# shellcheck disable=SC2016
if grep '{gh-pr}`${{ github.event.pull_request.number }}`' ./docs/reference/changelog.md; then
echo 'MISSING_CHANGELOG_ENTRY=0' >> "$GITHUB_ENV"
fi
- name: Find comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: 'Missing changelog entry'
- name: Echo debug info
run: |
echo "MISSING_CHANGELOG_ENTRY=${{ env.MISSING_CHANGELOG_ENTRY }}"
echo "comment-id=${{ steps.fc.outputs.comment-id }}"
echo "comment-node-id=${{ steps.fc.outputs.comment-node-id }}"
# MISSING_CHANGELOG_ENTRY=1 MISSING_CHANGELOG_ENTRY=0
# comment-id='' (A) POST
# comment-id='1234' (C) UNRESOLVE (B) RESOLVE
# (A) Post comment
- name: Post comment
if: ${{ env.MISSING_CHANGELOG_ENTRY == '1' && steps.fc.outputs.comment-id == '' }}
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
### :warning: **Missing changelog entry** :warning:
Please add an entry to the changelog in `docs/reference/changelog.md` for this PR.
The entry should be in the following format:
```markdown
- Description of the change ({gh-pr}`${{ github.event.pull_request.number }}`)
```
If you don't think a changelog entry is necessary for this change, you can add a `skip news` label to this PR.
- name: Error and exit
if: ${{ env.MISSING_CHANGELOG_ENTRY == '1' && steps.fc.outputs.comment-id == '' }}
run: |
echo "::error title=Missing Changelog Entry::Please add an entry to the changelog in docs/reference/changelog.md for the changes in this PR."
exit 1
# (D) Resolve comment
- name: Resolve comment
if: ${{ env.MISSING_CHANGELOG_ENTRY == '0' && steps.fc.outputs.comment-id != '' }}
uses: actions/github-script@v7
with:
script: |
query = `mutation minimizeComment {
minimizeComment(input: { subjectId: "${{ steps.fc.outputs.comment-node-id }}", classifier: RESOLVED }) {
minimizedComment {
isMinimized
minimizedReason
}
}
}`;
const result = await github.graphql(query);
console.log(result);
# (C) Unresolve comment
- name: Unresolve comment
if: ${{ env.MISSING_CHANGELOG_ENTRY == '1' && steps.fc.outputs.comment-id != '' }}
uses: actions/github-script@v7
with:
script: |
query = `mutation unminimizeComment {
unminimizeComment(input: { subjectId: "${{ steps.fc.outputs.comment-node-id }}" }) {
unminimizedComment {
isMinimized
}
}
}`;
const result = await github.graphql(query);
console.log(result);
- name: Error and exit
if: ${{ env.MISSING_CHANGELOG_ENTRY == '1' && steps.fc.outputs.comment-id != '' }}
run: |
echo "::error title=Missing Changelog Entry::Please add an entry to the changelog in docs/reference/changelog.md for the changes in this PR."
exit 1