Skip to content

Commit

Permalink
Run clang-format only over files changed in the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Tehforsch committed Jan 20, 2025
1 parent 26d9861 commit 0951ec6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .github/check-c-formatting.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh
# I wanted to get the merge base using {{ github.base_ref }}, however this is only
# available for the event that opens the PR or edits it, not on pushes to the branch.
# Comparing to main should be an OK alternative, since it will - at worst - do more
# autoformatting than it otherwise would.

[ -z "$1" ] && merge_base=main || merge_base="$1"

git fetch origin $merge_base:refs/remotes/origin/$merge_base

(git diff --name-only "origin/$merge_base") | while read filename; do
extension="${filename##*.}"
if [ "$extension" = "c" ] || [ "$extension" = "h" ]; then
clang-format -i -style=file "$filename"
fi
done
4 changes: 1 addition & 3 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ jobs:
- name: Check out openvas-scanner
uses: actions/checkout@v4
- name: Formatting
run: |
clang-format -i -style=file {src,misc,nasl}/*.{c,h}
git diff --exit-code
run: sh .github/check-c-formatting.sh ${{ github.base_ref }}
Rust:
runs-on: ubuntu-latest
defaults:
Expand Down

0 comments on commit 0951ec6

Please sign in to comment.