Skip to content

Commit

Permalink
feat(ci): add PR title check workflow (#12340)
Browse files Browse the repository at this point in the history
* Add PR title check workflow

Add PR title check workflow

Add colon

Add colon

Request change to PR title instead of blocking PR

Request change to PR title instead of blocking PR

Remove change requested if title conforms to the formate

Remove change requested if title conforms to the formate

* fix: workflow: Ensure PR title check posts review comments

fix: workflow: Ensure PR title check posts review comments

* Add fail if title is invalid

Add fail if title is invalid

* fix: workflow: Ensure PR title check fails for invalid titles

fix: workflow: Ensure PR title check fails for invalid titles

* refactor: pr-title-check: Streamline workflow and reduce complexity

refactor: pr-title-check: Streamline workflow and reduce complexity

* Update allowed PR-types pattern

Update allowed PR-types pattern

* Update pr-title-check.yml

Co-authored-by: Rod Vagg <[email protected]>

* Use conventional commit, but allow for legacy

- Allow optional "[skip changelog]" prefix
- Both <type>: <scope>: and <type>(<scope>): formats
- Use conventional commit "scope" instead of area
- Alphabetize <type> and <scope>

* docs: update pull_request_template.md

Adjust pull_request_template.md according to the changes introduced with the PR title check workflow

* fix(ci): update regex to support both PR title formats

fix(ci): update regex to support both PR title formats

* docs: seed CONTRIBUTING.md with pr title and changelog expectations (#12361)

This starts on #12360 as part of landing #12340

* Update .github/workflows/pr-title-check.yml

Co-authored-by: Phi-rjan <[email protected]>

* Update CONTRIBUTING.md

Co-authored-by: Phi-rjan <[email protected]>

* Update CONTRIBUTING.md

Co-authored-by: Phi-rjan <[email protected]>

* Update CONTRIBUTING.md

Co-authored-by: Phi-rjan <[email protected]>

---------

Co-authored-by: Phi-rjan <[email protected]>

* Update .github/workflows/pr-title-check.yml

Co-authored-by: Steve Loeppky <[email protected]>

---------

Co-authored-by: Rod Vagg <[email protected]>
Co-authored-by: Steve Loeppky <[email protected]>
  • Loading branch information
3 people committed Aug 12, 2024
1 parent d360251 commit 33851e9
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 13 deletions.
11 changes: 2 additions & 9 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@
Before you mark the PR ready for review, please make sure that:

- [ ] Commits have a clear commit message.
- [ ] PR title is in the form of of `<PR type>: <area>: <change being made>`
- example: ` fix: mempool: Introduce a cache for valid signatures`
- `PR type`: fix, feat, build, chore, ci, docs, perf, refactor, revert, style, test
- `area`, e.g. api, chain, state, mempool, multisig, networking, paych, proving, sealing, wallet, deps
- [ ] Update CHANGELOG.md or signal that this change does not need it.
- If the PR affects users (e.g., new feature, bug fix, system requirements change), update the CHANGELOG.md and add details to the UNRELEASED section.
- If the change does not require a CHANGELOG.md entry, do one of the following:
- Add `[skip changelog]` to the PR title
- Add the label `skip/changelog` to the PR
- [ ] PR title conforms with [contribution conventions](https://github.com/filecoin-project/lotus/blob/master/README.md#pr-title-conventions)
- [ ] Update CHANGELOG.md or signal that this change does not need it per [contribution conventions](https://github.com/filecoin-project/lotus/blob/master/README.md#changelog-management)
- [ ] New features have usage guidelines and / or documentation updates in
- [ ] [Lotus Documentation](https://lotus.filecoin.io)
- [ ] [Discussion Tutorials](https://github.com/filecoin-project/lotus/discussions/categories/tutorials)
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ jobs:
- if: steps.changelog.outputs.modified == '0'
env:
MESSAGE: |
docs/changelogs/ was not modified in this PR. Please do one of the following:
- add a changelog entry
- add `[skip changelog]` to the PR title
- label the PR with `skip/changelog`
docs/changelogs/ was not modified in this PR. Please do one of the options in [changelog management conventions](https://github.com/filecoin-project/lotus/blob/master/README.md#changelog-management)
run: |
echo "::error::${MESSAGE//$'\n'/%0A}"
exit 1
52 changes: 52 additions & 0 deletions .github/workflows/pr-title-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: PR Title Check

on:
pull_request:
types: [opened, edited, synchronize, reopened]

permissions:
pull-requests: write

jobs:
check-pr-title:
name: Check PR Title
runs-on: ubuntu-latest
steps:
- name: Check PR Title and Manage Review
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const title = context.payload.pull_request.title;
// This should match https://github.com/filecoin-project/lotus/blob/master/README.md#pr-title-conventions
// 202408: Beyond Conventional Commit conventions, we also optionally suport the "scope" outside of paranenthesis for a transitionary period from legacy conventions per https://github.com/filecoin-project/lotus/pull/12340
const pattern = /^(\[skip changelog\]\s)?(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(\w+\))?!?:?\s(\w+:)?\s?[a-z].+$/;
if (!pattern.test(title)) {
await github.rest.pulls.createReview({
...context.repo,
pull_number: context.payload.pull_request.number,
body: 'Please update the PR title to match https://github.com/filecoin-project/lotus/blob/master/README.md#pr-title-conventions',
event: 'REQUEST_CHANGES'
});
core.setFailed('PR title does not match the required format');
} else {
const reviews = await github.rest.pulls.listReviews({
...context.repo,
pull_number: context.payload.pull_request.number
});
const botReview = reviews.data.find(review =>
review.user.type === 'Bot' &&
review.state === 'CHANGES_REQUESTED'
);
if (botReview) {
await github.rest.pulls.dismissReview({
...context.repo,
pull_number: context.payload.pull_request.number,
review_id: botReview.id,
message: 'PR title now matches the required format.'
});
}
}
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
> 2024-08-08: this will get flushed out more soon as part of https://github.com/filecoin-project/lotus/issues/12360
### PR Title Conventions
PR titles should follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) standard.
This means the PR title should be in the form of `<type>(<scope>): <description>`
- example: `fix(mempool): introduce a cache for valid signatures`
- `type`: MUST be one of _build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test_
- `scope`: OPTIONAL arbitrary string that is usually one of _api, chain, deps, mempool, multisig, networking, paych, proving, sealing, state, wallet_
- Breaking changes must add a `!`
- Optionally the PR title can be prefixed with `[skip changelog]` if no changelog edits should be made for this change.
Note that this is enforced with https://github.com/filecoin-project/lotus/blob/master/.github/workflows/pr-title-check.yml

### CHANGELOG Management
To expedite the release process, the CHANGELOG is built-up incrementally.
We enforce that each PR updates CHANGELOG.md or signals that the change doesn't need it.
If the PR affects users (e.g., new feature, bug fix, system requirements change), update the CHANGELOG.md and add details to the UNRELEASED section.
If the change does not require a CHANGELOG.md entry, do one of the following:
- Add `[skip changelog]` to the PR title
- Add the label `skip/changelog` to the PR
Note that this is enforced with https://github.com/filecoin-project/lotus/blob/master/.github/workflows/changelog.yml

0 comments on commit 33851e9

Please sign in to comment.