From 5f63fb5ed6a0b199f55311e2c942aeeea9f92a1f Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Tue, 23 Jun 2026 01:30:36 +0300 Subject: [PATCH 01/10] feat: use commit-check-action to check PR title Replace the committed-based PR title check with our own commit-check-action to eat our own dogfood. - Remove Rust toolchain installation (rustup, cargo-binstall, committed) - Add commit-check.toml config mirroring the existing committed.toml rules - Simplify to a single checkout (action auto-discovers config in .github/) - Keep cspell spell check as a separate step --- .github/commit-check.toml | 21 +++++++++++++++++++ .github/workflows/pre-commit.yml | 36 ++++++-------------------------- 2 files changed, 27 insertions(+), 30 deletions(-) create mode 100644 .github/commit-check.toml diff --git a/.github/commit-check.toml b/.github/commit-check.toml new file mode 100644 index 0000000..33552a8 --- /dev/null +++ b/.github/commit-check.toml @@ -0,0 +1,21 @@ +[commit] +conventional_commits = true +subject_capitalized = false +subject_imperative = false +subject_max_length = 200 +subject_min_length = 1 +allow_commit_types = [ + "fix", + "feat", + "build", + "chore", + "docs", + "style", + "refactor", + "remove", + "deprecate", + "security", + "add", + "perf", + "test", +] diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 8888238..5f2aa6d 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -43,21 +43,14 @@ jobs: permissions: contents: read steps: - - name: Checkout ${{ github.repository }} repo - # needed for cspell.config.yml (project-specific) - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 with: persist-credentials: false - repository: ${{ github.repository }} - ref: ${{ github.sha }} - path: project-repo - - name: Checkout cpp-linter/.github (org) repo - # needed for committed.toml config (org-specific) - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + - uses: commit-check/commit-check-action@v2 with: - persist-credentials: false - repository: cpp-linter/.github - path: org-repo + message: false + branch: false + pr-title: true - name: Get PR title id: get-title env: @@ -67,18 +60,6 @@ jobs: run: |- pr_title=$(gh pr view "${PR_NUMBER}" --repo "${GH_REPO}" --json "title" -q ".title") echo "title=${pr_title}" >> "${GITHUB_OUTPUT}" - - run: rustup update --no-self-update - - name: Install cargo-binstall - uses: cargo-bins/cargo-binstall@aaa84a43aec4955a42c5ffc65d258961e39f276e # v1.19.1 - - name: Install committed - run: cargo binstall -y committed - env: - GITHUB_TOKEN: ${{ github.token }} - - name: conventional-commit - env: - PR_TITLE: "${{ steps.get-title.outputs.title }}" - COMMITTED_CONFIG: ${{ github.workspace }}/org-repo/.github/committed.toml - run: echo "${PR_TITLE}" | committed --config "${COMMITTED_CONFIG}" --commit-file - - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 with: node-version: latest @@ -86,9 +67,4 @@ jobs: env: PR_TITLE: "${{ steps.get-title.outputs.title }}" run: | - if [ -f project-repo/cspell.config.yml ]; then - CSPELL_CONFIG="project-repo/cspell.config.yml" - else - CSPELL_CONFIG="org-repo/cspell.config.yml" - fi - echo "${PR_TITLE}" | npx cspell-cli lint --config "${CSPELL_CONFIG}" stdin + echo "${PR_TITLE}" | npx cspell-cli lint --config cspell.config.yml stdin From 368252251523a7a2324d0679faa227bf23d5808e Mon Sep 17 00:00:00 2001 From: Xianpeng Shen Date: Tue, 23 Jun 2026 01:33:38 +0300 Subject: [PATCH 02/10] Apply suggestion from @shenxianpeng --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 5f2aa6d..6ac1621 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -46,7 +46,7 @@ jobs: - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 with: persist-credentials: false - - uses: commit-check/commit-check-action@v2 + - uses: commit-check/commit-check-action@60e903b3fb06f5e64580b959f58d5b9406a3e002 # v2.9.0 with: message: false branch: false From bacc06ada6d693a37e7856a47c9f5ed7451aee8d Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Thu, 9 Jul 2026 01:20:12 +0300 Subject: [PATCH 03/10] fix: restore cspell config fallback for consuming repos When a consuming repo doesn't have its own cspell.config.yml, download the org-level config from the .github repo as a fallback. Uses curl to fetch the file from the raw GitHub URL. --- .github/workflows/pre-commit.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 924381f..dc143bc 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -67,4 +67,11 @@ jobs: env: PR_TITLE: "${{ steps.get-title.outputs.title }}" run: | - echo "${PR_TITLE}" | npx cspell-cli lint --config cspell.config.yml stdin + if [ -f cspell.config.yml ]; then + CONFIG="cspell.config.yml" + else + CONFIG="org-cspell.config.yml" + curl -sSL -o "${CONFIG}" \ + "https://raw.githubusercontent.com/${{ github.action_repository }}/main/cspell.config.yml" + fi + echo "${PR_TITLE}" | npx cspell-cli lint --config "${CONFIG}" stdin From 55b94dcf0809bbcacb735d3b04d72e721a4d8a7b Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Thu, 9 Jul 2026 01:23:40 +0300 Subject: [PATCH 04/10] fix: dynamically resolve default branch for cspell config fallback Instead of hardcoding 'main', use gh api to get the default branch of the action repository, falling back to 'main' on failure. --- .github/workflows/pre-commit.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index dc143bc..ef1eb57 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -71,7 +71,9 @@ jobs: CONFIG="cspell.config.yml" else CONFIG="org-cspell.config.yml" + DEFAULT_BRANCH=$(gh api "repos/${{ github.action_repository }}" --jq '.default_branch') \ + || DEFAULT_BRANCH="main" curl -sSL -o "${CONFIG}" \ - "https://raw.githubusercontent.com/${{ github.action_repository }}/main/cspell.config.yml" + "https://raw.githubusercontent.com/${{ github.action_repository }}/${DEFAULT_BRANCH}/cspell.config.yml" fi echo "${PR_TITLE}" | npx cspell-cli lint --config "${CONFIG}" stdin From f50ca36d518ceeb44a6eade8ea9f8e79f67d28e5 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Thu, 9 Jul 2026 01:25:09 +0300 Subject: [PATCH 05/10] revert: restore PR author's original simplified cspell check The spell check change is out of scope for this PR (which focuses on replacing committed with commit-check-action). Reverting back to the original approach from the PR author. --- .github/workflows/pre-commit.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index ef1eb57..924381f 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -67,13 +67,4 @@ jobs: env: PR_TITLE: "${{ steps.get-title.outputs.title }}" run: | - if [ -f cspell.config.yml ]; then - CONFIG="cspell.config.yml" - else - CONFIG="org-cspell.config.yml" - DEFAULT_BRANCH=$(gh api "repos/${{ github.action_repository }}" --jq '.default_branch') \ - || DEFAULT_BRANCH="main" - curl -sSL -o "${CONFIG}" \ - "https://raw.githubusercontent.com/${{ github.action_repository }}/${DEFAULT_BRANCH}/cspell.config.yml" - fi - echo "${PR_TITLE}" | npx cspell-cli lint --config "${CONFIG}" stdin + echo "${PR_TITLE}" | npx cspell-cli lint --config cspell.config.yml stdin From 0abd6b31c6b88382e232f72b4f13817cead8a917 Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Thu, 9 Jul 2026 01:28:34 +0300 Subject: [PATCH 06/10] fix: restructure checkouts to keep spell check unchanged - Checkout .github repo to root (no path) so commit-check-action discovers .github/commit-check.toml automatically - Keep checkout of calling repo in project-repo/ for cspell - Remove second .github checkout to org-repo/ (replaced by root checkout) - Remove rustup/committed steps, add commit-check-action - Spell check if-else fallback preserved unchanged from main (path changes from org-repo/ to root since .github is now at root) --- .github/workflows/pre-commit.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 924381f..70c39f7 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -46,6 +46,15 @@ jobs: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: persist-credentials: false + repository: cpp-linter/.github + - name: Checkout ${{ github.repository }} repo + # needed for cspell.config.yml (project-specific) + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + persist-credentials: false + repository: ${{ github.repository }} + ref: ${{ github.sha }} + path: project-repo - uses: commit-check/commit-check-action@60e903b3fb06f5e64580b959f58d5b9406a3e002 # v2.9.0 with: message: false @@ -67,4 +76,9 @@ jobs: env: PR_TITLE: "${{ steps.get-title.outputs.title }}" run: | - echo "${PR_TITLE}" | npx cspell-cli lint --config cspell.config.yml stdin + if [ -f project-repo/cspell.config.yml ]; then + CSPELL_CONFIG="project-repo/cspell.config.yml" + else + CSPELL_CONFIG="cspell.config.yml" + fi + echo "${PR_TITLE}" | npx cspell-cli lint --config "${CSPELL_CONFIG}" stdin From 33fda1279384b09fbb7e2b48eee6231d1bd5e241 Mon Sep 17 00:00:00 2001 From: Xianpeng Shen Date: Thu, 9 Jul 2026 01:31:01 +0300 Subject: [PATCH 07/10] Apply suggestions from code review Co-authored-by: Xianpeng Shen --- .github/workflows/pre-commit.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 70c39f7..7828435 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -47,6 +47,7 @@ jobs: with: persist-credentials: false repository: cpp-linter/.github + path: org-repo - name: Checkout ${{ github.repository }} repo # needed for cspell.config.yml (project-specific) uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 @@ -79,6 +80,6 @@ jobs: if [ -f project-repo/cspell.config.yml ]; then CSPELL_CONFIG="project-repo/cspell.config.yml" else - CSPELL_CONFIG="cspell.config.yml" + SPELL_CONFIG="org-repo/cspell.config.yml" fi echo "${PR_TITLE}" | npx cspell-cli lint --config "${CSPELL_CONFIG}" stdin From cc140c159ae4d2a2f5ef40e496804737be41888a Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Thu, 9 Jul 2026 01:32:29 +0300 Subject: [PATCH 08/10] fix: correct variable name typo in cspell fallback SPELL_CONFIG -> CSPELL_CONFIG to match the variable referenced in the npx cspell-cli command --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 7828435..ef44650 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -80,6 +80,6 @@ jobs: if [ -f project-repo/cspell.config.yml ]; then CSPELL_CONFIG="project-repo/cspell.config.yml" else - SPELL_CONFIG="org-repo/cspell.config.yml" + CSPELL_CONFIG="org-repo/cspell.config.yml" fi echo "${PR_TITLE}" | npx cspell-cli lint --config "${CSPELL_CONFIG}" stdin From a4561ac9fd82181fdb0466387905530406e6e02f Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Thu, 9 Jul 2026 01:35:15 +0300 Subject: [PATCH 09/10] fix: checkout .github repo to root so commit-check-action finds config - Remove path from .github checkout so .github/commit-check.toml lands at workspace root for auto-discovery by the action - cspell fallback path adjusts accordingly: root instead of org-repo/ - Spell check if-else logic preserved unchanged from main --- .github/workflows/pre-commit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index ef44650..72bcc4e 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -44,10 +44,10 @@ jobs: contents: read steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + # needed for commit-check.toml and cspell.config.yml fallback with: persist-credentials: false repository: cpp-linter/.github - path: org-repo - name: Checkout ${{ github.repository }} repo # needed for cspell.config.yml (project-specific) uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 @@ -80,6 +80,6 @@ jobs: if [ -f project-repo/cspell.config.yml ]; then CSPELL_CONFIG="project-repo/cspell.config.yml" else - CSPELL_CONFIG="org-repo/cspell.config.yml" + CSPELL_CONFIG="cspell.config.yml" fi echo "${PR_TITLE}" | npx cspell-cli lint --config "${CSPELL_CONFIG}" stdin From d225ee578c66778d855e6e945e39ddb9e30fd17b Mon Sep 17 00:00:00 2001 From: shenxianpeng Date: Thu, 9 Jul 2026 01:37:08 +0300 Subject: [PATCH 10/10] docs: improve comment explaining root-level checkout of .github repo --- .github/workflows/pre-commit.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 72bcc4e..362ba5f 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -44,7 +44,9 @@ jobs: contents: read steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - # needed for commit-check.toml and cspell.config.yml fallback + # No path set — checks out to workspace root so commit-check-action + # can auto-discover .github/commit-check.toml. Also provides + # cspell.config.yml as a fallback for consuming repos. with: persist-credentials: false repository: cpp-linter/.github