diff --git a/.github/workflows/check-components-changelog.yml b/.github/workflows/check-components-changelog.yml index c793337b3bcbe..f45849a74c5f4 100644 --- a/.github/workflows/check-components-changelog.yml +++ b/.github/workflows/check-components-changelog.yml @@ -1,4 +1,4 @@ -name: Verify @wordpress/components CHANGELOG update +name: OPTIONAL - Verify @wordpress/components CHANGELOG update on: pull_request: @@ -26,10 +26,39 @@ jobs: fetch-depth: ${{ env.PR_COMMIT_COUNT }} - name: 'Fetch relevant history from origin' run: git fetch origin ${{ github.event.pull_request.base.ref }} - - name: Run git diff + - 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