From 7dc67410bbfa82d7650b80401219f864fa077542 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Thu, 23 Jan 2025 02:54:11 +0000 Subject: [PATCH] ci/update: cancel scheduled runs that don't bump nixpkgs This should help mitigate spammy force-pushes that don't actually update the nixpkgs input. This only affects _scheduled_ runs. Manually triggered updates will always force-push to the update branch. --- .github/workflows/update.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index f600f637..4d9f4247 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -62,6 +62,41 @@ jobs: echo "EOF" >> "$GITHUB_OUTPUT" fi + - name: Check if nixpkgs input was changed + if: github.event_name == 'schedule' + env: + repo: ${{ github.repository }} + branch: update/${{ github.ref_name }} + run: | + getAttr() { + nix eval --raw --impure \ + --expr '{ ref }: builtins.getFlake ref' \ + --argstr ref "$1" "$2" + } + getNixpkgsRev() { + getAttr "$1" 'inputs.nixpkgs.rev' + } + old=$( + getNixpkgsRev "github:$repo/$branch" \ + || echo "" # Could fail, e.g. if the branch is deleted + ) + new=$(getNixpkgsRev '.') + if [[ "$old" = "$new" ]]; then + ( + echo "nixpkgs rev has not changed ($new). Stopping..." + echo 'You can re-run the workflow manually to update anyway.' + ) >&2 + ( + echo '## Update cancelled' + echo + echo 'The `nixpkgs` rev has not changed (`'"$new"'`).' + echo + echo 'You can re-run the workflow manually to update anyway.' + echo + ) >> $GITHUB_STEP_SUMMARY + exit 1 + fi + - name: Update generated files id: generate if: inputs.generate || github.event_name == 'schedule'