From ebbf45d1234f16464897d1453cd51ed105a7557c Mon Sep 17 00:00:00 2001 From: vdeo Date: Mon, 16 Mar 2026 21:25:51 +0100 Subject: [PATCH 01/17] non compliant commit for PR. --- src/mylib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mylib.c b/src/mylib.c index cd01d47..7ed2369 100644 --- a/src/mylib.c +++ b/src/mylib.c @@ -5,7 +5,8 @@ static _Thread_local char buf[BUF_SIZE]; -const char* greet(const char* name) { +const char* greet( const char* name) { snprintf(buf, BUF_SIZE, "Hello, %s!", name); - return buf; + return buf + ; } From e6046c5357a92a9ff54a1289e82db6fe5af68eca Mon Sep 17 00:00:00 2001 From: vdeo Date: Mon, 16 Mar 2026 21:36:56 +0100 Subject: [PATCH 02/17] update pre-commit action so that it auto-commits in PRs --- .github/workflows/pre-commit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 201d3aa..c60b5ee 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -53,7 +53,7 @@ jobs: --files - name: Commit if changes - if: github.event_name == 'pull_request' + if: always() && github.event_name == 'pull_request' # always() bypasses the error code from pre-commit. run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" From fc31c6a44522c3b4841d74e40cccee371381e92d Mon Sep 17 00:00:00 2001 From: vdeo Date: Mon, 16 Mar 2026 21:40:39 +0100 Subject: [PATCH 03/17] another try --- .github/workflows/pre-commit.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index c60b5ee..7e35372 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -19,8 +19,9 @@ jobs: pre-commit: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} - name: Set up Python id: setup-python From df3d5978fcf1cf7d4ed503886eb63302e65b9619 Mon Sep 17 00:00:00 2001 From: vdeo Date: Mon, 16 Mar 2026 21:41:48 +0100 Subject: [PATCH 04/17] another try with permissions this time --- .github/workflows/pre-commit.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 7e35372..587af73 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -18,6 +18,9 @@ on: jobs: pre-commit: runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write steps: - uses: actions/checkout@v4 with: From 0ee7efd1faebc6bbb4cda1e5dce9de785b311cbd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 16 Mar 2026 20:42:11 +0000 Subject: [PATCH 05/17] chore: auto-format code [skip ci] --- src/main.c | 3 +-- src/mylib.c | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 77bf4a6..f2399e7 100644 --- a/src/main.c +++ b/src/main.c @@ -2,8 +2,7 @@ #include "mylib.h" int main(void) { - int x = 3 - ; + int x = 3; printf("%s\n", greet("World")); return 0; } diff --git a/src/mylib.c b/src/mylib.c index 7ed2369..cd01d47 100644 --- a/src/mylib.c +++ b/src/mylib.c @@ -5,8 +5,7 @@ static _Thread_local char buf[BUF_SIZE]; -const char* greet( const char* name) { +const char* greet(const char* name) { snprintf(buf, BUF_SIZE, "Hello, %s!", name); - return buf - ; + return buf; } From f5706623e3165194dcb118f32fc2b687134187fb Mon Sep 17 00:00:00 2001 From: vdeo Date: Mon, 16 Mar 2026 21:50:17 +0100 Subject: [PATCH 06/17] Fix action + noncompliant C --- .github/workflows/pre-commit.yaml | 12 ++++++++++-- README.md | 1 + src/main.c | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 587af73..a4e2c0a 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -15,6 +15,10 @@ on: required: false default: '.' +concurrency: + group: pre-commit-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + jobs: pre-commit: runs-on: ubuntu-latest @@ -57,12 +61,16 @@ jobs: --files - name: Commit if changes - if: always() && github.event_name == 'pull_request' # always() bypasses the error code from pre-commit. + # always() bypasses the error code from pre-commit. + # don't run again if this review has been triggered by github-actions[bot], + # since this would create an action loop. + if: always() && github.event_name == 'pull_request' && github.actor != 'github-actions[bot]' + # Normally github message would include [skip ci] to prevent loops, but since this is the pre-commit fixer, it should be stable. run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add -A if ! git diff --cached --quiet; then - git commit -m "chore: auto-format code [skip ci]" + git commit -m "chore: auto-format code" git push fi diff --git a/README.md b/README.md index 81ebdcf..b0b992f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # test_github_workflows + Test github workflows diff --git a/src/main.c b/src/main.c index f2399e7..65e6b00 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,7 @@ int main(void) { int x = 3; - printf("%s\n", greet("World")); + printf("%s\n", + greet("World")); return 0; } From 72e0f456ec1e470b8e4ca661110a413d9d8abcf9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 16 Mar 2026 20:50:39 +0000 Subject: [PATCH 07/17] chore: auto-format code --- src/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 65e6b00..f2399e7 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,6 @@ int main(void) { int x = 3; - printf("%s\n", - greet("World")); + printf("%s\n", greet("World")); return 0; } From c83cb84a491ab530fdf65a54cac49bb6e612ff8d Mon Sep 17 00:00:00 2001 From: vdeo Date: Mon, 16 Mar 2026 21:56:33 +0100 Subject: [PATCH 08/17] more testing --- .github/workflows/pre-commit.yaml | 16 ++++++++++------ src/mylib.c | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index a4e2c0a..df3ef26 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -15,10 +15,6 @@ on: required: false default: '.' -concurrency: - group: pre-commit-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - jobs: pre-commit: runs-on: ubuntu-latest @@ -28,7 +24,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - ref: ${{ github.head_ref }} + ref: ${{ github.head_ref || github.ref_name }} - name: Set up Python id: setup-python @@ -71,6 +67,14 @@ jobs: git config user.email "github-actions[bot]@users.noreply.github.com" git add -A if ! git diff --cached --quiet; then - git commit -m "chore: auto-format code" + git commit -m "chore: auto-format code [skip ci]" git push fi + + - name: Re-run pre-commit hooks + working-directory: ${{ inputs.working-directory }} + run: | + git ls-files | xargs pre-commit run \ + --show-diff-on-failure \ + --color=always \ + --files diff --git a/src/mylib.c b/src/mylib.c index cd01d47..b862f07 100644 --- a/src/mylib.c +++ b/src/mylib.c @@ -6,6 +6,7 @@ static _Thread_local char buf[BUF_SIZE]; const char* greet(const char* name) { - snprintf(buf, BUF_SIZE, "Hello, %s!", name); + snprintf(buf, + BUF_SIZE, "Hello, %s!", name); return buf; } From 12fcf0d5db1b4ca5ac0b538599b3a531b5b7a6f9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 16 Mar 2026 20:56:52 +0000 Subject: [PATCH 09/17] chore: auto-format code [skip ci] --- src/mylib.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mylib.c b/src/mylib.c index b862f07..cd01d47 100644 --- a/src/mylib.c +++ b/src/mylib.c @@ -6,7 +6,6 @@ static _Thread_local char buf[BUF_SIZE]; const char* greet(const char* name) { - snprintf(buf, - BUF_SIZE, "Hello, %s!", name); + snprintf(buf, BUF_SIZE, "Hello, %s!", name); return buf; } From 4436ea4526ed07383ad07b96aa08c2f18950b594 Mon Sep 17 00:00:00 2001 From: vdeo Date: Mon, 16 Mar 2026 21:59:54 +0100 Subject: [PATCH 10/17] x --- .github/workflows/pre-commit.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index df3ef26..cc5d332 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -49,6 +49,7 @@ jobs: pre-commit install - name: Run pre-commit hooks + continue-on-error: true working-directory: ${{ inputs.working-directory }} run: | git ls-files | xargs pre-commit run \ @@ -60,7 +61,7 @@ jobs: # always() bypasses the error code from pre-commit. # don't run again if this review has been triggered by github-actions[bot], # since this would create an action loop. - if: always() && github.event_name == 'pull_request' && github.actor != 'github-actions[bot]' + if: github.event_name == 'pull_request' && github.actor != 'github-actions[bot]' # Normally github message would include [skip ci] to prevent loops, but since this is the pre-commit fixer, it should be stable. run: | git config user.name "github-actions[bot]" From fe424957bb97cacac6df34a541f92f43136e6f69 Mon Sep 17 00:00:00 2001 From: vdeo Date: Mon, 16 Mar 2026 22:01:38 +0100 Subject: [PATCH 11/17] bad commit --- src/mylib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mylib.c b/src/mylib.c index cd01d47..9b9dd0c 100644 --- a/src/mylib.c +++ b/src/mylib.c @@ -6,6 +6,7 @@ static _Thread_local char buf[BUF_SIZE]; const char* greet(const char* name) { - snprintf(buf, BUF_SIZE, "Hello, %s!", name); + snprintf(buf, BUF_SIZE, + "Hello, %s!", name); return buf; } From 01b98baac026ec6f0c1bbb297983da1e037184bf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 16 Mar 2026 21:02:03 +0000 Subject: [PATCH 12/17] chore: auto-format code [skip ci] --- src/mylib.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mylib.c b/src/mylib.c index 9b9dd0c..cd01d47 100644 --- a/src/mylib.c +++ b/src/mylib.c @@ -6,7 +6,6 @@ static _Thread_local char buf[BUF_SIZE]; const char* greet(const char* name) { - snprintf(buf, BUF_SIZE, - "Hello, %s!", name); + snprintf(buf, BUF_SIZE, "Hello, %s!", name); return buf; } From a519e94f6701a5932ba609fbab54dbc4ff1a052b Mon Sep 17 00:00:00 2001 From: vdeo Date: Mon, 16 Mar 2026 22:12:32 +0100 Subject: [PATCH 13/17] more --- .github/workflows/pre-commit.yaml | 36 ++++++++++++++++++++++++------- src/main.c | 3 ++- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index cc5d332..349e18d 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -52,10 +52,20 @@ jobs: continue-on-error: true working-directory: ${{ inputs.working-directory }} run: | - git ls-files | xargs pre-commit run \ - --show-diff-on-failure \ - --color=always \ - --files + if [ "${{ github.event_name }}" = "pull_request" ]; then + git fetch --no-tags --depth=1 origin "${{ github.base_ref }}" + pre-commit run \ + --from-ref "${{ github.base_ref }}" \ + --to-ref "HEAD" \ + --show-diff-on-failure \ + --color=always + else + pre-commit run \ + --from-ref "HEAD~1" \ + --to-ref "HEAD" \ + --show-diff-on-failure \ + --color=always + fi - name: Commit if changes # always() bypasses the error code from pre-commit. @@ -75,7 +85,17 @@ jobs: - name: Re-run pre-commit hooks working-directory: ${{ inputs.working-directory }} run: | - git ls-files | xargs pre-commit run \ - --show-diff-on-failure \ - --color=always \ - --files + if [ "${{ github.event_name }}" = "pull_request" ]; then + git fetch --no-tags --depth=1 origin "${{ github.base_ref }}" + pre-commit run \ + --from-ref "${{ github.base_ref }}" \ + --to-ref "HEAD" \ + --show-diff-on-failure \ + --color=always + else + pre-commit run \ + --from-ref "HEAD~1" \ + --to-ref "HEAD" \ + --show-diff-on-failure \ + --color=always + fi diff --git a/src/main.c b/src/main.c index f2399e7..4ffd537 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,7 @@ int main(void) { int x = 3; - printf("%s\n", greet("World")); + printf("%s\n", greet(" + World")); return 0; } From fd0c009d4900f0fe59865ff0b11efdb36c8046f2 Mon Sep 17 00:00:00 2001 From: vdeo Date: Mon, 16 Mar 2026 22:13:31 +0100 Subject: [PATCH 14/17] bad commit --- src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 4ffd537..1295166 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,7 @@ int main(void) { int x = 3; - printf("%s\n", greet(" - World")); + printf("%s\n", + greet("World")); return 0; } From 2ae60e5fa9ebc3ccab911cf83474dc16f16fcb4b Mon Sep 17 00:00:00 2001 From: vdeo Date: Mon, 16 Mar 2026 22:17:58 +0100 Subject: [PATCH 15/17] yolo --- .github/workflows/pre-commit.yaml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index 349e18d..e8a32ad 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -53,9 +53,8 @@ jobs: working-directory: ${{ inputs.working-directory }} run: | if [ "${{ github.event_name }}" = "pull_request" ]; then - git fetch --no-tags --depth=1 origin "${{ github.base_ref }}" pre-commit run \ - --from-ref "${{ github.base_ref }}" \ + --from-ref "${{ github.event.pull_request.base.sha }}" \ --to-ref "HEAD" \ --show-diff-on-failure \ --color=always @@ -86,9 +85,8 @@ jobs: working-directory: ${{ inputs.working-directory }} run: | if [ "${{ github.event_name }}" = "pull_request" ]; then - git fetch --no-tags --depth=1 origin "${{ github.base_ref }}" pre-commit run \ - --from-ref "${{ github.base_ref }}" \ + --from-ref "${{ github.event.pull_request.base.sha }}" \ --to-ref "HEAD" \ --show-diff-on-failure \ --color=always From 5f5fcadba7c9599d9c490decb4e971c97d27e52f Mon Sep 17 00:00:00 2001 From: vdeo Date: Mon, 16 Mar 2026 22:20:09 +0100 Subject: [PATCH 16/17] yolo --- .github/workflows/pre-commit.yaml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index e8a32ad..a8f2dc4 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -52,9 +52,11 @@ jobs: continue-on-error: true working-directory: ${{ inputs.working-directory }} run: | + git fetch --no-tags --depth=1 origin \ + "${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}" if [ "${{ github.event_name }}" = "pull_request" ]; then pre-commit run \ - --from-ref "${{ github.event.pull_request.base.sha }}" \ + --from-ref "${{ github.base_ref }}" \ --to-ref "HEAD" \ --show-diff-on-failure \ --color=always @@ -84,12 +86,11 @@ jobs: - name: Re-run pre-commit hooks working-directory: ${{ inputs.working-directory }} run: | + git fetch --no-tags --depth=1 origin \ + "${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}" if [ "${{ github.event_name }}" = "pull_request" ]; then pre-commit run \ - --from-ref "${{ github.event.pull_request.base.sha }}" \ - --to-ref "HEAD" \ - --show-diff-on-failure \ - --color=always + --from-ref "${{ github.base_ref }}" \ else pre-commit run \ --from-ref "HEAD~1" \ From 2aad59213ceaa1f10b866fd1430aa6d0acd091b6 Mon Sep 17 00:00:00 2001 From: vdeo Date: Mon, 16 Mar 2026 22:23:35 +0100 Subject: [PATCH 17/17] yolo --- .github/workflows/pre-commit.yaml | 13 +++++++------ src/main.c | 3 +-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index a8f2dc4..5602edc 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -52,11 +52,10 @@ jobs: continue-on-error: true working-directory: ${{ inputs.working-directory }} run: | - git fetch --no-tags --depth=1 origin \ - "${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}" + git fetch --no-tags --depth=1 origin "${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}" if [ "${{ github.event_name }}" = "pull_request" ]; then pre-commit run \ - --from-ref "${{ github.base_ref }}" \ + --from-ref "origin/${{ github.base_ref }}" \ --to-ref "HEAD" \ --show-diff-on-failure \ --color=always @@ -86,11 +85,13 @@ jobs: - name: Re-run pre-commit hooks working-directory: ${{ inputs.working-directory }} run: | - git fetch --no-tags --depth=1 origin \ - "${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}" + git fetch --no-tags --depth=1 origin "${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}" if [ "${{ github.event_name }}" = "pull_request" ]; then pre-commit run \ - --from-ref "${{ github.base_ref }}" \ + --from-ref "origin/${{ github.base_ref }}" \ + --to-ref "HEAD" \ + --show-diff-on-failure \ + --color=always else pre-commit run \ --from-ref "HEAD~1" \ diff --git a/src/main.c b/src/main.c index 1295166..f2399e7 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,6 @@ int main(void) { int x = 3; - printf("%s\n", - greet("World")); + printf("%s\n", greet("World")); return 0; }