From 96fd886f8437ac92fab5f7a0a84c5221253663a3 Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Mon, 18 Nov 2024 15:23:08 +0100 Subject: [PATCH] fix: update nixfmt workflow to use 'main' branch and improve formatting checks --- .github/workflows/nixfmt.yml | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/.github/workflows/nixfmt.yml b/.github/workflows/nixfmt.yml index 80c0f2c..edec213 100644 --- a/.github/workflows/nixfmt.yml +++ b/.github/workflows/nixfmt.yml @@ -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 \ No newline at end of file