infrastructure/workflows/npins-update.nix

65 lines
1.7 KiB
Nix
Raw Normal View History

# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
{ nix-actions, ... }:
{
name = "npins update";
on.schedule = [
# Run at 15:25 everyday
{ cron = "25 15 * * *"; }
];
jobs.npins_update = {
runs-on = "nix";
steps = [
(nix-actions.steps.checkout {
fetch-depth = 0;
token = nix-actions.lib.secret "TEA_DGNUM_CHORES_TOKEN";
})
{
name = "Update dependencies and open PR if necessary";
run = # bash
''
npins update
if [ ! -z "$(git diff --name-only)" ]; then
echo "[+] Changes detected, pushing updates."
git switch -C npins-update
2023-12-12 14:46:36 +01:00
git add npins
2023-12-12 14:46:36 +01:00
git commit --message "chore(npins): Update"
git push --set-upstream origin npins-update --force
2023-12-12 14:46:36 +01:00
# Connect to the server with the cli
tea login add \
-n dgnum-chores \
-t "${nix-actions.lib.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='title,author' -o simple | grep 'chore(npins): Update dgnum-chores')" ]; then
tea pr create \
--description "Automatic npins update" \
--title "chore(npins): Update" \
--head npins-update
fi
2023-12-12 14:46:36 +01:00
fi
'';
env = {
GIT_AUTHOR_NAME = "DGNum Chores";
GIT_AUTHOR_EMAIL = "tech@dgnum.eu";
GIT_COMMITTER_NAME = "DGNum Chores";
GIT_COMMITTER_EMAIL = "tech@dgnum.eu";
};
}
];
};
}