From 8bbfb0bc8b793fac96dfaa1be93047765d5f12b3 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 17 Jul 2024 07:10:02 +0200 Subject: [PATCH] workflows/check-nix-format: Only ensure for already formatted files This prevents situations where contributors need to suddenly format a huge file even if they only changed a small part of it (e.g. all-packages.nix) --- .github/workflows/check-nix-format.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-nix-format.yml b/.github/workflows/check-nix-format.yml index 77fcc93819378..5395134de09fe 100644 --- a/.github/workflows/check-nix-format.yml +++ b/.github/workflows/check-nix-format.yml @@ -56,12 +56,15 @@ jobs: file=${entry[1]} case $type in A*) + source="" dest=$file ;; M*) + source=$file dest=$file ;; C*|R*) + source=$file read -r -d '' dest ;; *) @@ -69,7 +72,10 @@ jobs: continue esac - if ! nixfmt --check "$dest"; then + # Ignore files that weren't already formatted + if [[ -n "$source" ]] && ! nixfmt --check ${{ env.base }}/"$source" 2>/dev/null; then + echo "Ignoring file $file because it's not formatted in the base commit" + elif ! nixfmt --check "$dest"; then unformattedFiles+=("$file") fi done < <(git diff -z --name-status ${{ env.baseRev }} -- '*.nix')