Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 44 additions & 7 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ on:
jobs:
pre-commit:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}

- name: Set up Python
id: setup-python
Expand All @@ -45,15 +49,30 @@ 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 \
--show-diff-on-failure \
--color=always \
--files
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 "origin/${{ 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
if: github.event_name == 'pull_request'
# 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: 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"
Expand All @@ -62,3 +81,21 @@ jobs:
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 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 "origin/${{ 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# test_github_workflows

Test github workflows
3 changes: 1 addition & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#include "mylib.h"

int main(void) {
int x = 3
;
int x = 3;
printf("%s\n", greet("World"));
return 0;
}
Loading