-
Notifications
You must be signed in to change notification settings - Fork 129
ci: drop external action for checking PR title format #2388
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
Open
james-garner-canonical
wants to merge
3
commits into
canonical:main
Choose a base branch
from
james-garner-canonical:26-03+ci+roll-our-own-semantic-commit-names
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,84 @@ | ||
| # Copyright 2025 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
|
|
||
| """Check that a PR title follows the Conventional Commits specification. | ||
|
|
||
| Reads the PR title from the PR_TITLE environment variable. | ||
| Exits with a non-zero status and prints an error message if the title is invalid. | ||
|
|
||
| Reference: https://www.conventionalcommits.org/en/v1.0.0/ | ||
|
|
||
| This repo defines a restricted set of commit types and disallows scopes in PR titles. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import re | ||
| import sys | ||
|
|
||
| _TYPES = frozenset({ | ||
| 'chore', | ||
| 'ci', | ||
| 'docs', | ||
| 'feat', | ||
| 'fix', | ||
| 'perf', | ||
| 'refactor', | ||
| 'revert', | ||
| 'test', | ||
| }) | ||
|
|
||
| # <type>[optional scope][optional !]: <description> | ||
| _PATTERN = re.compile( | ||
| r'^(?p<type>[a-za-z]+)' # lower-case only, but let this be validated by _TYPES | ||
| r'(?:\((?P<scope>[^()]+)\))?' | ||
| r'(?P<breaking>!)?' | ||
| r': ' | ||
| r'(?P<description>.+)$' | ||
| ) | ||
|
|
||
|
|
||
| def _main() -> None: | ||
| title = os.environ.get('PR_TITLE', '').strip() | ||
| if not title: | ||
| print('PR_TITLE environment variable is not set or empty.', file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| match = _PATTERN.match(title) | ||
| if not match: | ||
| print( | ||
| f'PR title does not follow Conventional Commits format.\n' | ||
| f'Expected: <type>[!]: <description>\n' | ||
| f'Got: {title!r}\n' | ||
| 'Read more: https://github.com/canonical/operator/blob/main/CONTRIBUTING.md#pull-requests', | ||
| file=sys.stderr, | ||
| ) | ||
| sys.exit(1) | ||
|
|
||
| scope = match.group('scope') | ||
| if scope is not None: | ||
| print( | ||
| f'Scopes are not used in PR titles.\n' | ||
| f'Got: {title!r}\n' | ||
| 'Read more: https://github.com/canonical/operator/blob/main/CONTRIBUTING.md#pull-requests', | ||
| file=sys.stderr, | ||
| ) | ||
| sys.exit(1) | ||
|
|
||
| commit_type = match.group('type') | ||
| if commit_type not in _TYPES: | ||
| print( | ||
| f'Invalid type {commit_type!r} in PR title.\n' | ||
| f'Valid types: {", ".join(sorted(_TYPES))}\n' | ||
| f'Got: {title!r}\n' | ||
| 'Read more: https://github.com/canonical/operator/blob/main/CONTRIBUTING.md#pull-requests', | ||
| file=sys.stderr, | ||
| ) | ||
| sys.exit(1) | ||
|
|
||
| print(f'OK: {title!r}') | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| _main() |
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 |
|---|---|---|
|
|
@@ -3,11 +3,10 @@ name: "Validate PR Title" | |
| # Ensure that the PR title conforms to the Conventional Commits and our choice of types and scopes, so that library version bumps can be detected automatically | ||
|
|
||
| on: | ||
| pull_request_target: # zizmor: ignore[dangerous-triggers] Doesn't touch code - pull_request results in cancellation errors. | ||
| pull_request: | ||
| types: [opened, edited, synchronize] | ||
|
|
||
| permissions: | ||
| pull-requests: read | ||
| permissions: {} | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number }} | ||
|
|
@@ -18,18 +17,9 @@ jobs: | |
| name: Validate PR title | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| types: | | ||
| chore | ||
| ci | ||
| docs | ||
| feat | ||
| fix | ||
| perf | ||
| refactor | ||
| revert | ||
| test | ||
| disallowScopes: ".*" | ||
| persist-credentials: false | ||
| - run: python3 .github/check-conventional-pr-title.py | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about attempting a super-compact inline Python block instead?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't love the idea, I think that will be harder to maintain in future |
||
| env: | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
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.
I think we'd be back to cancellation errors, unless the concurrency group is removed or changed.
Maybe it's cleaner to the remove concurrency seeting, given how simple the job is.
Uh oh!
There was an error while loading. Please reload this page.
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.
I believe the cancelation errors are only due to there being two workflows running right now, the pull_request trigger one from this branch, and the pull_request_target one from main.
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.
I doubt that. We used to have
on: pull_requestoriginally, and had those cancellation errors. I think it's because pushing the branch and creating a PR triggers both "pr created" and "code pushed" events. TBH I never found the root cause.Uh oh!
There was an error while loading. Please reload this page.
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.
I'm certain that the cancellations we see in this PR are because both the
pull_requesttrigger from this branch, and thepull_request_targettrigger frommainare running here, and they define the same concurrency group.I know those aren't the errors you're talking about, just to be clear.
I suggest we merge this PR and keep an eye out for cancellation errors thereafter. If we see the issue you remember, then let's remove the concurrency. I believe the idea with concurrency for this job is to avoid multiple quick PR edits resulting in spurious failures if an intermediate edit made a mistake.