From 62c8f4547c3ce303f3a9082f2672833d4dd390fa Mon Sep 17 00:00:00 2001 From: Divit Mittal <64.69.76.69.74.m@gmail.com> Date: Wed, 4 Nov 2026 05:49:38 +0530 Subject: [PATCH] fix(ci): gate flake.lock update to the first Sunday of the month Cron ORs day-of-month and day-of-week when both are set, so "0 0 1-7 * 0" fired on every day from the 1st to the 7th and on every Sunday, opening a flake.lock PR each time. Schedule days 1-7 and skip the job's steps unless it is Sunday; manual dispatch always runs. --- .github/workflows/flake-lock-update.yml | 22 ++++++++++++---- flake/actions/flake-lock-update.nix | 35 ++++++++++++++++++------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/.github/workflows/flake-lock-update.yml b/.github/workflows/flake-lock-update.yml index 80ff902..b874b07 100644 --- a/.github/workflows/flake-lock-update.yml +++ b/.github/workflows/flake-lock-update.yml @@ -12,19 +12,31 @@ jobs: pull-requests: write runs-on: ubuntu-latest steps: - - name: Checkout repo + - id: gate + name: Gate to first Sunday of the month + run: |- + if [ "$GITHUB_EVENT_NAME" != schedule ] || [ "$(date -u +%u)" = 7 ]; then + echo "run=true" >> "$GITHUB_OUTPUT" + else + echo "run=false" >> "$GITHUB_OUTPUT" + fi + - if: steps.gate.outputs.run == 'true' + name: Checkout repo uses: actions/checkout@main with: fetch-depth: 1 persist-credentials: false - - name: Install Nix + - if: steps.gate.outputs.run == 'true' + name: Install Nix uses: nixbuild/nix-quick-install-action@master - - name: Magic Nix Cache(Use GitHub Actions Cache) + - if: steps.gate.outputs.run == 'true' + name: Magic Nix Cache(Use GitHub Actions Cache) uses: DeterminateSystems/magic-nix-cache-action@main - - name: Update flake.lock + - if: steps.gate.outputs.run == 'true' + name: Update flake.lock uses: DeterminateSystems/update-flake-lock@main timeout-minutes: 30 'on': schedule: - - cron: 0 0 1-7 * 0 + - cron: 0 0 1-7 * * workflow_dispatch: {} diff --git a/flake/actions/flake-lock-update.nix b/flake/actions/flake-lock-update.nix index fe9144e..46be4a3 100644 --- a/flake/actions/flake-lock-update.nix +++ b/flake/actions/flake-lock-update.nix @@ -1,14 +1,30 @@ { + lib, common-permissions, common-actions, ... -}: { +}: let + # Cron ORs day-of-month and day-of-week when both are set, so "first Sunday" + # can't be expressed directly: fire on days 1-7 and let this gate pick Sunday. + gate = { + name = "Gate to first Sunday of the month"; + id = "gate"; + run = '' + if [ "$GITHUB_EVENT_NAME" != schedule ] || [ "$(date -u +%u)" = 7 ]; then + echo "run=true" >> "$GITHUB_OUTPUT" + else + echo "run=false" >> "$GITHUB_OUTPUT" + fi + ''; + }; + gated = step: step // {"if" = "steps.gate.outputs.run == 'true'";}; +in { flake.actions-nix.workflows.".github/workflows/flake-lock-update.yml" = { on = { workflow_dispatch = {}; schedule = [ { - cron = "0 0 1-7 * 0"; # First Sunday of every month at midnight + cron = "0 0 1-7 * *"; # Days 1-7; the gate step keeps only Sunday } ]; }; @@ -20,13 +36,14 @@ pull-requests = "write"; }; steps = - common-actions - ++ [ - { - name = "Update flake.lock"; - uses = "DeterminateSystems/update-flake-lock@main"; - } - ]; + [gate] + ++ lib.map gated (common-actions + ++ [ + { + name = "Update flake.lock"; + uses = "DeterminateSystems/update-flake-lock@main"; + } + ]); }; }; }