Files
goodwe-addon/.gitea/ci/run-affected.sh
T
glenn schrooyenandClaude Opus 5.5 22ef89bf10
checks / unit (pull_request) Successful in 20m22s
infra-pin / fresh (pull_request) Successful in 1s
CI-18 review: --head needs B checked out; guard the CI image against CI_ONLY
The selector reads the graph, and run-affected.sh runs the tests, from the
working tree, so a --base/--head range is only right with the head checked
out. The CI image is built from the merged tree, so an ENV CI_ONLY in its
Dockerfile would make the gate partial; test_affected_tests.py now fails on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 23:29:34 +01:00

36 lines
1.8 KiB
Bash

#!/bin/sh
# CI-18: run the test files a diff affects, in the CI image, for a dev or review
# round. NOT the merge gate: `checks / unit (pull_request)` runs all of them.
#
# sh .gitea/ci/run-affected.sh # merge-base(origin/release/1.0) .. working tree
# sh .gitea/ci/run-affected.sh --base A --head B # with B checked out: the tests run from the working tree
# INFRA_DIR=/path/to/admin-goodwe@pin sh .gitea/ci/run-affected.sh
#
# Arguments go to affected_tests.py (which prints what it chose and why). It
# selects ALL when it cannot map a change, so a run of this script is never a
# silent skip. Needs python3, git and docker on the host. INFRA_DIR is the
# admin/goodwe checkout at the commit in .gitea/infra-pin (test_freeze.py part 3
# needs sim/hwsim.py); without it test_freeze.py fails, as it does in CI without
# the checkout, and the script says so.
set -eu
repo=$(git rev-parse --show-toplevel)
cd "$repo"
python3 .gitea/ci/affected_tests.py "$@"
only=$(python3 .gitea/ci/affected_tests.py --names "$@" | tr '\n' ' ')
if [ -z "${only# }" ]; then echo "nothing selected"; exit 0; fi
IMG=${CI_IMAGE:-goodwe-addon-checks:1}
docker image inspect "$IMG" >/dev/null 2>&1 || docker build -q -t "$IMG" .gitea/ci >/dev/null
infra=
if [ -n "${INFRA_DIR:-}" ]; then
infra="-v $INFRA_DIR:/w/goodwe:ro"
else
echo "INFRA_DIR is not set: test_freeze.py will fail if it is selected (it needs admin/goodwe at the pin)."
fi
# --network none: the tests need none. --memory: a runaway test must not take the host.
# shellcheck disable=SC2086
exec docker run --rm ${CONTAINER_NAME:+--name "$CONTAINER_NAME"} --network none \
--memory "${CI_MEMORY:-16g}" -e PYTHONDONTWRITEBYTECODE=1 -e GOODWE_REQUIRE_HWSIM=1 \
-e CI_JOBS="${CI_JOBS:-6}" -e CI_ONLY="$only" \
-v "$repo:/w/goodwe-addon:ro" $infra "$IMG" \
sh -eu /w/goodwe-addon/.gitea/ci/run-tests.sh