From ce6472f59514f8280e967e715ba2483eb1a8bc2b Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Sat, 17 Jun 2023 23:04:45 -0700 Subject: [PATCH 01/15] Add an initial workflow --- .github/workflows/commit-checker.yaml | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/commit-checker.yaml diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml new file mode 100644 index 000000000..1c4c54454 --- /dev/null +++ b/.github/workflows/commit-checker.yaml @@ -0,0 +1,42 @@ +name: 'Commit Message Check' +on: + pull_request: + types: + - opened + - edited + - reopened + - synchronize + +jobs: + check-commit-message: + name: Check Commit Message + runs-on: ubuntu-latest + steps: + - name: Check Subject Line Length + uses: gsactions/commit-message-checker@v2 + with: + excludeDescription: 'true' # optional: this excludes the description body of a pull request + excludeTitle: 'true' # optional: this excludes the title of a pull request + checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request + accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true + pattern: '^.{0,50}(\n.*)*$' + error: 'Subject too long (max 50)' + - name: Check Body Line Length + if: ${{ success() || failure() }} + uses: gsactions/commit-message-checker@v2 + with: + excludeDescription: 'true' # optional: this excludes the description body of a pull request + excludeTitle: 'true' # optional: this excludes the title of a pull request + checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request + accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true + pattern: '^.+(\n.{0,72})*$' + error: 'Body line too long (max 72)' + - name: Check that main was not merged + uses: gsactions/commit-message-checker@v2 + with: + excludeDescription: 'true' # optional: this excludes the description body of a pull request + excludeTitle: 'true' # optional: this excludes the title of a pull request + checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request + accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true + pattern: ^(?!Merge branch 'main' into) + error: 'Ticket branch needs to be rebased onto main' From fb007176fba1c05959e47af465eeb058b6d1c8dc Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Sat, 17 Jun 2023 23:31:01 -0700 Subject: [PATCH 02/15] add capitalization rule --- .github/workflows/commit-checker.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml index 1c4c54454..1d05f50f0 100644 --- a/.github/workflows/commit-checker.yaml +++ b/.github/workflows/commit-checker.yaml @@ -21,6 +21,16 @@ jobs: accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true pattern: '^.{0,50}(\n.*)*$' error: 'Subject too long (max 50)' + - name: Check Subject Line Capitalization + if: ${{ success() || failure() }} + uses: gsactions/commit-message-checker@v2 + with: + excludeDescription: 'true' # optional: this excludes the description body of a pull request + excludeTitle: 'true' # optional: this excludes the title of a pull request + checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request + accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true + pattern: '^[A-Z]' + error: 'Subject line must begin with an imperative, capitalized' - name: Check Body Line Length if: ${{ success() || failure() }} uses: gsactions/commit-message-checker@v2 From e6de60ba1f6f77bc2cb1b67e8c074365838fe271 Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Sat, 17 Jun 2023 23:31:20 -0700 Subject: [PATCH 03/15] Add ending rule. --- .github/workflows/commit-checker.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml index 1d05f50f0..31d44dd56 100644 --- a/.github/workflows/commit-checker.yaml +++ b/.github/workflows/commit-checker.yaml @@ -31,6 +31,16 @@ jobs: accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true pattern: '^[A-Z]' error: 'Subject line must begin with an imperative, capitalized' + - name: Check Subject Line Ending + if: ${{ success() || failure() }} + uses: gsactions/commit-message-checker@v2 + with: + excludeDescription: 'true' # optional: this excludes the description body of a pull request + excludeTitle: 'true' # optional: this excludes the title of a pull request + checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request + accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true + pattern: '(? Date: Sat, 17 Jun 2023 23:33:27 -0700 Subject: [PATCH 04/15] Run the merge main into check regardless of whether the previous steps succeeded or failed. It is helpful for the developer to get all the feedback at once --- .github/workflows/commit-checker.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml index 31d44dd56..3da3aeaba 100644 --- a/.github/workflows/commit-checker.yaml +++ b/.github/workflows/commit-checker.yaml @@ -52,6 +52,7 @@ jobs: pattern: '^.+(\n.{0,72})*$' error: 'Body line too long (max 72)' - name: Check that main was not merged + if: ${{ success() || failure() }} uses: gsactions/commit-message-checker@v2 with: excludeDescription: 'true' # optional: this excludes the description body of a pull request From b445fb8dcb9e773f12cc4d3d3dbbc8d0a1f6704f Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Sat, 17 Jun 2023 23:50:48 -0700 Subject: [PATCH 05/15] fix body line check --- .github/workflows/commit-checker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml index 3da3aeaba..70c61dc21 100644 --- a/.github/workflows/commit-checker.yaml +++ b/.github/workflows/commit-checker.yaml @@ -49,7 +49,7 @@ jobs: excludeTitle: 'true' # optional: this excludes the title of a pull request checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true - pattern: '^.+(\n.{0,72})*$' + pattern: '^.+(\n.{0,72}\n)*$' error: 'Body line too long (max 72)' - name: Check that main was not merged if: ${{ success() || failure() }} From 9a23c2f021b8dc51681c118b63d6c6d18cb4049e Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Sun, 18 Jun 2023 07:55:42 -0700 Subject: [PATCH 06/15] Add opiniated commit check workflow --- .github/workflows/commit-checker.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml index 70c61dc21..b1db8c7ee 100644 --- a/.github/workflows/commit-checker.yaml +++ b/.github/workflows/commit-checker.yaml @@ -61,3 +61,10 @@ jobs: accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true pattern: ^(?!Merge branch 'main' into) error: 'Ticket branch needs to be rebased onto main' + + check-commit-message-style: + name: Check commit message style + runs-on: ubuntu-latest + steps: + - name: Check + uses: mristin/opinionated-commit-message@v3.0.0 From 12fb8ecd875ce5456e4906738faae0bf83b402f7 Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Sun, 18 Jun 2023 07:57:07 -0700 Subject: [PATCH 07/15] allow one liners. --- .github/workflows/commit-checker.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml index b1db8c7ee..9c1712e60 100644 --- a/.github/workflows/commit-checker.yaml +++ b/.github/workflows/commit-checker.yaml @@ -68,3 +68,5 @@ jobs: steps: - name: Check uses: mristin/opinionated-commit-message@v3.0.0 + with: + allow-one-liners: true From e632bb750f468790a7eb2eec721ac9daee065b90 Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Sun, 18 Jun 2023 08:06:49 -0700 Subject: [PATCH 08/15] Check On push --- .github/workflows/commit-checker.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml index 9c1712e60..f606cdb5f 100644 --- a/.github/workflows/commit-checker.yaml +++ b/.github/workflows/commit-checker.yaml @@ -7,6 +7,8 @@ on: - reopened - synchronize + push: + jobs: check-commit-message: name: Check Commit Message From 7d8510f98d258c7711d54b3acb8b29b39cfade6a Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Sun, 18 Jun 2023 08:20:27 -0700 Subject: [PATCH 09/15] Remove opiniated commit message checker because it was not good enough. --- .github/workflows/commit-checker.yaml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml index f606cdb5f..f61b39583 100644 --- a/.github/workflows/commit-checker.yaml +++ b/.github/workflows/commit-checker.yaml @@ -63,12 +63,3 @@ jobs: accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true pattern: ^(?!Merge branch 'main' into) error: 'Ticket branch needs to be rebased onto main' - - check-commit-message-style: - name: Check commit message style - runs-on: ubuntu-latest - steps: - - name: Check - uses: mristin/opinionated-commit-message@v3.0.0 - with: - allow-one-liners: true From 65f15f8730bf53bfb576dd4ae2141c32523c49f5 Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Sun, 18 Jun 2023 08:47:42 -0700 Subject: [PATCH 10/15] Add an overall message checker --- .github/workflows/commit-checker.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml index f61b39583..eb7b1dab2 100644 --- a/.github/workflows/commit-checker.yaml +++ b/.github/workflows/commit-checker.yaml @@ -63,3 +63,13 @@ jobs: accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true pattern: ^(?!Merge branch 'main' into) error: 'Ticket branch needs to be rebased onto main' + - name: Check overall commit Message + if: ${{ success() || failure() }} + uses: gsactions/commit-message-checker@v2 + with: + excludeDescription: 'true' # optional: this excludes the description body of a pull request + excludeTitle: 'true' # optional: this excludes the title of a pull request + checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request + accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true + pattern: '^(?![A-Z].*\.)[A-Z].{0,49}\r?\n\r?\n(?:.{0,71}\r?\n)*(?:.{0,71}\.)?\r?\n?$' + error: "Something is not right" From 6f4bcb9fdeb0f153fee6a0cdfeaffb5c21951b7c Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Sun, 18 Jun 2023 10:04:02 -0700 Subject: [PATCH 11/15] Allow for one-liners in overall pattern --- .github/workflows/commit-checker.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml index eb7b1dab2..f9805fd56 100644 --- a/.github/workflows/commit-checker.yaml +++ b/.github/workflows/commit-checker.yaml @@ -63,6 +63,7 @@ jobs: accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true pattern: ^(?!Merge branch 'main' into) error: 'Ticket branch needs to be rebased onto main' + # Check the full pattern, now that we covered more common mistakes. - name: Check overall commit Message if: ${{ success() || failure() }} uses: gsactions/commit-message-checker@v2 @@ -71,5 +72,5 @@ jobs: excludeTitle: 'true' # optional: this excludes the title of a pull request checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true - pattern: '^(?![A-Z].*\.)[A-Z].{0,49}\r?\n\r?\n(?:.{0,71}\r?\n)*(?:.{0,71}\.)?\r?\n?$' - error: "Something is not right" + pattern: '^(?![A-Z].*\.)[A-Z].{0,49}(\r?|\r?\n(?:.{0,71}\r?\n)*(?:.{0,71}\.)?\r?\n?)$' + error: "The commit messages do not follow " From 99b599015bd2f55d6540d670cbbb3b1997046eca Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Sun, 18 Jun 2023 10:19:30 -0700 Subject: [PATCH 12/15] Remove push --- .github/workflows/commit-checker.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml index f9805fd56..99422acc3 100644 --- a/.github/workflows/commit-checker.yaml +++ b/.github/workflows/commit-checker.yaml @@ -7,8 +7,6 @@ on: - reopened - synchronize - push: - jobs: check-commit-message: name: Check Commit Message From d4519d4a9def5537b57903c9c9662e8a26b41df5 Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Wed, 21 Jun 2023 09:37:21 -0700 Subject: [PATCH 13/15] Leave extra space before comments --- .github/workflows/commit-checker.yaml | 68 +++++++++++++-------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml index 99422acc3..1ada8b3fb 100644 --- a/.github/workflows/commit-checker.yaml +++ b/.github/workflows/commit-checker.yaml @@ -15,60 +15,60 @@ jobs: - name: Check Subject Line Length uses: gsactions/commit-message-checker@v2 with: - excludeDescription: 'true' # optional: this excludes the description body of a pull request - excludeTitle: 'true' # optional: this excludes the title of a pull request - checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request - accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true + excludeDescription: 'true' # optional: this excludes the description body of a pull request + excludeTitle: 'true' # optional: this excludes the title of a pull request + checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request + accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true pattern: '^.{0,50}(\n.*)*$' - error: 'Subject too long (max 50)' + error: 'Subject line was too long, exceeding 50 characters. Continue in the body of the commit message' - name: Check Subject Line Capitalization if: ${{ success() || failure() }} uses: gsactions/commit-message-checker@v2 with: - excludeDescription: 'true' # optional: this excludes the description body of a pull request - excludeTitle: 'true' # optional: this excludes the title of a pull request - checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request - accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true + excludeDescription: 'true' # optional: this excludes the description body of a pull request + excludeTitle: 'true' # optional: this excludes the title of a pull request + checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request + accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true pattern: '^[A-Z]' - error: 'Subject line must begin with an imperative, capitalized' + error: 'Subject line must begin with an imperative verb in present tense and first letter in uppercase' - name: Check Subject Line Ending if: ${{ success() || failure() }} uses: gsactions/commit-message-checker@v2 with: - excludeDescription: 'true' # optional: this excludes the description body of a pull request - excludeTitle: 'true' # optional: this excludes the title of a pull request - checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request - accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true - pattern: '(? Date: Wed, 21 Jun 2023 09:37:40 -0700 Subject: [PATCH 14/15] Make commit organization a separate job --- .github/workflows/commit-checker.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml index 1ada8b3fb..065c643cb 100644 --- a/.github/workflows/commit-checker.yaml +++ b/.github/workflows/commit-checker.yaml @@ -8,6 +8,20 @@ on: - synchronize jobs: + check-commit-organization: + name: Check if 'main' was merged to the ticket branch + runs-on: ubuntu-latest + steps: + - name: Check that main was not merged + uses: gsactions/commit-message-checker@v2 + with: + excludeDescription: 'true' # optional: this excludes the description body of a pull request + excludeTitle: 'true' # optional: this excludes the title of a pull request + checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request + accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true + pattern: ^(?!Merge branch 'main' into) + error: 'Ticket branch needs to be rebased onto main' + check-commit-message: name: Check Commit Message runs-on: ubuntu-latest From 518e0d9dd542b4aba6dd9e55a97b5788207527fe Mon Sep 17 00:00:00 2001 From: Arun Kannawadi Date: Wed, 21 Jun 2023 10:38:23 -0700 Subject: [PATCH 15/15] Reorganize steps to run individual checks only if the overall commit message checker failed --- .github/workflows/commit-checker.yaml | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/.github/workflows/commit-checker.yaml b/.github/workflows/commit-checker.yaml index 065c643cb..8e258825e 100644 --- a/.github/workflows/commit-checker.yaml +++ b/.github/workflows/commit-checker.yaml @@ -26,7 +26,17 @@ jobs: name: Check Commit Message runs-on: ubuntu-latest steps: + - name: Check overall commit Message + uses: gsactions/commit-message-checker@v2 + with: + excludeDescription: 'true' # optional: this excludes the description body of a pull request + excludeTitle: 'true' # optional: this excludes the title of a pull request + checkAllCommitMessages: 'true' # optional: this checks all commits associated with a pull request + accessToken: ${{ secrets.GITHUB_TOKEN }} # github access token is only required if checkAllCommitMessages is true + pattern: '^(?![A-Z].*\.)[A-Z].{0,49}(\r?|\r?\n(?:.{0,71}\r?\n)*(?:.{0,71}\.)?\r?\n?)$' + error: "The commit messages do not follow " - name: Check Subject Line Length + if: ${{ failure() }} uses: gsactions/commit-message-checker@v2 with: excludeDescription: 'true' # optional: this excludes the description body of a pull request @@ -36,7 +46,7 @@ jobs: pattern: '^.{0,50}(\n.*)*$' error: 'Subject line was too long, exceeding 50 characters. Continue in the body of the commit message' - name: Check Subject Line Capitalization - if: ${{ success() || failure() }} + if: ${{ failure() }} uses: gsactions/commit-message-checker@v2 with: excludeDescription: 'true' # optional: this excludes the description body of a pull request @@ -46,7 +56,7 @@ jobs: pattern: '^[A-Z]' error: 'Subject line must begin with an imperative verb in present tense and first letter in uppercase' - name: Check Subject Line Ending - if: ${{ success() || failure() }} + if: ${{ failure() }} uses: gsactions/commit-message-checker@v2 with: excludeDescription: 'true' # optional: this excludes the description body of a pull request @@ -56,7 +66,7 @@ jobs: pattern: '(?