xin/bin/ci

66 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env sh
. ./common.sh
direnv allow
CMD=${1:-""}
eval $(keychain --eval --agents ssh --inherit any)
start_ci
trap ci_error INT TERM
ci_branch=$(date +"%Y%m%dT%H%M%S%z")
can_sign=0
for i in $(ssh-add -L | awk '{print $NF}'); do
grep -q $i .allowed_signers && can_sign=1
done
if [ $can_sign != 1 ]; then
echo "Can't find signing key."
exit 1
fi
git pull || handle_pull_fail
if [ "${1}" = "update" ]; then
if ! git checkout -b "${ci_branch}"; then
handle_co_fail
exit 1
fi
if ! nix flake update --commit-lock-file; then
handle_update_fail
exit 1
fi
if ! nix flake check --print-build-logs; then
handle_update_check_fail
exit 1
fi
if ! git checkout main; then
handle_co_fail
exit 1
fi
if ! git merge "${ci_branch}"; then
handle_merge_fail
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
if ! git push; then
handle_push_fail
exit 1
fi
else
if ! nix flake check --print-build-logs; then
handle_check_fail
exit 1
fi
fi
finish