forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (60 loc) · 3.36 KB
/
check-components-changelog.yml
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
55
56
57
58
59
60
61
62
63
64
65
66
name: OPTIONAL - Verify @wordpress/components CHANGELOG update
on:
pull_request:
types: [opened, synchronize]
paths:
- 'packages/components/**'
- '!packages/components/src/**/stories/**'
- '!packages/components/src/**/test/**'
- '!packages/components/src/**/*.android.js'
- '!packages/components/src/**/*.ios.js'
- '!packages/components/src/**/*.native.js'
- '!packages/components/src/**/*.native.scss'
- '!packages/components/src/**/react-native-*'
jobs:
check:
name: Check CHANGELOG diff
runs-on: ubuntu-latest
steps:
- name: 'Get PR commit count'
run: echo "PR_COMMIT_COUNT=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: ${{ env.PR_COMMIT_COUNT }}
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
- name: 'Fetch relevant history from origin'
run: git fetch origin ${{ github.event.pull_request.base.ref }}
- name: Check CHANGELOG status
env:
PR_NUMBER: ${{ github.event.number }}
run: |
changelog_path="packages/components/CHANGELOG.md"
optional_check_notice="This isn't a required check, so if you think your changes are small enough that they don't warrant a CHANGELOG entry, please go ahead and merge without one."
# Fail if the PR doesn't touch the changelog
if git diff --quiet ${{ github.event.pull_request.base.sha }} HEAD -- "$changelog_path"; then
echo "Please add a CHANGELOG entry to $changelog_path"
echo
echo "${optional_check_notice}"
exit 1
fi
pr_link_pattern="\[#${PR_NUMBER}\]\(https://github\.com/WordPress/gutenberg/pull/${PR_NUMBER}\)"
pr_link_grep_pattern="\[#${PR_NUMBER}\](https://github\.com/WordPress/gutenberg/pull/${PR_NUMBER})"
unreleased_section=$(sed -n '/^## Unreleased$/,/^## /p' "${changelog_path}")
# Confirm that the CHANGELOG has an entry for the current PR
if ! grep -nq -e "${pr_link_grep_pattern}" "${changelog_path}"; then
echo "Please add a CHANGELOG entry to $changelog_path, and make sure your CHANGELOG entry has a link to the current PR."
echo
echo "${optional_check_notice}"
exit 1
fi
# Confirm that there is an 'Unreleased' section and that the relevant entry is in that section
if ! grep -nq -e '^## Unreleased' "${changelog_path}" || \
! [[ $unreleased_section = *${pr_link_pattern}* ]]; then
echo "Please make sure your CHANGELOG entry is in the \`## Unreleased\` section"
echo
echo "${optional_check_notice}"
exit 1
fi