-
Notifications
You must be signed in to change notification settings - Fork 11
54 lines (47 loc) · 1.93 KB
/
check-changelog.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: Check changelog
on:
pull_request:
types:
- opened
- synchronize
- labeled
- unlabeled
jobs:
check-changelog:
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v3.3.0
- name: 🧰 Find Changed Files in changelog.d
id: changed-files
uses: tj-actions/changed-files@v35
with:
files: "./changelog.d/**"
- name: 🔨 Enforce New File or 'No Changelog Required' Label
uses: actions/github-script@v6
# Don't require changelogs for draft PRs:
if: github.event.pull_request.draft == false
with:
script: |
function shouldCheckChangelog() {
return !${{ contains(github.event.pull_request.labels.*.name, 'No Changelog Required') }}
}
function getNewChangelogFiles() {
const newFiles = '${{ steps.changed-files.outputs.added_files }}'.trim().split(' ')
// We check that added_files is the singleton array containing the empty string.
// This is probably a bug in tj-actions/changed-files
return newFiles.length === 1 && newFiles[0] === "" ? [] : newFiles
}
function checkChangelog() {
const newFiles = getNewChangelogFiles()
if (newFiles.length === 0) {
core.info("No files were added by this PR in any of the **/changelog.d directories.")
core.info("Either commit a new file, or add the label 'No Changelog Required' to your PR.")
core.setFailed("Changelog check failed.")
} else
core.info(`The following changelog files were added by this PR:\n${newFiles}`)
}
if (shouldCheckChangelog())
checkChangelog()
else
core.info("PR contains the label 'No Changelog Required', skipping changelog check.")