grapevine/bin/job
Charles Hall 2265b6615e
run ci for each commit
GitLab doesn't seem to have built-in support for this because of course
it doesn't.

To do this, we move the job scripts to a different file to make it
possible to share code between job scripts.
2024-12-11 11:39:20 -08:00

67 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
job_artifacts() (
set -euo pipefail
nix-build-and-cache packages
)
job_ci() (
set -euo pipefail
nix-build-and-cache ci
direnv exec . engage
)
job_pages() (
set -euo pipefail
nix build .#website-root
cp --recursive --dereference result public
chmod u+w -R public
)
bail() (
set -euo pipefail
git show --shortstat
echo
echo "Failure caused by the above commit"
exit 1
)
run() (
set -euo pipefail
if [[ -z "${1+x}" ]]; then
echo "You must supply a job to run. Available jobs:"
declare -F | rg \
--only-matching \
--color never \
--replace '* $1' \
'^declare -f job_(.*)$'
exit 1
fi
job="$1"
cd "$(git rev-parse --show-toplevel)"
if [[ -z "${CI_MERGE_REQUEST_DIFF_BASE_SHA+x}" ]]; then
echo "Running against latest commit only..."
job_"$job" || bail
else
echo "Running against all commits since this branch's base..."
readarray -t commits < \
<(git rev-list --reverse "$CI_MERGE_REQUEST_DIFF_BASE_SHA..HEAD")
for commit in "${commits[@]}"; do
git checkout "$commit"
job_"$job" || bail
done
fi
)
run "$@"