298 lines
12 KiB
YAML
298 lines
12 KiB
YAML
name: Dependency updates
|
|
|
|
on:
|
|
schedule:
|
|
- cron: "0 6 * * 1"
|
|
workflow_dispatch:
|
|
inputs:
|
|
force_nixpkgs:
|
|
description: "Update nixpkgs even when no watched package version changed"
|
|
type: boolean
|
|
default: false
|
|
|
|
# Read-only by default: the job that runs fetched code (flake updates, update-pins.sh, nix
|
|
# builds and checks) never holds a token that can push. Only the last job may, and it runs
|
|
# nothing it fetched: it applies the first job's diff and opens the pull request.
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: dependency-updates
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
update-dependencies:
|
|
runs-on: ubuntu-24.04
|
|
outputs:
|
|
has_changes: ${{ steps.changes.outputs.has_changes }}
|
|
# A skipped pin, failed package build or failed check: the pull request opens as a
|
|
# draft and the run ends red.
|
|
failed: ${{ (steps.pins.outputs.skipped == 'true' || steps.builds.outputs.failed == 'true' || steps.checks.outputs.failed == 'true') && 'true' || 'false' }}
|
|
steps:
|
|
# No token left in .git/config for the steps that run fetched code (flake updates,
|
|
# update-pins.sh, nix builds); create-pull-request authenticates on its own.
|
|
- name: Checkout
|
|
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Install Nix
|
|
uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 # v22
|
|
|
|
- name: Decide whether nixpkgs should be updated
|
|
id: nixpkgs_gate
|
|
run: |
|
|
set -euo pipefail
|
|
scripts/check-nixpkgs-relevance.sh >> "$GITHUB_OUTPUT"
|
|
|
|
# Step outputs and inputs reach scripts through the environment, never spliced into them.
|
|
- name: Update flake inputs
|
|
env:
|
|
SHOULD_UPDATE_NIXPKGS: ${{ steps.nixpkgs_gate.outputs.should_update_nixpkgs }}
|
|
FORCE_NIXPKGS: ${{ inputs.force_nixpkgs }}
|
|
run: |
|
|
set -euo pipefail
|
|
if [[ "$SHOULD_UPDATE_NIXPKGS" == "true" || "$FORCE_NIXPKGS" == "true" ]]; then
|
|
nix flake update nixpkgs
|
|
else
|
|
echo "Skipping nixpkgs update: watched package versions on nixos-unstable are unchanged."
|
|
fi
|
|
# Every other input, every run; update-pins.sh then refreshes the hashes of the
|
|
# sources that follow one (z2k-detect follows z2k).
|
|
nix flake update zapret z2k nfqws2-keenetic disko
|
|
|
|
# A pin that cannot be updated is put back and listed as "skipped"; the rest go through.
|
|
- name: Update pinned sources
|
|
id: pins
|
|
env:
|
|
GITHUB_TOKEN: ${{ github.token }}
|
|
run: |
|
|
set -euo pipefail
|
|
scripts/update-pins.sh --self-test
|
|
scripts/update-pins.sh | tee "$RUNNER_TEMP/pin-updates.txt"
|
|
if grep -q '^skipped ' "$RUNNER_TEMP/pin-updates.txt"; then
|
|
echo "skipped=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "skipped=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
# A nixpkgs bump can bring a nixfmt whose style differs; restyle the tree with
|
|
# it so the nix-format check passes and the restyle rides along in the PR.
|
|
- name: Reformat Nix files
|
|
run: nix fmt
|
|
|
|
- name: Detect dependency file changes
|
|
id: changes
|
|
run: |
|
|
set -euo pipefail
|
|
if git diff --quiet -- flake.lock pkgs; then
|
|
echo "has_changes=false" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "has_changes=true" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
# One build per package, so a failure names it; like the checks, a failure makes the
|
|
# pull request a draft instead of holding the update back.
|
|
- name: Build updated packages
|
|
id: builds
|
|
if: steps.changes.outputs.has_changes == 'true'
|
|
run: |
|
|
set -uo pipefail
|
|
mapfile -t attrs < <(scripts/update-pins.sh --attrs)
|
|
: > "$RUNNER_TEMP/failed-builds.txt"
|
|
for attr in "${attrs[@]}"; do
|
|
echo "::group::nix build ${attr}"
|
|
nix build --no-link --print-build-logs "$attr" || echo "${attr#.#}" >> "$RUNNER_TEMP/failed-builds.txt"
|
|
echo "::endgroup::"
|
|
done
|
|
if [[ -s "$RUNNER_TEMP/failed-builds.txt" ]]; then
|
|
echo "failed=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "failed=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
# A failing check does not hold the update back: the pull request opens as a draft
|
|
# naming the failures, and the run still ends red (open-pull-request's last step).
|
|
- name: Run flake checks
|
|
id: checks
|
|
if: steps.changes.outputs.has_changes == 'true'
|
|
run: |
|
|
set -uo pipefail
|
|
log="$RUNNER_TEMP/flake-check.log"
|
|
if nix flake check --keep-going --print-build-logs 2>&1 | tee "$log"; then
|
|
echo "failed=false" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
echo "failed=true" >> "$GITHUB_OUTPUT"
|
|
# The check attributes nix marks failed; else the derivations it could not build.
|
|
{
|
|
grep -oE '❌ checks\.[^[:space:]]+' "$log" | sed 's/^❌ //' ||
|
|
grep -oE "Cannot build '/nix/store/[a-z0-9]{32}-[^']+\.drv'" "$log" |
|
|
sed -E "s|^.*/[a-z0-9]{32}-||; s|\.drv'$||"
|
|
} | sort -u > "$RUNNER_TEMP/failed-checks.txt" || true
|
|
|
|
- name: Compose pull request body
|
|
if: steps.changes.outputs.has_changes == 'true'
|
|
env:
|
|
SHOULD_UPDATE_NIXPKGS: ${{ steps.nixpkgs_gate.outputs.should_update_nixpkgs }}
|
|
CHANGED_WATCH_ATTRS: ${{ steps.nixpkgs_gate.outputs.nixpkgs_changed_watch_attrs }}
|
|
PINS_SKIPPED: ${{ steps.pins.outputs.skipped }}
|
|
BUILDS_FAILED: ${{ steps.builds.outputs.failed }}
|
|
CHECKS_FAILED: ${{ steps.checks.outputs.failed }}
|
|
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
run: |
|
|
set -euo pipefail
|
|
{
|
|
echo "## Automated dependency update"
|
|
echo
|
|
echo "Managed by CI; the \`ci/update-dependencies\` branch is reused across runs."
|
|
echo
|
|
echo "### Pinned sources"
|
|
if [[ "$PINS_SKIPPED" == "true" ]]; then
|
|
echo "Some could not be updated and were kept, so this pull request is a draft ([run log]($RUN_URL))."
|
|
fi
|
|
if [[ -s "$RUNNER_TEMP/pin-updates.txt" ]]; then
|
|
sed 's/^/- /' "$RUNNER_TEMP/pin-updates.txt"
|
|
else
|
|
echo "- no pin changes"
|
|
fi
|
|
echo
|
|
echo "### Flake inputs"
|
|
echo "- nixpkgs updated: \`$SHOULD_UPDATE_NIXPKGS\`"
|
|
echo "- changed watched attrs: \`$CHANGED_WATCH_ATTRS\`"
|
|
# The locked revs that moved, against the checked-out lock file.
|
|
git show HEAD:flake.lock | jq -r --slurpfile new flake.lock '
|
|
.nodes as $old | $new[0].nodes | to_entries[]
|
|
| select(.value.locked.rev? != null)
|
|
| (.value.locked.rev) as $rev | ($old[.key].locked.rev // "none") as $prev
|
|
| select($rev != $prev)
|
|
| "- \(.key): `\($prev[0:7])` -> `\($rev[0:7])`"'
|
|
echo
|
|
echo "### Package builds"
|
|
if [[ "$BUILDS_FAILED" == "true" ]]; then
|
|
echo "Failed, so this pull request is a draft ([run log]($RUN_URL)):"
|
|
while IFS= read -r attr; do echo "- \`$attr\`"; done < "$RUNNER_TEMP/failed-builds.txt"
|
|
else
|
|
echo "- all built"
|
|
fi
|
|
echo
|
|
echo "### Flake checks"
|
|
if [[ "$CHECKS_FAILED" == "true" ]]; then
|
|
echo "Failed, so this pull request is a draft ([run log]($RUN_URL)):"
|
|
if [[ -s "$RUNNER_TEMP/failed-checks.txt" ]]; then
|
|
while IFS= read -r check; do echo "- \`$check\`"; done < "$RUNNER_TEMP/failed-checks.txt"
|
|
else
|
|
echo "- no failing check named in the log; see the run"
|
|
fi
|
|
else
|
|
echo "- all passed"
|
|
fi
|
|
echo
|
|
echo '```'
|
|
git diff --stat
|
|
echo '```'
|
|
} > "$RUNNER_TEMP/pr-body.md"
|
|
cat "$RUNNER_TEMP/pr-body.md" >> "$GITHUB_STEP_SUMMARY"
|
|
|
|
# The changes as a patch, new files included, for the job that may push.
|
|
- name: Export the changes
|
|
if: steps.changes.outputs.has_changes == 'true'
|
|
run: |
|
|
set -euo pipefail
|
|
git add -A -- flake.lock '*.nix'
|
|
git diff --cached --binary > "$RUNNER_TEMP/dependency-updates.patch"
|
|
cp "$RUNNER_TEMP/pr-body.md" "$RUNNER_TEMP/dependency-updates.md"
|
|
|
|
- name: Upload the changes
|
|
if: steps.changes.outputs.has_changes == 'true'
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: dependency-updates
|
|
path: |
|
|
${{ runner.temp }}/dependency-updates.patch
|
|
${{ runner.temp }}/dependency-updates.md
|
|
retention-days: 1
|
|
|
|
# With nothing else to propose there is no pull request to carry a skipped pin.
|
|
- name: No dependency changes
|
|
if: steps.changes.outputs.has_changes != 'true'
|
|
env:
|
|
PINS_SKIPPED: ${{ steps.pins.outputs.skipped }}
|
|
run: |
|
|
set -euo pipefail
|
|
if [[ "$PINS_SKIPPED" == "true" ]]; then
|
|
grep '^skipped ' "$RUNNER_TEMP/pin-updates.txt" | sed 's/^/::error::/'
|
|
exit 1
|
|
fi
|
|
echo "No dependency updates detected."
|
|
|
|
open-pull-request:
|
|
needs: update-dependencies
|
|
if: needs.update-dependencies.outputs.has_changes == 'true'
|
|
runs-on: ubuntu-24.04
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Download the changes
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
with:
|
|
name: dependency-updates
|
|
path: ${{ runner.temp }}/dependency-updates
|
|
|
|
# Data only: git applies the diff; nothing from it runs.
|
|
- name: Apply the changes
|
|
run: |
|
|
set -euo pipefail
|
|
git apply --index "$RUNNER_TEMP/dependency-updates/dependency-updates.patch"
|
|
# The commit takes the whole index, whatever add-paths says: refuse a patch
|
|
# that reaches past the lock file and the Nix files the updates and nix fmt touch.
|
|
if git diff --cached --name-only | grep -vxE 'flake\.lock|.+\.nix'; then
|
|
echo "The patch changes files other than flake.lock and *.nix (above)." >&2
|
|
exit 1
|
|
fi
|
|
|
|
- name: Create or update pull request
|
|
id: pr
|
|
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
|
|
with:
|
|
# always-true also turns an open pull request back into a draft.
|
|
draft: ${{ needs.update-dependencies.outputs.failed == 'true' && 'always-true' || 'false' }}
|
|
branch: ci/update-dependencies
|
|
delete-branch: false
|
|
add-paths: |
|
|
flake.lock
|
|
pkgs
|
|
*.nix
|
|
commit-message: "chore(deps): refresh flake inputs and pinned sources"
|
|
title: "chore(deps): refresh flake inputs and pinned sources"
|
|
body-path: ${{ runner.temp }}/dependency-updates/dependency-updates.md
|
|
labels: |
|
|
dependencies
|
|
nix
|
|
|
|
# draft: false leaves an existing draft alone; once nothing was skipped or failed, mark it ready.
|
|
- name: Mark the pull request ready for review
|
|
if: needs.update-dependencies.outputs.failed != 'true' && steps.pr.outputs.pull-request-operation == 'updated'
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
PR_NUMBER: ${{ steps.pr.outputs.pull-request-number }}
|
|
run: |
|
|
set -euo pipefail
|
|
if [[ "$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json isDraft --jq .isDraft)" == "true" ]]; then
|
|
gh pr ready "$PR_NUMBER" --repo "$GITHUB_REPOSITORY"
|
|
fi
|
|
|
|
- name: Fail the run on skipped pins, failed builds or checks
|
|
if: needs.update-dependencies.outputs.failed == 'true'
|
|
env:
|
|
PR_URL: ${{ steps.pr.outputs.pull-request-url }}
|
|
run: |
|
|
echo "::error::Pins were skipped, or package builds or flake checks failed; the update is a draft pull request: $PR_URL"
|
|
exit 1
|