fix: update nixfmt workflow to use 'main' branch and improve formatting checks

This commit is contained in:
Menno van Leeuwen 2024-11-18 15:23:08 +01:00
parent 212050a0ee
commit 96fd886f84
Signed by: vleeuwenmenno
SSH Key Fingerprint: SHA256:OJFmjANpakwD3F2Rsws4GLtbdz1TJ5tkQF0RZmF0TRE

View File

@ -3,7 +3,7 @@ name: Nix Format Check
on:
pull_request:
push:
branches: [ master ]
branches: [ main ]
jobs:
check-format:
@ -13,17 +13,32 @@ jobs:
- name: Install Nix
uses: cachix/install-nix-action@v30
with:
extra_nix_config: |
experimental-features = nix-command flakes
- name: Install nixfmt
run: nix-env -i nixfmt-rfc-style
run: nix profile install nixpkgs#nixfmt-rfc-style
- name: Check Nix formatting
run: |
find . -name "*.nix" -type f -exec nixfmt {} \;
if git diff --quiet; then
echo "All Nix files are properly formatted"
exit_code=0
while IFS= read -r file; do
if ! nixfmt "$file"; then
echo "Error: Failed to format $file"
exit_code=1
break
fi
done < <(find . -name "*.nix" -type f)
if [ $exit_code -eq 0 ]; then
if git diff --quiet; then
echo "All Nix files are properly formatted"
else
echo "Error: Some Nix files are not properly formatted"
git diff
exit 1
fi
else
echo "Error: Some Nix files are not properly formatted"
git diff
exit 1
fi
exit $exit_code
fi