Skip to content

Commit 88aec0a

Browse files
committed
ci: enforce Conventional Commits PRs
1 parent 3e047ea commit 88aec0a

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

.github/workflows/lint-pr.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: "Lint PR"
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
10+
permissions:
11+
pull-requests: write
12+
13+
jobs:
14+
main:
15+
name: Validate PR title
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: amannn/action-semantic-pull-request@0723387faaf9b38adef4775cd42cfd5155ed6017 # v5.5.3
19+
id: lint_pr_title
20+
with:
21+
# Ensure the subject doesn't start with an uppercase character.
22+
subjectPattern: ^(?![A-Z]).+$
23+
subjectPatternError: |
24+
Please ensure the subject in the pull request title ("{subject}")
25+
doesn't start with an uppercase character.
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.1
30+
# When the previous steps fail, the workflow would stop. By adding this
31+
# condition you can continue the execution with the populated error message.
32+
if: always() && (steps.lint_pr_title.outputs.error_message != null)
33+
with:
34+
header: pr-title-lint-error
35+
message: |
36+
Hey there and thank you for opening this pull request! :wave:
37+
38+
We require pull request titles to follow the
39+
[Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/)
40+
and it looks like your proposed title needs to be adjusted.
41+
42+
While the specification does not require a specific casing, it recommends being consistent.
43+
We use the pull request title in automated release changelog updates, and would like our
44+
changelogs to look nice.
45+
46+
Details:
47+
48+
```
49+
${{ steps.lint_pr_title.outputs.error_message }}
50+
```
51+
52+
# Delete a previous comment when the issue has been resolved
53+
- if: ${{ steps.lint_pr_title.outputs.error_message == null }}
54+
uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.1
55+
with:
56+
header: pr-title-lint-error
57+
delete: true

CONTRIBUTING.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ interact with the project and how to get involved in development as smoothly as
1818

1919
These things will make a PR more likely to be accepted:
2020

21+
- should address a single concern or task
22+
- avoid bundling unrelated changes
2123
- a well-described requirement
2224
- tests for new code
2325
- tests for old code!
2426
- new code and tests follow the conventions in old code and tests
25-
- a good commit message (see below)
27+
- a good PR title and description (see below)
2628
- all code must abide by [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments)
2729
- names should abide by [What's in a name](https://talks.golang.org/2014/names.slide#1)
2830
- code must build on both Linux and Darwin, via plain `go build`
@@ -31,8 +33,19 @@ These things will make a PR more likely to be accepted:
3133

3234
In general, we will merge a PR once at least one maintainer has endorsed it. For substantial changes, more people may become involved, and you might get asked to resubmit the PR or divide the changes into more than one PR.
3335

34-
## Format of the Commit Message
36+
## Format of the pull request
3537

36-
Limit the subject to 50 characters and write as the continuation of the sentence "If applied, this commit will ..."
37-
Explain what and why in the body, if more than a trivial change; wrap it at 72 characters.
38-
The [following article](https://cbea.ms/git-commit/#seven-rules) has some more helpful advice on documenting your work.
38+
This project enforces that your pull request title match the
39+
[Conventional Commits specification](https://conventionalcommits.org).
40+
When the PR is merged, the full PR changeset will be squashed into a single
41+
commit on the default branch using the PR title as the commit message.
42+
While this approach might surprise some, this is done to simplify the release
43+
process including generating (good) release notes.
44+
45+
The commit message on the default branch will automatically include a reference
46+
back to the PR, so please explain what and why in the PR description.
47+
48+
Each pull request should address a single concern or task.
49+
Avoid bundling unrelated changes into one PR, as it can make the review process
50+
more challenging and less efficient. Keeping PRs focused helps reviewers
51+
understand the purpose and context of the changes.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![LICENSE](https://img.shields.io/github/license/weaveworks/weave-gitops)](https://github.com/weaveworks/weave-gitops/blob/master/LICENSE)
55
[![Contributors](https://img.shields.io/github/contributors/weaveworks/weave-gitops)](https://github.com/weaveworks/weave-gitops/graphs/contributors)
66
[![Release](https://img.shields.io/github/v/release/weaveworks/weave-gitops?include_prereleases)](https://github.com/weaveworks/weave-gitops/releases/latest)
7+
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
78
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fweaveworks%2Fweave-gitops.svg?type=shield&issueType=license)](https://app.fossa.com/projects/git%2Bgithub.com%2Fweaveworks%2Fweave-gitops?ref=badge_shield&issueType=license)
89
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fweaveworks%2Fweave-gitops.svg?type=shield&issueType=security)](https://app.fossa.com/projects/git%2Bgithub.com%2Fweaveworks%2Fweave-gitops?ref=badge_shield&issueType=security)
910
[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/7820/badge)](https://www.bestpractices.dev/projects/7820)

0 commit comments

Comments
 (0)