diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b7cfd0..4319ce0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,15 +60,46 @@ jobs: server: ${{ fromJson(needs.parse-flake.outputs.servers) }} steps: - uses: actions/checkout@v5 + with: + fetch-depth: 0 - uses: cachix/install-nix-action@v31 with: extra_nix_config: experimental-features = nix-command flakes pipe-operators + - name: Check if build can be skipped + id: skip-check + env: + GH_TOKEN: ${{ github.token }} + run: | + last_sha=$(gh api \ + "repos/${{ github.repository }}/actions/workflows/ci.yml/runs?branch=main&status=success&per_page=1" \ + --jq '.workflow_runs[0].head_sha // empty') + + if [[ -z "$last_sha" ]]; then + echo "No previous successful run found, build required" + echo "skip=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + + echo "Comparing current (${{ github.sha }}) with last successful ($last_sha)" + + current_drv=$(nix eval .#nixosConfigurations.${{ matrix.server }}.config.system.build.toplevel.drvPath --raw) + previous_drv=$(nix eval "git+file://$(pwd)?rev=$last_sha#nixosConfigurations.${{ matrix.server }}.config.system.build.toplevel.drvPath" --raw) + + if [[ "$current_drv" == "$previous_drv" ]]; then + echo "Derivations match, skipping build" + echo "skip=true" >> "$GITHUB_OUTPUT" + else + echo "Derivations differ, build required" + echo "skip=false" >> "$GITHUB_OUTPUT" + fi - uses: cachix/cachix-action@v15 + if: steps.skip-check.outputs.skip != 'true' with: name: sebastian-stork authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" useDaemon: false - name: Build server + if: steps.skip-check.outputs.skip != 'true' run: nix build .#nixosConfigurations.${{ matrix.server }}.config.system.build.toplevel --print-build-logs deploy: needs: [build-check, build-server] diff --git a/flake.lock b/flake.lock index 7e15d35..0a303c5 100644 --- a/flake.lock +++ b/flake.lock @@ -90,11 +90,11 @@ }, "locked": { "dir": "pkgs/firefox-addons", - "lastModified": 1772596991, - "narHash": "sha256-awJJ4ATy9t8Svrx2z0zAftgXnUaGCFb2Ty0u036CnCQ=", + "lastModified": 1772424169, + "narHash": "sha256-mhv7yclJj+qCagNv0WOuob5yQNV1aTqKcJLfBMUqsVA=", "owner": "rycee", "repo": "nur-expressions", - "rev": "cd2d0893966c0a5c27345a9a72d0418b42b7e36d", + "rev": "701de032cc247a1c309a34f0ed646e824efd7ac6", "type": "gitlab" }, "original": { @@ -244,11 +244,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1772542754, - "narHash": "sha256-WGV2hy+VIeQsYXpsLjdr4GvHv5eECMISX1zKLTedhdg=", + "lastModified": 1772198003, + "narHash": "sha256-I45esRSssFtJ8p/gLHUZ1OUaaTaVLluNkABkk6arQwE=", "owner": "nixos", "repo": "nixpkgs", - "rev": "8c809a146a140c5c8806f13399592dbcb1bb5dc4", + "rev": "dd9b079222d43e1943b6ebd802f04fd959dc8e61", "type": "github" }, "original": { @@ -260,11 +260,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1772465433, - "narHash": "sha256-ywy9troNEfpgh0Ee+zaV1UTgU8kYBVKtvPSxh6clYGU=", + "lastModified": 1772047000, + "narHash": "sha256-7DaQVv4R97cii/Qdfy4tmDZMB2xxtyIvNGSwXBBhSmo=", "owner": "nixos", "repo": "nixpkgs", - "rev": "c581273b8d5bdf1c6ce7e0a54da9841e6a763913", + "rev": "1267bb4920d0fc06ea916734c11b0bf004bbe17e", "type": "github" }, "original": { @@ -317,11 +317,11 @@ ] }, "locked": { - "lastModified": 1772495394, - "narHash": "sha256-hmIvE/slLKEFKNEJz27IZ8BKlAaZDcjIHmkZ7GCEjfw=", + "lastModified": 1772401007, + "narHash": "sha256-YHykQg0h9hrlZGpMcywnaFzQ1Kn/5YNCCOSaaAl6z7Q=", "owner": "Mic92", "repo": "sops-nix", - "rev": "1d9b98a29a45abe9c4d3174bd36de9f28755e3ff", + "rev": "d8be5ea4cd3bc363492ab5bc6e874ccdc5465fe4", "type": "github" }, "original": { @@ -397,11 +397,11 @@ ] }, "locked": { - "lastModified": 1772592001, - "narHash": "sha256-945zZWaHJ8BfnL+49GzmKSNOY1SmD/XZnra8B2zfFPM=", + "lastModified": 1772419365, + "narHash": "sha256-+IjvRKrbSQX9/ikWy1ptPJBqG+RildNl7Cd9yypyzU0=", "owner": "nix-community", "repo": "nix-vscode-extensions", - "rev": "94cfd7508800655275c5b2431ba6ca4788552069", + "rev": "96e284c58556366535781d9a476121b2b5e839f1", "type": "github" }, "original": {