Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/generate-changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ on:
default: 'chore: generate changelog'
type: string

release_commit_pattern:
description: 'Skip changelog generation when the head commit subject matches this extended regular expression. Set to an empty string to disable the check.'
required: false
default: '^chore:[[:space:]]release([[:space:]]|$)'
type: string

token_app_id:
description: 'A GitHub App ID used to generate an access token to create a pull request.'
required: true
Expand Down Expand Up @@ -94,18 +100,40 @@ jobs:
fetch-depth: 0
fetch-tags: true

- name: Check for release commit
id: release_commit
shell: bash
env:
RELEASE_COMMIT_PATTERN: ${{ inputs.release_commit_pattern }}
run: |
subject=$(git log -1 --format=%s)

# A release commit bumps the project version, and the matching tag is usually not
# pushed yet when this workflow runs. Commitizen then has nothing to changelog and
# exits non-zero, failing the job. Skip those commits entirely.
if [ -n "$RELEASE_COMMIT_PATTERN" ] && [[ "$subject" =~ $RELEASE_COMMIT_PATTERN ]]; then
echo 'skip=true' >> "$GITHUB_OUTPUT"
echo "::notice::Head commit is a release commit ('$subject'); skipping changelog generation."
else
echo 'skip=false' >> "$GITHUB_OUTPUT"
fi

- name: Setup Python
if: steps.release_commit.outputs.skip != 'true'
uses: dfinity/ci-tools/actions/setup-python@afeee4fbdc0683a88ec5a74ed7f59a2ce0e833ad # main

- name: Setup Commitizen
if: steps.release_commit.outputs.skip != 'true'
uses: dfinity/ci-tools/actions/setup-commitizen@afeee4fbdc0683a88ec5a74ed7f59a2ce0e833ad # main

- name: Generate changelog
if: steps.release_commit.outputs.skip != 'true'
uses: dfinity/ci-tools/actions/generate-changelog@afeee4fbdc0683a88ec5a74ed7f59a2ce0e833ad # main
with:
file_name: ${{ inputs.file_name }}

- name: Create pull request
if: steps.release_commit.outputs.skip != 'true'
uses: dfinity/ci-tools/actions/create-pr@afeee4fbdc0683a88ec5a74ed7f59a2ce0e833ad # main
with:
branch_name: ${{ inputs.branch_name }}
Expand Down
15 changes: 14 additions & 1 deletion actions/generate-changelog/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,17 @@ runs:
shell: bash
env:
FILE_NAME: ${{ inputs.file_name }}
run: cz changelog --incremental --merge-prerelease --file-name="$FILE_NAME" --version-scheme semver2
run: |
set +e
cz changelog --incremental --merge-prerelease --file-name="$FILE_NAME" --version-scheme semver2
exit_code=$?
set -e

# Commitizen exits 3 when it finds no commits to add to the changelog. That is a
# no-op rather than a failure, so it must not fail the job.
if [ "$exit_code" -eq 3 ]; then
echo "::notice::No commits to add to the changelog; nothing to do."
exit 0
fi

exit "$exit_code"
Loading