From 26d9861e688000a7eba6275ec521de4f047fbda1 Mon Sep 17 00:00:00 2001 From: Toni Peter Date: Fri, 17 Jan 2025 12:47:36 +0100 Subject: [PATCH 1/3] Fix C formatting again. --- src/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.c b/src/utils.c index 1ce8afde8..742e0c700 100644 --- a/src/utils.c +++ b/src/utils.c @@ -280,8 +280,8 @@ write_script_stats (const char *buf, const char *path, int mode) pd = fopen (path, mode == 0 ? "a" : mode == 1 ? "r+" : "w"); if (pd == NULL) { - g_warning ("%s: Error opening FILE '%s' for script stats: %d - %s", __func__, - path, errno, strerror (errno)); + g_warning ("%s: Error opening FILE '%s' for script stats: %d - %s", + __func__, path, errno, strerror (errno)); return; } From 0951ec69c60cadc7ea54f23f408d0c943f58c5c2 Mon Sep 17 00:00:00 2001 From: Toni Peter Date: Fri, 17 Jan 2025 13:55:40 +0100 Subject: [PATCH 2/3] Run clang-format only over files changed in the PR --- .github/check-c-formatting.sh | 16 ++++++++++++++++ .github/workflows/linting.yml | 4 +--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100755 .github/check-c-formatting.sh diff --git a/.github/check-c-formatting.sh b/.github/check-c-formatting.sh new file mode 100755 index 000000000..1877ae9de --- /dev/null +++ b/.github/check-c-formatting.sh @@ -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 diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index e0d357537..78d2cdd40 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -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: From eab9a1cac7efd204e18e8f6ff2bb45edfd6fe0b6 Mon Sep 17 00:00:00 2001 From: Toni Peter Date: Mon, 20 Jan 2025 13:28:27 +0100 Subject: [PATCH 3/3] Print clang-format version --- .github/check-c-formatting.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/check-c-formatting.sh b/.github/check-c-formatting.sh index 1877ae9de..1047a1d53 100755 --- a/.github/check-c-formatting.sh +++ b/.github/check-c-formatting.sh @@ -8,6 +8,7 @@ git fetch origin $merge_base:refs/remotes/origin/$merge_base +echo "$(clang-format --version)" (git diff --name-only "origin/$merge_base") | while read filename; do extension="${filename##*.}" if [ "$extension" = "c" ] || [ "$extension" = "h" ]; then