From ddeb89f71fb9153d8eaf418114db4d52b80b08f3 Mon Sep 17 00:00:00 2001 From: PatTheMav Date: Wed, 28 Feb 2024 00:31:05 +0100 Subject: [PATCH] CI: Limit format checks to changed files only Before the CI checks for source code and CMake files would always check the entire source code even if just a single files has been changed. With this update, the formatting script is enhanced to accept a list of files (which is generated as a condition to run the script in the first place) which ensures that a PR will only fail validation over files it changed itself. --- .github/actions/run-clang-format/action.yaml | 2 +- .github/actions/run-cmake-format/action.yaml | 2 +- .github/actions/run-swift-format/action.yaml | 2 +- build-aux/.run-format.zsh | 26 +++++++++++--------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/actions/run-clang-format/action.yaml b/.github/actions/run-clang-format/action.yaml index 433d936ed..fbb5b9cb0 100644 --- a/.github/actions/run-clang-format/action.yaml +++ b/.github/actions/run-clang-format/action.yaml @@ -60,6 +60,6 @@ runs: print ::endgroup:: print ::group::Run clang-format-16 - ./build-aux/run-clang-format --fail-${{ inputs.failCondition }} --check + ./build-aux/run-clang-format --fail-${{ inputs.failCondition }} --check ${(M)changes:#(*.c|*.h|*.cpp|*.hpp|*.m|*.mm)} print ::endgroup:: } diff --git a/.github/actions/run-cmake-format/action.yaml b/.github/actions/run-cmake-format/action.yaml index 14de53b71..0ece8c16c 100644 --- a/.github/actions/run-cmake-format/action.yaml +++ b/.github/actions/run-cmake-format/action.yaml @@ -59,6 +59,6 @@ runs: print ::endgroup:: print ::group::Run cmake-format - ./build-aux/run-cmake-format --fail-${{ inputs.failCondition }} --check + ./build-aux/run-cmake-format --fail-${{ inputs.failCondition }} --check ${(M)changes:#(*.cmake|*CMakeLists.txt)} print ::endgroup:: } diff --git a/.github/actions/run-swift-format/action.yaml b/.github/actions/run-swift-format/action.yaml index 74ca70a5e..a7b5a31c7 100644 --- a/.github/actions/run-swift-format/action.yaml +++ b/.github/actions/run-swift-format/action.yaml @@ -59,6 +59,6 @@ runs: print ::endgroup:: print ::group::Run swift-format - ./build-aux/run-swift-format --fail-${{ inputs.failCondition }} --check + ./build-aux/run-swift-format --fail-${{ inputs.failCondition }} --check ${(M)changes:#(*.swift)} print ::endgroup:: } diff --git a/build-aux/.run-format.zsh b/build-aux/.run-format.zsh index be4687290..e054f26cd 100755 --- a/build-aux/.run-format.zsh +++ b/build-aux/.run-format.zsh @@ -27,7 +27,11 @@ invoke_formatter() { exit 2 } - case ${1} { + local formatter="${1}" + shift + local -a source_files=(${@}) + + case ${formatter} { clang) if (( ${+commands[clang-format-16]} )) { local formatter=clang-format-16 @@ -50,7 +54,8 @@ invoke_formatter() { exit 2 fi - local -a source_files=((libobs|libobs-*|UI|plugins|deps)/**/*.(c|cpp|h|hpp|m|mm)(.N)) + if (( ! #source_files )) source_files=((libobs|libobs-*|UI|plugins|deps)/**/*.(c|cpp|h|hpp|m|mm)(.N)) + source_files=(${source_files:#*/(obs-websocket/deps|decklink/*/decklink-sdk|mac-syphon/syphon-framework|obs-outputs/ftl-sdk|win-dshow/libdshowcapture)/*}) local -a format_args=(-style=file -fallback-style=none) @@ -70,7 +75,8 @@ invoke_formatter() { exit 2 } - local -a source_files=((libobs|libobs-*|UI|plugins|deps|cmake)/**/(CMakeLists.txt|*.cmake)(.N)) + if (( ! #source_files )) source_files=((libobs|libobs-*|UI|plugins|deps|cmake)/**/(CMakeLists.txt|*.cmake)(.N)) + source_files=(${source_files:#*/(obs-outputs/ftl-sdk|jansson|decklink/*/decklink-sdk|obs-websocket|obs-browser|win-dshow/libdshowcapture)/*}) local -a format_args=() @@ -90,7 +96,7 @@ invoke_formatter() { exit 2 } - local -a source_files=((libobs|libobs-*|UI|plugins)/**/*.swift(.N)) + if (( ! #source_files )) source_files=((libobs|libobs-*|UI|plugins)/**/*.swift(.N)) local -a format_args=() ;; @@ -155,11 +161,6 @@ Usage: %B${functrace[1]%:*}%b