flake: add automatic update PRs
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Jake Hillion 2024-04-01 17:45:08 +01:00
parent 88378c3179
commit 1dcbf0c755
2 changed files with 67 additions and 0 deletions

View File

@ -21,6 +21,32 @@ trigger:
- tag
- pull_request
---
kind: pipeline
type: docker
name: update
steps:
- name: update inputs
image: nixos/nix:2.20.1
environment:
GIT_AUTHOR_NAME: Drone
GIT_AUTHOR_EMAIL: drone@mg.hillion.co.uk
GITEA_SERVER_TOKEN:
from_secret: GITEA_TOKEN
commands:
- mkdir -p ~/.config/nix
- echo 'experimental-features = nix-command flakes' > ~/.config/nix/nix.conf
- git config credential.helper '!f() { sleep 1; echo "username=drone"; echo "password=${GITEA_SERVER_TOKEN}"; }; f'
- scripts/update_inputs.sh
trigger:
branch:
# - main
event:
- cron
- push
---
kind: signature
hmac: 5af72ec77460d7d914f9177c78febed763ea1a33dc0f0e39e7599bbf8f4ad987

41
scripts/update_inputs.sh Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix -p jq -p git -p tea -p yq-go
set -e
tea logins add --url https://gitea.hillion.co.uk --token $GITEA_SERVER_TOKEN
INIT_HASH=$(git rev-parse HEAD)
PULLS=$(tea pulls list --output yaml | grep -v NOTE)
git remote -v
INPUTS=$(nix flake metadata --json | jq '.locks.nodes | keys | .[]' -r)
for input in $INPUTS; do
echo "Starting update for: $input"
git switch --detach $INIT_HASH
BRANCH=updater/$input
PULL_INDEX=$(echo "$PULLS" | yq ".[] | select( .head == \"$BRANCH\" ) | .index")
nix flake lock --update-input $input
if git diff --exit-code; then
if ! [ -z $PULL_INDEX ]; then
tea pulls close $PULL_INDEX
tea pulls clean $PULL_INDEX
fi
continue
fi
git switch --force-create updater/$input
LAST_MODIFIED=$(nix flake metadata --json | jq ".locks.nodes.\"$input\".locked.lastModified")
git commit --date="$LAST_MODIFIED" -am "updater: update $input"
git push --set-upstream --force origin updater/$input
exit 1
done
git switch --detach $INIT_HASH