infrastructure/workflows/npins-update.nix
Tom Hubrecht 1ad9ef3d70
All checks were successful
Check meta / check_meta (pull_request) Successful in 17s
Check meta / check_dns (pull_request) Successful in 18s
Check workflows / check_workflows (pull_request) Successful in 18s
Build all the nodes / netaccess01 (pull_request) Successful in 26s
Run pre-commit on all files / pre-commit (pull_request) Successful in 32s
Build all the nodes / ap01 (pull_request) Successful in 41s
Build all the nodes / netcore00 (pull_request) Successful in 27s
Build all the nodes / netcore01 (pull_request) Successful in 26s
Build all the nodes / netcore02 (pull_request) Successful in 26s
Build all the nodes / bridge01 (pull_request) Successful in 51s
Build all the nodes / geo02 (pull_request) Successful in 58s
Build all the nodes / lab-router01 (pull_request) Successful in 1m2s
Build all the nodes / geo01 (pull_request) Successful in 1m5s
Build all the nodes / cof02 (pull_request) Successful in 1m6s
Build all the nodes / hypervisor03 (pull_request) Successful in 1m7s
Build all the nodes / hypervisor01 (pull_request) Successful in 1m7s
Build all the nodes / hypervisor02 (pull_request) Successful in 1m7s
Build all the nodes / iso (pull_request) Successful in 1m13s
Build all the nodes / build01 (pull_request) Successful in 1m15s
Build all the nodes / compute01 (pull_request) Successful in 1m20s
Build the shell / build-shell (pull_request) Successful in 26s
Build all the nodes / tower01 (pull_request) Successful in 51s
Build all the nodes / rescue01 (pull_request) Successful in 1m4s
Build all the nodes / vault01 (pull_request) Successful in 1m2s
Build all the nodes / krz01 (pull_request) Successful in 1m46s
Build all the nodes / web02 (pull_request) Successful in 50s
Build all the nodes / web03 (pull_request) Successful in 51s
Build all the nodes / web01 (pull_request) Successful in 1m7s
Build all the nodes / storage01 (pull_request) Successful in 1m50s
Check workflows / check_workflows (push) Successful in 17s
Run pre-commit on all files / pre-commit (push) Successful in 31s
Build all the nodes / netaccess01 (push) Successful in 24s
Build all the nodes / ap01 (push) Successful in 42s
Build all the nodes / bridge01 (push) Successful in 48s
Build all the nodes / cof02 (push) Successful in 59s
Build all the nodes / geo01 (push) Successful in 1m3s
Build all the nodes / hypervisor03 (push) Successful in 1m3s
Build all the nodes / netcore01 (push) Successful in 21s
Build all the nodes / netcore00 (push) Successful in 22s
Build all the nodes / hypervisor02 (push) Successful in 1m7s
Build all the nodes / hypervisor01 (push) Successful in 1m7s
Build all the nodes / geo02 (push) Successful in 1m7s
Build all the nodes / lab-router01 (push) Successful in 1m7s
Build all the nodes / netcore02 (push) Successful in 22s
Build all the nodes / build01 (push) Successful in 1m13s
Build all the nodes / iso (push) Successful in 1m13s
Build all the nodes / compute01 (push) Successful in 1m20s
Build the shell / build-shell (push) Successful in 23s
Build all the nodes / krz01 (push) Successful in 1m46s
Build all the nodes / tower01 (push) Successful in 46s
Build all the nodes / rescue01 (push) Successful in 1m3s
Build all the nodes / web02 (push) Successful in 54s
Build all the nodes / vault01 (push) Successful in 1m2s
Build all the nodes / web03 (push) Successful in 58s
Build all the nodes / web01 (push) Successful in 1m7s
Build all the nodes / storage01 (push) Successful in 2m42s
chore(workflows/npins-update): Update running date
2025-05-12 15:24:24 +02:00

98 lines
2.9 KiB
Nix

# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
{ lib, nix-actions, ... }:
let
inherit (nix-actions.lib) secret;
inherit (lib) genAttrs mapAttrs' nameValuePair;
dependencies = builtins.attrNames (import ../npins);
in
{
name = "Update dependencies";
on.schedule = [
# Run every 24h
{ cron = "30 13 * * *"; }
];
# Global environment, necessary for rebases and commits
env = rec {
GIT_AUTHOR_NAME = "HT Chores";
GIT_AUTHOR_EMAIL = "chores@mail.hubrecht.ovh";
GIT_COMMITTER_NAME = GIT_AUTHOR_NAME;
GIT_COMMITTER_EMAIL = GIT_AUTHOR_EMAIL;
};
jobs = mapAttrs' (name: nameValuePair (builtins.replaceStrings [ "." ] [ "_" ] name)) (
genAttrs dependencies (name: {
runs-on = "nix-infra";
steps = [
(nix-actions.lib.steps.checkout {
fetch-depth = 0;
token = secret "TEA_DGNUM_CHORES_TOKEN";
})
{
env.GIT_UPDATE_BRANCH = "npins-updates/${name}";
name = "Switch to a new branch";
run = # bash
''
if git ls-remote --exit-code --heads origin "refs/heads/$GIT_UPDATE_BRANCH"; then
git switch "$GIT_UPDATE_BRANCH"
git rebase main
echo "EXISTING_BRANCH=1" >> $GITHUB_ENV
else
git switch -C "$GIT_UPDATE_BRANCH"
echo "EXISTING_BRANCH=" >> $GITHUB_ENV
fi
'';
}
{
env = {
GIT_UPDATE_BRANCH = "npins-updates/${name}";
COMMIT_MESSAGE = "chore(npins): Update ${name}";
};
name = "Open a PR if updates are present";
run = nix-actions.lib.nix-shell {
shell = "npins-shell";
script = ''
npins update ${name}
if ! git diff --exit-code npins/sources.json > /dev/null; then
echo "[+] Changes detected, pushing updates."
git add npins/sources.json
if [ -n "$EXISTING_BRANCH" ]; then
git commit --amend --no-edit
git push --force
else
git commit --message "$COMMIT_MESSAGE"
git push -u origin "$GIT_UPDATE_BRANCH"
fi
# Connect to the server with the cli
tea login add -n dgnum-chores -t ${secret "TEA_DGNUM_CHORES_TOKEN"} -u https://git.dgnum.eu
# Create a pull request if needed
# i.e. no PR with the same title exists
if [ -z $(tea pr ls -f='head' -o simple | grep "$GIT_UPDATE_BRANCH") ]; then
tea pr create --description "Automatic npins update" --title "$COMMIT_MESSAGE" --head "$GIT_UPDATE_BRANCH"
fi
elif [ -n "$EXISTING_BRANCH" ]; then
git push --force
fi
'';
};
}
];
})
);
}