xin/bin/ci

116 lines
2.3 KiB
Plaintext
Raw Permalink Normal View History

2023-01-29 06:11:36 -07:00
#!/usr/bin/env sh
. ./common.sh
if [ -f ./lock ]; then
msg "${SCRIPT_NAME} locked..."
exit 0
fi
2023-02-03 06:13:54 -07:00
direnv allow
2023-01-29 08:58:35 -07:00
CMD=${1:-""}
eval $(keychain --eval --agents ssh --inherit any)
2023-06-14 12:10:02 -06:00
git config user.signingkey /run/secrets/ci_signing_ed25519_key
2023-06-14 08:07:04 -06:00
git config commit.gpgsign true
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
git checkout main || handle_co_fail "main"
2023-01-31 16:28:08 -07:00
git pull || handle_pull_fail
if [ "${1}" = "update" ]; then
2023-02-27 07:14:00 -07:00
if ! git checkout -b "${ci_branch}"; then
handle_co_fail "${ci_branch}"
2023-02-27 07:14:00 -07:00
exit 1
fi
2023-05-23 20:48:53 -06:00
bin/deploy watch update
if ! git diff --exit-code >/dev/null; then
git add pull_requests
git commit -m 'watched: update watched pull requests'
fi
for inp in $(nix flake metadata --json | jq -r '.locks.nodes.root.inputs | keys[] as $k | $k'); do
if ! git checkout -b "${ci_branch}_${inp}"; then
handle_co_fail "${ci_branch}_${inp}"
continue
fi
current_hash="$(git rev-parse HEAD)"
if ! nix flake lock --commit-lock-file --update-input "$inp"; then
handle_update_fail "$inp"
continue
fi
maybe_new_hash="$(git rev-parse HEAD)"
if [ "${current_hash}" != "${maybe_new_hash}" ]; then
if ! nix flake check --print-build-logs; then
handle_update_check_fail "$inp"
continue
fi
else
msg "No change in input, skipping checks."
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
fi
done
if ! nix flake check --print-build-logs; then
handle_update_check_fail "$ci_branch"
2023-02-27 07:14:00 -07:00
exit 1
fi
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
handle_merge_fail "${ci_branch}" "main"
2023-02-27 07:14:00 -07:00
exit 1
fi
# 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
else
if ! nix flake check --print-build-logs; then
2023-03-27 06:09:11 -06:00
handle_check_fail
exit 1
fi
fi
2023-06-16 09:28:51 -06:00
finish_ci