From 0836a78d84e7150942794e8a2e4920331da8475b Mon Sep 17 00:00:00 2001 From: Pierre Jeanjacquot <26487010+PierreJeanjacquot@users.noreply.github.com> Date: Tue, 29 Sep 2026 13:25:51 +0000 Subject: [PATCH] fix(conventional-commits): report PR title errors in job summary The sticky comment steps read steps.lint_pr_title.outputs.error_message, but the semantic-pull-request step had no id, so the error comment was never posted. Posting it would also need pull-requests: write, which callers only grant as read. Add the missing step id and write the error to the job summary instead of a PR comment, so no extra permission is required. Also lint this repository's PR titles with the local reusable workflow. --- .github/workflows/conventional-commits.yml | 41 ++++++++++------------ .github/workflows/lint-pr-title.yml | 21 +++++++++++ conventional-commits/README.md | 2 +- conventional-commits/workflow-sha256 | 2 +- 4 files changed, 41 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/lint-pr-title.yml diff --git a/.github/workflows/conventional-commits.yml b/.github/workflows/conventional-commits.yml index 4842a14..9c37f58 100644 --- a/.github/workflows/conventional-commits.yml +++ b/.github/workflows/conventional-commits.yml @@ -10,30 +10,25 @@ jobs: permissions: pull-requests: read steps: - - uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1 + - name: Validate PR title + id: lint_pr_title + uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v3.0.5 - # When the previous steps fails, the workflow would stop. By adding this - # condition you can continue the execution with the populated error message. + - name: Report PR title error if: always() && (steps.lint_pr_title.outputs.error_message != null) - with: - header: pr-title-lint-error - message: | - Hey there and thank you for opening this pull request! 👋🏼 - - We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted. - - Details: - - ``` - ${{ steps.lint_pr_title.outputs.error_message }} - ``` - - # Delete a previous comment when the issue has been resolved - - if: ${{ steps.lint_pr_title.outputs.error_message == null }} - uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 # v3.0.5 - with: - header: pr-title-lint-error - delete: true + env: + ERROR_MESSAGE: ${{ steps.lint_pr_title.outputs.error_message }} + run: | + { + echo "## PR title does not follow Conventional Commits" + echo + echo "We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted." + echo + echo "Details:" + echo + echo '```' + printf '%s\n' "$ERROR_MESSAGE" + echo '```' + } >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/lint-pr-title.yml b/.github/workflows/lint-pr-title.yml new file mode 100644 index 0000000..f121670 --- /dev/null +++ b/.github/workflows/lint-pr-title.yml @@ -0,0 +1,21 @@ +name: Lint PR title + +on: + pull_request: + types: + - opened + - edited + - reopened + - synchronize + +permissions: {} + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + lint-pr-title: + permissions: + pull-requests: read + uses: ./.github/workflows/conventional-commits.yml diff --git a/conventional-commits/README.md b/conventional-commits/README.md index 86dfde5..aa05f7b 100644 --- a/conventional-commits/README.md +++ b/conventional-commits/README.md @@ -65,7 +65,7 @@ jobs: ## 📋 Implementation Notes - 🔄 The workflow runs automatically when PRs are opened, edited, or reopened to ensure continuous validation - ✅ It validates the PR title against the Conventional Commits specification with comprehensive checks -- 💬 If validation fails, the workflow will comment on the PR with detailed guidance on how to fix the title +- 💬 If validation fails, the workflow writes detailed guidance on how to fix the title to the job summary - 🔗 This workflow is particularly useful when combined with the release-please workflow for a fully automated release process - 🚀 Helps maintain a high-quality repository that's ready for automated versioning and changelog generation diff --git a/conventional-commits/workflow-sha256 b/conventional-commits/workflow-sha256 index 8366669..d0ce19a 100644 --- a/conventional-commits/workflow-sha256 +++ b/conventional-commits/workflow-sha256 @@ -1 +1 @@ -f4d93a8c6e9661da06e9cdc25bc14514ce8ba762289824d22b4e38ed55d53f45 +7b63fac2d587df6d61130b3df42e93f8e7bb41f6e7b163bae20c452e4b4f02b3