diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index b0a353f..0087961 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -81,10 +81,15 @@ jobs: if: github.ref == 'refs/heads/main' || github.event_name == 'schedule' run: echo "NOSTR_E2E=1" >> $GITHUB_ENV - name: Run tests with coverage + timeout-minutes: 16 shell: bash - run: | - pytest ${STRESS_ARGS} --cov=src --cov-report=xml --cov-report=term-missing \ - --cov-fail-under=20 src/tests + run: scripts/run_ci_tests.sh + - name: Upload pytest log + if: always() + uses: actions/upload-artifact@v4 + with: + name: pytest-log-${{ matrix.os }} + path: pytest.log - name: Upload coverage report uses: actions/upload-artifact@v4 with: diff --git a/scripts/run_ci_tests.sh b/scripts/run_ci_tests.sh new file mode 100755 index 0000000..661aa47 --- /dev/null +++ b/scripts/run_ci_tests.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -eo pipefail + +pytest_args=(-vv) +if [[ -n "${STRESS_ARGS:-}" ]]; then + pytest_args+=(${STRESS_ARGS}) +fi +if [[ "${RUNNER_OS:-}" == "Windows" ]]; then + pytest_args+=(-n 1) +fi +pytest_args+=(--cov=src --cov-report=xml --cov-report=term-missing --cov-fail-under=20 src/tests) + +timeout_bin="timeout" +if ! command -v "$timeout_bin" >/dev/null 2>&1; then + if command -v gtimeout >/dev/null 2>&1; then + timeout_bin="gtimeout" + else + timeout_bin="" + fi +fi + +if [[ -n "$timeout_bin" ]]; then + $timeout_bin 15m pytest "${pytest_args[@]}" 2>&1 | tee pytest.log + status=${PIPESTATUS[0]} +else + echo "timeout command not found; running tests without timeout" >&2 + pytest "${pytest_args[@]}" 2>&1 | tee pytest.log + status=${PIPESTATUS[0]} +fi + +if [[ $status -eq 124 ]]; then + echo "::error::Tests exceeded 15-minute limit" + tail -n 20 pytest.log + exit 1 +fi +exit $status