|
| 1 | +name: Pull request changelog |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened, labeled, unlabeled] |
| 6 | + |
| 7 | +jobs: |
| 8 | + changelog: |
| 9 | + name: 'check changelog change' |
| 10 | + |
| 11 | + steps: |
| 12 | + - name: Fail if no changelog change when needed |
| 13 | + uses: actions/github-script@v2 |
| 14 | + with: |
| 15 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 16 | + script: | |
| 17 | + const labelsWhereChangelogChangeIsRequired = [ |
| 18 | + 'Action: patch bump', |
| 19 | + 'Action: minor bump', |
| 20 | + 'Action: major bump', |
| 21 | + ]; |
| 22 | + const { data: labels } = await github.issues.listLabelsOnIssue({ |
| 23 | + owner: context.repo.owner, |
| 24 | + repo: context.repo.repo, |
| 25 | + issue_number: context.payload.pull_request.number, |
| 26 | + per_page: 100, |
| 27 | + }); |
| 28 | + const matchingLabels = labels |
| 29 | + .filter(label => labelsWhereChangelogChangeIsRequired.includes(label.name)) |
| 30 | + if (matchingLabels.length === 0) { |
| 31 | + console.log('::debug ::No label requiring changelog change. Nothing to do') |
| 32 | + return; |
| 33 | + } |
| 34 | + const { data: files } = await github.pulls.listFiles({ |
| 35 | + owner: context.repo.owner, |
| 36 | + repo: context.repo.repo, |
| 37 | + pull_number: context.payload.pull_request.number, |
| 38 | + per_page: 100, |
| 39 | + }); |
| 40 | + const fileNotDeletedNames = files |
| 41 | + .filter(file => file.status === 'added' || file.status === 'modified') |
| 42 | + .map(file => file.filename) |
| 43 | + if (!fileNotDeletedNames.includes('CHANGELOG.md')) { |
| 44 | + throw new Error('CHANGELOG.md Unreleased section shoud have line additions when PR is not a no-release') |
| 45 | + } |
0 commit comments