-
Notifications
You must be signed in to change notification settings - Fork 1
ci: add workflow to check for conventional commit PR titles #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1a00e48
Initial plan
Copilot 3a64bd2
feat: add workflow to check conventional commit PR titles
Copilot 6817b9c
refactor: use @commitlint/config-conventional instead of custom regex
Copilot 6ea4091
fix: use pipefail so commitlint exit code propagates through tee
Copilot 417871f
refactor: remove commitlint.config.js and generate config inline in w…
Copilot 8a0a6ea
fix: disable color in commitlint output to avoid ANSI codes in PR com…
Copilot 6b75065
fix: delete outdated failure comment when PR title passes validation
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| name: Conventional Commit | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, edited, synchronize, reopened] | ||
| branches: ["main"] | ||
|
|
||
| jobs: | ||
| check-title: | ||
| name: Check PR Title | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: lts/* | ||
|
|
||
| - name: Install commitlint | ||
| run: npm install --no-save @commitlint/cli@20 @commitlint/config-conventional@20 | ||
|
|
||
| - name: Lint PR title | ||
| id: commitlint | ||
| env: | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| run: | | ||
| set -o pipefail | ||
| echo '{"extends":["@commitlint/config-conventional"]}' > .commitlintrc.json | ||
| echo "$PR_TITLE" | npx commitlint --color false 2>&1 | tee /tmp/commitlint-output.txt | ||
|
|
||
| - name: Delete outdated comment on success | ||
| if: success() | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.payload.pull_request.number, | ||
| }); | ||
|
|
||
| const marker = "**PR title does not follow [Conventional Commits]"; | ||
| const existing = comments.find( | ||
| (c) => c.user.type === "Bot" && c.body.includes(marker) | ||
| ); | ||
|
|
||
| if (existing) { | ||
| await github.rest.issues.deleteComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existing.id, | ||
| }); | ||
| } | ||
|
|
||
| - name: Comment on failure | ||
| if: failure() | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const fs = require("fs"); | ||
| const output = fs.readFileSync("/tmp/commitlint-output.txt", "utf8").trim(); | ||
|
|
||
| const body = [ | ||
| `**PR title does not follow [Conventional Commits](https://www.conventionalcommits.org/) format.**`, | ||
| ``, | ||
| `Please update the PR title to match the format: \`type(optional scope): description\``, | ||
| ``, | ||
| `Examples:`, | ||
| `- \`feat: added new feature\``, | ||
| `- \`fix(cli): corrected typo in help message\``, | ||
| `- \`docs: updated README.md\``, | ||
| ``, | ||
| `<details>`, | ||
| `<summary>commitlint output</summary>`, | ||
| ``, | ||
| "```", | ||
| output, | ||
| "```", | ||
| `</details>`, | ||
| ].join("\n"); | ||
|
|
||
| // Find existing bot comment to update instead of creating duplicates | ||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.payload.pull_request.number, | ||
| }); | ||
|
|
||
| const marker = "**PR title does not follow [Conventional Commits]"; | ||
| const existing = comments.find( | ||
| (c) => c.user.type === "Bot" && c.body.includes(marker) | ||
| ); | ||
|
|
||
| if (existing) { | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existing.id, | ||
| body: body, | ||
| }); | ||
| } else { | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.payload.pull_request.number, | ||
| body: body, | ||
| }); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's already a comment and the workflow runs again, the comment will be left outdated. @copilot what would be a good strategy to handle this outdated comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a "Delete outdated comment on success" step that runs when the lint step passes. It finds and deletes any existing bot failure comment, so the PR isn't left with a stale warning after the title is corrected. See
6b75065.