From d645d69c6b0e69f24e1efb6ef453d1bf48bd8cec Mon Sep 17 00:00:00 2001 From: Marco Walz Date: Mon, 3 Aug 2026 16:51:46 +0200 Subject: [PATCH] fix(generate-changelog): do not fail on release commits or empty changelogs The generate_changelog workflow fires on every push to main, including when a release PR is merged. Commitizen then has nothing to add to the changelog and exits non-zero, failing the job. Two variants have been observed in dfinity/icp-js-core: - exit 3 ("No commits found") when the tag already exists - exit 16 ("No tag found to do an incremental changelog") when the tag has not been pushed yet, which is the common case since the release tag is pushed manually a couple of minutes after the release PR merges Both are no-ops in intent, not errors. Two complementary changes: - Skip the changelog steps entirely when the head commit subject looks like a release commit, via a new release_commit_pattern input. This covers the exit 16 case, whose cause is the tag not existing yet. - Treat commitizen exit 3 as success in actions/generate-changelog, so a release commit that slips past the subject check (retitled release PR, or a repo that permits merge commits) still does not fail the job. Exit 16 deliberately remains fatal. Unlike exit 3 it is ambiguous: it also fires when tags are genuinely unavailable, for example a shallow clone or a regression in tag fetching. Swallowing it would turn a loud failure into a silent no-op where the changelog quietly stops being generated. Closes #75 Co-Authored-By: Claude Opus 5 (1M context) --- .github/workflows/generate-changelog.yaml | 28 +++++++++++++++++++++++ actions/generate-changelog/action.yaml | 15 +++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/.github/workflows/generate-changelog.yaml b/.github/workflows/generate-changelog.yaml index 75caf29..61497b6 100644 --- a/.github/workflows/generate-changelog.yaml +++ b/.github/workflows/generate-changelog.yaml @@ -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 @@ -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 }} diff --git a/actions/generate-changelog/action.yaml b/actions/generate-changelog/action.yaml index d34be07..233a6a6 100644 --- a/actions/generate-changelog/action.yaml +++ b/actions/generate-changelog/action.yaml @@ -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"