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"