|
| 1 | +# This workflow checks that there is either a 'pr/no-changelog' label applied to a PR |
| 2 | +# or there is a .changelog/<pr number>.txt file associated with a PR for a changelog entry |
| 3 | + |
| 4 | +name: Changelog Checker |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + types: [opened, synchronize, labeled] |
| 9 | + # Runs on PRs to main and all release branches |
| 10 | + branches: |
| 11 | + - main |
| 12 | + - release/* |
| 13 | + |
| 14 | +jobs: |
| 15 | + # checks that a .changelog entry is present for a PR |
| 16 | + changelog-check: |
| 17 | + # If there a `pr/no-changelog` label we ignore this check. |
| 18 | + if: "! contains(github.event.pull_request.labels.*.name, 'pr/no-changelog')" |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v2 |
| 23 | + with: |
| 24 | + ref: ${{ github.event.pull_request.head.sha }} |
| 25 | + fetch-depth: 0 # by default the checkout action doesn't checkout all branches |
| 26 | + - name: Check for changelog entry in diff |
| 27 | + run: | |
| 28 | + pull_request_base_main=$(expr "${{ github.event.pull_request.base.ref }}" = "main") |
| 29 | +
|
| 30 | + # check if there is a diff in the .changelog directory |
| 31 | + # for PRs against the main branch, the changelog file name should match the PR number |
| 32 | + if [ pull_request_base_main ]; then |
| 33 | + enforce_matching_pull_request_number="matching this PR number " |
| 34 | + changelog_file_path=".changelog/${{ github.event.pull_request.number }}.txt" |
| 35 | + else |
| 36 | + changelog_file_path=".changelog/*.txt" |
| 37 | + fi |
| 38 | +
|
| 39 | + changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/main")" -- ${changelog_file_path}) |
| 40 | +
|
| 41 | + # If we do not find a file in .changelog/, we fail the check |
| 42 | + if [ -z "$changelog_files" ]; then |
| 43 | + # Fail status check when no .changelog entry was found on the PR |
| 44 | + echo "Did not find a .changelog entry ${enforce_matching_pull_request_number}and the 'pr/no-changelog' label was not applied." |
| 45 | + exit 1 |
| 46 | + else |
| 47 | + echo "Found .changelog entry in PR!" |
| 48 | + fi |
0 commit comments