Skip to main content

ci/ts

1#!/usr/bin/env bash
3set -o errexit
4set -o nounset
6function run_python_tests() {
7 GIT_ROOT=$(git rev-parse --show-toplevel)
8
9 pushd "$GIT_ROOT" >/dev/null
10 # If there's a `scripts` folder with a test script, run that
11 if find "scripts" -name 'run_*_tests.sh' >/dev/null; then
12 print_info "-> bash scripts/run_*_tests.sh"
13 bash scripts/run_*_tests.sh
14 return 0
15 fi
16 popd >/dev/null
18 REPO_NAME="$(basename $(pwd))"
20 # Run ruff to do Python formatting
21 print_info "-> ruff format"
22 ruff format .
24 echo ""
26 print_info "-> ruff check --fix"
27 ruff check --fix .
29 echo ""
31 # This is one repo which is a bit special -- I'm gradually trying to chase
32 # the code into `src`, but for now I have to remember to look at *.py
33 if [[ "$REPO_NAME" = "library-lookup" ]]
34 then
35 print_info '-> mypy *.py src tests'
36 mypy *.py src tests
37 else
38 print_info '-> mypy src tests'
40 if mypy src tests >/dev/null
41 then
42 mypy src tests --no-color-output
43 else
44 mypy src tests
45 fi
46 fi
48 echo ""
50 # Run the tests.
51 print_info "-> coverage run -m pytest tests"
52 coverage run -m pytest tests --quiet
54 echo ""
56 print_info "-> coverage report"
58 if [[ $(coverage report --format=total) = "100" ]]
59 then
60 echo "100% coverage!"
61 else
62 coverage report
63 fi
66function run_rust_tests() {
67 print_info "-> cargo fmt"
68 cargo fmt
70 echo ""
72 print_info "-> cargo build"
73 cargo build
75 echo ""
77 print_info -n "-> cargo test"
78 cargo test --quiet
81if test -f Cargo.toml
82then
83 run_rust_tests
84else
85 run_python_tests "$@"
86fi