From 21497d1fdf2ed40cb5591fffb53b42d853f02305 Mon Sep 17 00:00:00 2001 From: kbauer Date: Tue, 6 May 2025 13:22:02 -0700 Subject: [PATCH 1/7] ci: enforce conventional commit PRs --- .../workflows/lint-conventional-commits.yaml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/lint-conventional-commits.yaml diff --git a/.github/workflows/lint-conventional-commits.yaml b/.github/workflows/lint-conventional-commits.yaml new file mode 100644 index 00000000..83e9aeb7 --- /dev/null +++ b/.github/workflows/lint-conventional-commits.yaml @@ -0,0 +1,22 @@ +name: 🔄 Lint | Conventional Commits + +on: + pull_request: + branches: [main] + +env: + GH_TOKEN: ${{ github.token }} +permissions: + pull-requests: write +jobs: + check-pr-name: + runs-on: ubuntu-latest + steps: + # Low-tech linter to avoid squashing commits into non-semantic conventional commit by addressing the most common cause + - name: Assert PR name adhering to conventional commits + run: | + gh pr view ${{ github.event.number }} --json title + | jq --args '.title | test("\\w+: \\w+")' -e 1 || { + gh pr comment ${{ github.event.number }} \ + --body "PR title does not adhere to conventional commits. Change PR title to ensure that the suggested squash commit follows the conventions and thus ends up in the changelog." + } From d18f4c8d5ad5b4bf89cfe832cc0a1959a23e0a2b Mon Sep 17 00:00:00 2001 From: kbauer Date: Tue, 6 May 2025 13:34:26 -0700 Subject: [PATCH 2/7] ci: avoid checkout in workflow --- .github/workflows/lint-conventional-commits.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-conventional-commits.yaml b/.github/workflows/lint-conventional-commits.yaml index 83e9aeb7..64d5e938 100644 --- a/.github/workflows/lint-conventional-commits.yaml +++ b/.github/workflows/lint-conventional-commits.yaml @@ -15,7 +15,7 @@ jobs: # Low-tech linter to avoid squashing commits into non-semantic conventional commit by addressing the most common cause - name: Assert PR name adhering to conventional commits run: | - gh pr view ${{ github.event.number }} --json title + gh pr --repo ${{ github.repository }} view ${{ github.event.number }} --json title | jq --args '.title | test("\\w+: \\w+")' -e 1 || { gh pr comment ${{ github.event.number }} \ --body "PR title does not adhere to conventional commits. Change PR title to ensure that the suggested squash commit follows the conventions and thus ends up in the changelog." From 89c8f7db1c34e91c0b44bf43d9f701d98e9dc043 Mon Sep 17 00:00:00 2001 From: kbauer Date: Tue, 6 May 2025 13:36:34 -0700 Subject: [PATCH 3/7] ci: fix syntax --- .github/workflows/lint-conventional-commits.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-conventional-commits.yaml b/.github/workflows/lint-conventional-commits.yaml index 64d5e938..3c10fa7f 100644 --- a/.github/workflows/lint-conventional-commits.yaml +++ b/.github/workflows/lint-conventional-commits.yaml @@ -15,8 +15,8 @@ jobs: # Low-tech linter to avoid squashing commits into non-semantic conventional commit by addressing the most common cause - name: Assert PR name adhering to conventional commits run: | - gh pr --repo ${{ github.repository }} view ${{ github.event.number }} --json title - | jq --args '.title | test("\\w+: \\w+")' -e 1 || { + gh pr --repo ${{ github.repository }} view ${{ github.event.number }} --json title | + jq --args '.title | test("\\w+: \\w+")' -e 1 || { gh pr comment ${{ github.event.number }} \ --body "PR title does not adhere to conventional commits. Change PR title to ensure that the suggested squash commit follows the conventions and thus ends up in the changelog." } From 7e2b08442c6dde3f40b3b0dac5f50c8424b750ec Mon Sep 17 00:00:00 2001 From: kbauer Date: Tue, 6 May 2025 13:38:16 -0700 Subject: [PATCH 4/7] ci: limit linter triggers --- .github/workflows/lint-conventional-commits.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/lint-conventional-commits.yaml b/.github/workflows/lint-conventional-commits.yaml index 3c10fa7f..8e80e2d9 100644 --- a/.github/workflows/lint-conventional-commits.yaml +++ b/.github/workflows/lint-conventional-commits.yaml @@ -2,6 +2,7 @@ name: 🔄 Lint | Conventional Commits on: pull_request: + types: [opened, edited] branches: [main] env: From 050796117151bbbd97fcd740c17af3722e951b33 Mon Sep 17 00:00:00 2001 From: kbauer Date: Tue, 6 May 2025 13:42:41 -0700 Subject: [PATCH 5/7] ci: fix commenting --- .github/workflows/lint-conventional-commits.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint-conventional-commits.yaml b/.github/workflows/lint-conventional-commits.yaml index 8e80e2d9..7459df73 100644 --- a/.github/workflows/lint-conventional-commits.yaml +++ b/.github/workflows/lint-conventional-commits.yaml @@ -16,8 +16,9 @@ jobs: # Low-tech linter to avoid squashing commits into non-semantic conventional commit by addressing the most common cause - name: Assert PR name adhering to conventional commits run: | - gh pr --repo ${{ github.repository }} view ${{ github.event.number }} --json title | - jq --args '.title | test("\\w+: \\w+")' -e 1 || { - gh pr comment ${{ github.event.number }} \ - --body "PR title does not adhere to conventional commits. Change PR title to ensure that the suggested squash commit follows the conventions and thus ends up in the changelog." + pr_title=$(gh pr --repo ${{ github.repository }} view ${{ github.event.number }} --json title) + echo "${pr_title}" | + jq --args '.title | test("\\w+: \\w+")' -e 1 || { + gh pr --repo ${{ github.repository }} comment ${{ github.event.number }} \ + --body "PR title '${pr_title}' does not adhere to conventional commits. Change PR title to ensure that the suggested squash commit follows the conventions and thus ends up in the changelog." } From 46220d70c468bef790ed7454fb7c476023c848f5 Mon Sep 17 00:00:00 2001 From: kbauer Date: Tue, 6 May 2025 13:49:08 -0700 Subject: [PATCH 6/7] ci: fix pr comment message --- .github/workflows/lint-conventional-commits.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-conventional-commits.yaml b/.github/workflows/lint-conventional-commits.yaml index 7459df73..bc142e5d 100644 --- a/.github/workflows/lint-conventional-commits.yaml +++ b/.github/workflows/lint-conventional-commits.yaml @@ -16,9 +16,10 @@ jobs: # Low-tech linter to avoid squashing commits into non-semantic conventional commit by addressing the most common cause - name: Assert PR name adhering to conventional commits run: | - pr_title=$(gh pr --repo ${{ github.repository }} view ${{ github.event.number }} --json title) - echo "${pr_title}" | + pr_title_json=$(gh pr --repo ${{ github.repository }} view ${{ github.event.number }} --json title) + echo "${pr_title_json}" | jq --args '.title | test("\\w+: \\w+")' -e 1 || { + pr_title=$(echo "${pr_title_json}" | jq -r '.title') gh pr --repo ${{ github.repository }} comment ${{ github.event.number }} \ --body "PR title '${pr_title}' does not adhere to conventional commits. Change PR title to ensure that the suggested squash commit follows the conventions and thus ends up in the changelog." } From 4d1aede0a9a53bf63d5965862b61a2e0c4a09535 Mon Sep 17 00:00:00 2001 From: kbauer Date: Tue, 6 May 2025 13:50:17 -0700 Subject: [PATCH 7/7] ci: fail on invalid pr titel --- .github/workflows/lint-conventional-commits.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/lint-conventional-commits.yaml b/.github/workflows/lint-conventional-commits.yaml index bc142e5d..48a95c3c 100644 --- a/.github/workflows/lint-conventional-commits.yaml +++ b/.github/workflows/lint-conventional-commits.yaml @@ -22,4 +22,5 @@ jobs: pr_title=$(echo "${pr_title_json}" | jq -r '.title') gh pr --repo ${{ github.repository }} comment ${{ github.event.number }} \ --body "PR title '${pr_title}' does not adhere to conventional commits. Change PR title to ensure that the suggested squash commit follows the conventions and thus ends up in the changelog." + exit 1 }