name: "PR Formatting" on: pull_request_target: types: - opened - reopened - edited - synchronize permissions: contents: read statuses: write pull-requests: write issues: write jobs: title-check: name: Title Check runs-on: ubuntu-latest steps: - name: Harden Runner uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0 with: egress-policy: audit - name: Check PR Title id: title_check uses: amannn/action-semantic-pull-request@v6 env: GITHUB_TOKEN: ${{ github.token }} - name: Comment with changelog hint on failure if: failure() uses: actions/github-script@v8 with: script: | const marker = ''; const error = `${{ steps.title_check.outputs.error_message || steps.title_check.outputs.error || '' }}`.trim(); const details = error ? `\n\n**Error:** ${error}` : '\n\n**Error:** See workflow logs.'; const body = `${marker}\n**PR title check failed**\n\n` + `Please use a Conventional Commit-style prefix (e.g., \`feat:\`, \`fix:\`, \`docs:\`, \`chore:\`).\n` + `If this change should appear in release notes, ensure the title reflects the correct category.${details}`; const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, per_page: 100, }); const existing = comments.find((comment) => (comment.body || "").includes(marker)); if (existing) { await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: existing.id, body, }); } else { await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, body, }); } - name: Remove failure comment on success if: success() uses: actions/github-script@v8 with: script: | const marker = ''; const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, per_page: 100, }); const existing = comments.find((comment) => (comment.body || "").includes(marker)); if (!existing) { core.info("No previous PR title failure comment found."); return; } await github.rest.issues.deleteComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: existing.id, }); core.info(`Deleted previous failure comment id=${existing.id}`);