Skip to main content

ci/post_receive_tests.sh

1#!/usr/bin/env bash
2# Run the post-receive tests for a repository, which means:
3#
4# 1. Cloning the repo to a scratch directory
5# 2. Setting up a virtualenv/dependencies
6# 3. Running the test suite through `ts`
7#
8# TODO: Support running tests on the non-main branch.
10set -o errexit
11set -o nounset
13if (( $# != 1 )); then
14 echo "Usage: $0 REPO_NAME" >&2
15 exit 1
16fi
18# Print a command in blue, then run the command
19run_command() {
20 echo -e "\033[34m-> $@\033[0m"
21 bash -c "$@"
24unset GIT_DIR
26# REPO_NAME is the name of the repository to run tests for
27REPO_NAME="$1"
29# REMOTES_ROOT is the directory where I keep all my remote repos
30REMOTES_ROOT="/Volumes/Media (Speedwell)/repos"
32# SCRATCH_ROOT is the directory where I have checked-out versions for
33# running post-receive tests
34SCRATCH_ROOT="$REMOTES_ROOT/.working"
36export REPO_DIR="$REMOTES_ROOT/$REPO_NAME"
37export SCRATCH_DIR="$SCRATCH_ROOT/$REPO_NAME"
39export CI=true
41# Clone the Git repo to the directory if it doesn't exist yet, or update
42# it if it doesn't.
43if [ ! -d "$SCRATCH_DIR/.git" ]; then
44 run_command 'git clone "$REPO_DIR" "$SCRATCH_DIR"'
46 run_command 'cd "$SCRATCH_DIR"'
47 echo "$SCRATCH_DIR"
48 cd "$SCRATCH_DIR"
49else
50 run_command 'cd "$SCRATCH_DIR"'
51 echo "$SCRATCH_DIR"
52 cd "$SCRATCH_DIR"
54 run_command 'git pull origin main --rebase'
55fi
57# If there's a requirements.txt file in the repo, then this is a Python repo.
58# Set up a virtualenv.
59if [ -f "$SCRATCH_DIR/requirements.txt" ] || [ -f "$SCRATCH_DIR/dev_requirements.txt" ]; then
60 run_command 'uv venv --quiet --allow-existing .venv --python 3.14'
61 echo "$SCRATCH_DIR/.venv" >> ~/.venv_registry
62 run_command 'source .venv/bin/activate'
63 source .venv/bin/activate
64 run_pip_sync
65fi
67echo ""
69~/repos/scripts/ci/ts