Skip to content

Commit

Permalink
(wip) [cmd/chloggen] Enhance CI process to validate changelog updates (
Browse files Browse the repository at this point in the history
…#11847)

* (wip) [cmd/chloggen] Enhance CI process to validate changelog updates

* Add a bad link to the new change entry

* Revert bad link. Invalidate the change entry.

* Revert the invalid change entry. Remove unrelated change entry.

* Restore unrelated change entry. Alter unrelated change entry.

* Restore unrelated change entry. Add unrelated change entry.

* Split logic into 'no entry was added' vs 'too many'

* Swap gt/lt conditions to print appropriate message

* Remove extra change entry. Remove correct change entry.

* Restore correct change entry. Add text directly to CHANGELOG.md.

* Revert change to CHANGELOG.md

* Update unreleased/chloggen-ci.yaml

Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com>

* Update .github/workflows/changelog.yml

Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com>

Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com>
  • Loading branch information
djaglowski and TylerHelmuth committed Jul 1, 2022
1 parent 5d6d02d commit 8778b87
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 8 deletions.
85 changes: 77 additions & 8 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This action requires that any PR targeting the main branch should touch at
# least one CHANGELOG file. If a CHANGELOG entry is not required, add the "Skip
# Changelog" label to disable this action.
# This action requires that any PR targeting the main branch should add a
# yaml file to the ./unreleased/ directory. If a CHANGELOG entry is not required,
# or if performing maintance on the Changelog, add the "Skip Changelog" label to
# disable this action.

name: changelog

Expand All @@ -15,19 +16,87 @@ jobs:
if: ${{ !contains(github.event.pull_request.labels.*.name, 'dependencies') && !contains(github.event.pull_request.labels.*.name, 'Skip Changelog')}}

steps:
- uses: actions/checkout@v3
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.17
- name: Cache Go
id: go-cache
uses: actions/cache@v3
with:
path: |
~/go/bin
~/go/pkg/mod
key: changelog-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

- name: Check for CHANGELOG changes
- name: Ensure no changes to the CHANGELOG
run: |
# Only the latest commit of the feature branch is available
# automatically. To diff with the base branch, we need to
# fetch that too (and we only need its latest commit).
git fetch origin ${{ github.base_ref }} --depth=1
if [[ $(git diff --name-only FETCH_HEAD | grep CHANGELOG) ]]
then
echo "A CHANGELOG was modified. Looks good!"
echo "The CHANGELOG should not be directly modified."
echo "Please add a .yaml file to the ./unreleased/ directory."
echo "See CONTRIBUTING.md for more details."
echo "Alternately, add the \"Skip Changelog\" label if this job should be skipped."
false
else
echo "The CHANGELOG was not modified."
fi
- name: Ensure one ./unreleased/*.yaml addition
run: |
git fetch origin ${{ github.base_ref }} --depth=1
if [[ 1 -gt $(git diff --diff-filter=A --name-only FETCH_HEAD ./unreleased | grep -c \\.yaml) ]]
then
echo "No changelog entry was added to the ./unreleased/ directory."
echo "Please add a .yaml file to the ./unreleased/ directory."
echo "See CONTRIBUTING.md for more details."
echo "Alternately, add the \"Skip Changelog\" label if this job should be skipped."
false
elif [[ 1 -lt $(git diff --diff-filter=A --name-only FETCH_HEAD ./unreleased | grep -c \\.yaml) ]]
then
echo "More than 1 changelog entry was added to the ./unreleased/ directory."
echo "Please add a .yaml file to the ./unreleased/ directory."
echo "See CONTRIBUTING.md for more details."
echo "Alternately, add the \"Skip Changelog\" label if this job should be skipped."
false
else
echo "No CHANGELOG was modified."
echo "Please add a CHANGELOG entry, or add the \"Skip Changelog\" label if not required."
echo "A changelog entry was added to the ./unreleased/ directory!"
fi
- name: Ensure no other ./unreleased/*.yaml changes
run: |
git fetch origin ${{ github.base_ref }} --depth=1
if [[ 0 -eq $(git diff --diff-filter=CDMRTUXB --name-only FETCH_HEAD ./unreleased | grep -c \\.yaml) ]]
then
echo "No other changes to ./unreleased/ directory!"
else
echo "Unrelated changes to ./unreleased/ directory detected."
echo "Only a single file may be added to ./unreleased/ directory per PR. No other changes are allowed to this directory."
echo "See CONTRIBUTING.md for more details."
echo "Alternately, add the \"Skip Changelog\" label if this job should be skipped."
false
fi
- name: Validate ./unreleased/*.yaml changes
run: |
make chlog-validate \
|| { echo "New ./unreleased/*.yaml file failed validation."; exit 1; }
# In order to validate any links in the yaml file, render the config to markdown
- name: Render unreleased changelog entries
run: make chlog-preview > changelog_preview.md
- name: Install markdown-link-check
run: npm install -g markdown-link-check
- name: Run markdown-link-check
run: |
markdown-link-check \
--verbose \
--config .github/workflows/check_links_config.json \
changelog_preview.md \
|| { echo "Check that anchor links are lowercase"; exit 1; }
4 changes: 4 additions & 0 deletions unreleased/chloggen-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
change_type: enhancement
component: cmd/chloggen
note: Update CI process to validate new changelog strategy
issues: [11841]

0 comments on commit 8778b87

Please sign in to comment.