Adding github action to check for changelog file (#11894)
* Adding github action to check for changelog file This might have to be slightly different on ENT, where changelog files should be prefixed with an underscore. * Fixing comment * Adding release branches, enhancement more specific Also tidying my rusty bash * More descriptive error messages I also un-nested some if statements. * Reference this PR too
This commit is contained in:
parent
ed8511f8bf
commit
33f6530529
|
@ -0,0 +1,49 @@
|
|||
# This workflow checks that there is either a 'pr/no-changelog' label applied to a PR
|
||||
# or there is a changelog/<pr number>.txt file associated with a PR for a changelog entry
|
||||
|
||||
name: Check Changelog
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, labeled, unlabeled]
|
||||
# Runs on PRs to master
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
# checks that a changelog entry is present for a PR
|
||||
changelog-check:
|
||||
# If there a `pr/no-changelog` label we ignore this check
|
||||
if: "!contains(github.event.pull_request.labels.*.name, 'pr/no-changelog')"
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
fetch-depth: 0 # by default the checkout action doesn't checkout all branches
|
||||
- name: Check for changelog entry in diff
|
||||
run: |
|
||||
# check if there is a diff in the changelog directory
|
||||
changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/${{ github.event.pull_request.base.ref }}")" -- changelog/${{ github.event.pull_request.number }}.txt)
|
||||
|
||||
# If we do not find a file matching the PR # in changelog/, we fail the check
|
||||
if [ -z "$changelog_files" ]; then
|
||||
echo "Did not find a changelog entry named ${{ github.event.pull_request.number }}.txt"
|
||||
echo "If your changelog file is correct, skip this check with the 'pr/no-changelog' label"
|
||||
echo "Reference - https://github.com/hashicorp/vault/pull/10363 and https://github.com/hashicorp/vault/pull/11894"
|
||||
exit 1
|
||||
elif grep -q ':enhancement$' $changelog_files; then
|
||||
# "Enhancement is not a valid type of changelog entry, but it's a common mistake.
|
||||
echo "Found invalid type (enhancement) in changelog - did you mean improvement?"
|
||||
exit 1
|
||||
elif grep -q ':bugs$' $changelog_files; then
|
||||
echo "Found invalid type (bugs) in changelog - did you mean bug?"
|
||||
exit 1
|
||||
elif ! grep -q '```release-note:' $changelog_files; then
|
||||
# People often make changelog files like ```changelog:, which is incorrect.
|
||||
echo "Changelog file did not contain 'release-note' heading - check formatting."
|
||||
exit 1
|
||||
else
|
||||
echo "Found changelog entry in PR!"
|
||||
fi
|
Loading…
Reference in New Issue