Skip to content
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

ci: Add PR title check #5548

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/check-pr-title.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Check PR title

on:
pull_request:
types:
- opened
- edited
- synchronize

jobs:
check:
runs-on: ubuntu-latest
env:
PR_TITLE: ${{ github.event.pull_request.title }}
steps:
- id: release
name: Check for release PR format
if: startsWith(github.event.pull_request.title, 'Release')
shell: bash
run: |
if ! grep -qP '^Release [0-9]{4}-[0-9]{2}$' <<< "$PR_TITLE"; then
echo "::warning::Release PR title should be: 'Release <year>-<ISO week number>'"
exit 1
fi

- name: Check for Conventional Commit format
shell: bash
if: steps.release.conclusion == 'skipped'
run: |
if ! grep -qP '^\w+(\(\w+\))?:\s' <<< "$PR_TITLE"; then
echo "::warning::PR title should be in Conventional Commit style, e.g. 'feat: ...'"
exit 1
fi

- name: Check for conventional type allow-list
if: steps.release.conclusion == 'skipped'
shell: bash
run: |
if ! grep -qP '^(ci|db|deps|doc|env|feat|fix|fmt|merge|refactor|repo|revert|style|test|tweak)(\(\w+\))?:\s' <<< "$PR_TITLE"; then
jaskfla marked this conversation as resolved.
Show resolved Hide resolved
echo "::warning::PR title Conventional Type is not on the list; refer to README.md"
exit 1
fi

- name: Check for Linear card number for feature branches
if: steps.release.conclusion == 'skipped' && startsWith(github.event.pull_request.title, 'feat')
shell: bash
run: |
if ! grep -qP '^\w+(\(\w+\))?:\s[A-Z]+-[0-9]+(:\s+\w+)?' <<< "$PR_TITLE"; then
echo "::warning::PR title should start with ticket number, e.g. 'feat(scope): ABC-123: ...'"
exit 1
fi
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,46 @@ In order to automatically format code in VS Code according to our style guide:
2. Enable the **Editor: Format on Save** setting: `"editor.formatOnSave": true`.

Your files will now be formatted automatically when you save them.

### PR title rules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this addition belong in the CONTRIBUTING.md instead?

We also have a (public!) Slab doc: https://beyond-essential.slab.com/posts/pr-titles-conventional-commits-avgsj3xb

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point, will move it there


We use a squash-and-merge strategy when merging PRs into dev. This means the commit messages in dev will match the PR titles. We like to keep standardised commit messages as an easy way to track release changes and for record keeping purposes.

The title of pull requests must be in [Conventional Commit] format. This is used to generate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The title of pull requests must be in [Conventional Commit] format. This is used to generate
The title of pull requests must be in [Conventional Commit](https://beyond-essential.slab.com/posts/pr-titles-conventional-commits-avgsj3xb) format. This is used to generate

changelogs, and to provide a consistent format for commits landing in the main branch, as pull
requests are merged in "squash" mode.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
requests are merged in "squash" mode.
requests are merged in squash mode.

Admittedly a nitpick of nitpicks


```plain
type: <description>
type(scope): <description>
```

When a Linear card is applicable, the Linear card number should be included:

```plain
type: TEAM-123: <description>
type(scope): TEAM-123: <description>
```

The following types are conventional:

- `ci` for changes to the CI/CD workflows
- `db` for changes to the database schema, migrations, etc
- `deps` for changes to dependencies or dependency upgrades
- `doc` for documentation changes
- `env` for changes to the environment variables
- `feat` for new features
- `fix` for bug fixes
- `fmt` for automatic formatting changes
- `merge` for merging between branches (generally between `master` and `dev`)
- `refactor` for code refactoring
- `repo` for changes to the repository structure (e.g. `.gitignore`, `.editorconfig`, etc)
- `revert` for reverting a previous commit
- `style` for stylistic changes that do not affect the meaning of the code
- `test` for adding missing tests or correcting existing tests
- `tweak` for minor changes that do not fit into any other category

When merging, additional change lines may be added to the squashed commit message to provide further
context to be pulled into changelogs.

Using Conventional Commit format for actual commit messages within pull requests is not required.
Loading