2023-01-29 06:11:36 -07:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
. ./common.sh
|
|
|
|
|
2023-02-03 06:13:54 -07:00
|
|
|
direnv allow
|
2023-02-03 06:05:43 -07:00
|
|
|
|
2023-01-29 08:58:35 -07:00
|
|
|
CMD=${1:-""}
|
|
|
|
|
2023-03-03 07:48:42 -07:00
|
|
|
eval $(keychain --eval --agents ssh --inherit any)
|
|
|
|
|
2023-06-13 16:51:19 -06:00
|
|
|
grep -q /run/secrets/ci_ed25519_pub .git/config || git config user.signingkey /run/secrets/ci_ed25519_pub
|
2023-06-13 18:05:20 -06:00
|
|
|
grep -q gpgsign .git/config || git config commit.gpgsign true
|
2023-06-13 18:46:51 -06:00
|
|
|
grep -q allowedSignersFile .git/config || git config gpg.ssh.allowedSignersFile .allowed_signers
|
2023-06-13 15:36:47 -06:00
|
|
|
|
2023-01-31 14:26:29 -07:00
|
|
|
start_ci
|
2023-01-29 08:29:43 -07:00
|
|
|
|
2023-01-31 05:23:20 -07:00
|
|
|
trap ci_error INT TERM
|
2023-01-29 10:01:15 -07:00
|
|
|
|
2023-01-31 05:23:20 -07:00
|
|
|
ci_branch=$(date +"%Y%m%dT%H%M%S%z")
|
|
|
|
can_sign=0
|
2023-01-29 06:11:36 -07:00
|
|
|
|
2023-01-31 05:23:20 -07:00
|
|
|
for i in $(ssh-add -L | awk '{print $NF}'); do
|
|
|
|
grep -q $i .allowed_signers && can_sign=1
|
|
|
|
done
|
2023-01-29 06:11:36 -07:00
|
|
|
|
2023-01-31 05:23:20 -07:00
|
|
|
if [ $can_sign != 1 ]; then
|
|
|
|
echo "Can't find signing key."
|
|
|
|
exit 1
|
2023-01-29 08:52:54 -07:00
|
|
|
fi
|
2023-01-31 05:23:20 -07:00
|
|
|
|
2023-05-24 06:04:58 -06:00
|
|
|
git checkout main || handle_co_fail "main"
|
2023-01-31 16:28:08 -07:00
|
|
|
git pull || handle_pull_fail
|
2023-02-02 10:38:40 -07:00
|
|
|
|
|
|
|
if [ "${1}" = "update" ]; then
|
2023-02-27 07:14:00 -07:00
|
|
|
if ! git checkout -b "${ci_branch}"; then
|
2023-05-09 19:02:59 -06:00
|
|
|
handle_co_fail "${ci_branch}"
|
2023-02-27 07:14:00 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-05-23 14:56:12 -06:00
|
|
|
|
2023-05-23 20:48:53 -06:00
|
|
|
bin/deploy watch update
|
2023-05-23 14:56:12 -06:00
|
|
|
if ! git diff --exit-code >/dev/null; then
|
|
|
|
git add pull_requests
|
|
|
|
git commit -m 'watched: update watched pull requests'
|
|
|
|
fi
|
2023-05-09 19:02:59 -06:00
|
|
|
|
2023-05-09 18:31:04 -06:00
|
|
|
for inp in $(nix flake metadata --json | jq -r '.locks.nodes.root.inputs | keys[] as $k | $k'); do
|
2023-05-09 19:02:59 -06:00
|
|
|
if ! git checkout -b "${ci_branch}_${inp}"; then
|
|
|
|
handle_co_fail "${ci_branch}_${inp}"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2023-05-09 18:31:04 -06:00
|
|
|
if ! nix flake lock --commit-lock-file --update-input "$inp"; then
|
2023-05-09 19:02:59 -06:00
|
|
|
handle_update_fail "$inp"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! nix flake check --print-build-logs; then
|
|
|
|
handle_update_check_fail "$inp"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! git checkout "${ci_branch}"; then
|
|
|
|
handle_co_fail "${ci_branch}"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! git merge "${ci_branch}_${inp}"; then
|
|
|
|
handle_merge_fail "${ci_branch}_${inp}" "${ci_branch}"
|
|
|
|
continue
|
2023-05-09 18:31:04 -06:00
|
|
|
fi
|
|
|
|
done
|
2023-05-09 19:02:59 -06:00
|
|
|
|
2023-05-08 06:58:19 -06:00
|
|
|
if ! nix flake check --print-build-logs; then
|
2023-05-09 19:02:59 -06:00
|
|
|
handle_update_check_fail "$ci_branch"
|
2023-02-27 07:14:00 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-05-09 19:02:59 -06:00
|
|
|
|
|
|
|
|
2023-02-27 07:14:00 -07:00
|
|
|
if ! git checkout main; then
|
|
|
|
handle_co_fail
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if ! git merge "${ci_branch}"; then
|
2023-05-09 19:02:59 -06:00
|
|
|
handle_merge_fail "${ci_branch}" "main"
|
2023-02-27 07:14:00 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-02-18 06:45:53 -07:00
|
|
|
|
|
|
|
# Agent is configured to forget keys after X, if that happens we need to re-add before push
|
|
|
|
agentHasKey "$(cat /run/secrets/ci_ed25519_pub | awk '{print $2}')" ||
|
|
|
|
ssh-add /run/secrets/ci_ed25519_key
|
2023-02-27 07:14:00 -07:00
|
|
|
if ! git push; then
|
|
|
|
handle_push_fail
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-02-02 10:38:40 -07:00
|
|
|
else
|
2023-05-08 06:58:19 -06:00
|
|
|
if ! nix flake check --print-build-logs; then
|
2023-03-27 06:09:11 -06:00
|
|
|
handle_check_fail
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-02-02 10:38:40 -07:00
|
|
|
fi
|
|
|
|
|
2023-02-02 14:49:47 -07:00
|
|
|
finish
|