Skip to content

Commit

Permalink
Inspired from changelog-check-action
Browse files Browse the repository at this point in the history
  • Loading branch information
phklive committed Jul 18, 2024
1 parent f21f2b5 commit 42782d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
19 changes: 8 additions & 11 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@ on:
types: [opened, reopened, synchronize]

jobs:
# CI job heavily inspired by: https://github.com/tarides/changelog-check-action
changelog:
runs-on: ubuntu-latest
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@main
with:
fetch-depth: 0
- name: Check if CHANGELOG.md is modified
run: |
# Get the list of changed files in the PR
changed_files=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}...${{ github.sha }})
# Check if CHANGELOG.md is in the list of changed files
if echo "$changed_files" | grep -q '^CHANGELOG.md$'; then
echo "CHANGELOG.md has been modified."
else
echo $'::warning file=CHANGELOG.md::CHANGELOG.md has not been modified.\n This warning can be ignored if is has been explicitely decided not to log changes.\n Except in this situation, make sure to add log changes.'
exit 1
fi
- name: Check for changes in changelog
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
NO_CHANGELOG_LABEL: ${{ contains(github.event.pull_request.labels.*.name, 'no changelog') }}
run: ./scripts/check-changelog.sh "${{ inputs.changelog }}"
shell: bash
19 changes: 19 additions & 0 deletions scripts/check-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -uo pipefail

CHANGELOG_FILE="${1:-CHANGES.md}"

if [ "${NO_CHANGELOG_LABEL}" = "true" ]; then
# 'no changelog' set, so finish successfully
echo "::info no changelog label has been set"
exit 0
else
# a changelog check is required
# fail if the diff is empty
if git diff --exit-code "origin/${BASE_REF}" -- "${CHANGELOG_FILE}"; then
>&2 echo "::warning Changes should come with an entry in the CHANGELOG.md file. This behavior
can be overridden by using the \"no changelog\" label, which is used for changes
that trivial / explicitely decided not to need a changelog entry."
exit 1
fi
fi

0 comments on commit 42782d6

Please sign in to comment.