Tests #1014
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tests | |
# gh-84728: "paths-ignore" is not used to skip documentation-only PRs, because | |
# it prevents to mark a job as mandatory. A PR cannot be merged if a job is | |
# mandatory but not scheduled because of "paths-ignore". | |
on: | |
workflow_dispatch: | |
permissions: | |
contents: read | |
jobs: | |
check_source: | |
name: 'Check for source changes' | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
outputs: | |
run-docs: ${{ steps.docs-changes.outputs.run-docs || false }} | |
run_tests: ${{ steps.check.outputs.run_tests }} | |
run_hypothesis: ${{ steps.check.outputs.run_hypothesis }} | |
run_cifuzz: ${{ steps.check.outputs.run_cifuzz }} | |
config_hash: ${{ steps.config_hash.outputs.hash }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Check for source changes | |
id: check | |
run: | | |
if [ -z "$GITHUB_BASE_REF" ]; then | |
echo "run_tests=true" >> $GITHUB_OUTPUT | |
else | |
git fetch origin $GITHUB_BASE_REF --depth=1 | |
# git diff "origin/$GITHUB_BASE_REF..." (3 dots) may be more | |
# reliable than git diff "origin/$GITHUB_BASE_REF.." (2 dots), | |
# but it requires to download more commits (this job uses | |
# "git fetch --depth=1"). | |
# | |
# git diff "origin/$GITHUB_BASE_REF..." (3 dots) works with Git | |
# 2.26, but Git 2.28 is stricter and fails with "no merge base". | |
# | |
# git diff "origin/$GITHUB_BASE_REF.." (2 dots) should be enough on | |
# GitHub, since GitHub starts by merging origin/$GITHUB_BASE_REF | |
# into the PR branch anyway. | |
# | |
# https://github.com/python/core-workflow/issues/373 | |
git diff --name-only origin/$GITHUB_BASE_REF.. | grep -qvE '(\.rst$|^Doc|^Misc|^\.pre-commit-config\.yaml$|\.ruff\.toml$)' && echo "run_tests=true" >> $GITHUB_OUTPUT || true | |
fi | |
# Check if we should run hypothesis tests | |
GIT_BRANCH=${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}} | |
echo $GIT_BRANCH | |
if $(echo "$GIT_BRANCH" | grep -q -w '3\.\(8\|9\|10\|11\)'); then | |
echo "Branch too old for hypothesis tests" | |
echo "run_hypothesis=false" >> $GITHUB_OUTPUT | |
else | |
echo "Run hypothesis tests" | |
echo "run_hypothesis=true" >> $GITHUB_OUTPUT | |
fi | |
# oss-fuzz maintains a configuration for fuzzing the main branch of | |
# CPython, so CIFuzz should be run only for code that is likely to be | |
# merged into the main branch; compatibility with older branches may | |
# be broken. | |
FUZZ_RELEVANT_FILES='(\.c$|\.h$|\.cpp$|^configure$|^\.github/workflows/build\.yml$|^Modules/_xxtestfuzz)' | |
if [ "$GITHUB_BASE_REF" = "main" ] && [ "$(git diff --name-only origin/$GITHUB_BASE_REF.. | grep -qE $FUZZ_RELEVANT_FILES; echo $?)" -eq 0 ]; then | |
# The tests are pretty slow so they are executed only for PRs | |
# changing relevant files. | |
echo "Run CIFuzz tests" | |
echo "run_cifuzz=true" >> $GITHUB_OUTPUT | |
else | |
echo "Branch too old for CIFuzz tests; or no C files were changed" | |
echo "run_cifuzz=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Compute hash for config cache key | |
id: config_hash | |
run: | | |
echo "hash=${{ hashFiles('configure', 'configure.ac', '.github/workflows/build.yml') }}" >> $GITHUB_OUTPUT | |
- name: Get a list of the changed documentation-related files | |
if: github.event_name == 'pull_request' | |
id: changed-docs-files | |
uses: Ana06/[email protected] | |
with: | |
filter: | | |
Doc/** | |
Misc/** | |
.github/workflows/reusable-docs.yml | |
format: csv # works for paths with spaces | |
- name: Check for docs changes | |
if: >- | |
github.event_name == 'pull_request' | |
&& steps.changed-docs-files.outputs.added_modified_renamed != '' | |
id: docs-changes | |
run: | | |
echo "run-docs=true" >> "${GITHUB_OUTPUT}" | |
build_tsan: | |
name: 'Thread sanitizer' | |
needs: check_source | |
if: needs.check_source.outputs.run_tests == 'true' | |
uses: ./.github/workflows/reusable-tsan.yml | |
with: | |
config_hash: ${{ needs.check_source.outputs.config_hash }} | |
options: ./configure --config-cache --with-thread-sanitizer --with-pydebug | |
suppressions_path: Tools/tsan/supressions.txt | |
tsan_logs_artifact_name: tsan-logs-default | |
build_tsan_free_threading: | |
name: 'Thread sanitizer (free-threading)' | |
needs: check_source | |
if: needs.check_source.outputs.run_tests == 'true' | |
uses: ./.github/workflows/reusable-tsan.yml | |
with: | |
config_hash: ${{ needs.check_source.outputs.config_hash }} | |
options: ./configure --config-cache --disable-gil --with-thread-sanitizer --with-pydebug | |
suppressions_path: Tools/tsan/suppressions_free_threading.txt | |
tsan_logs_artifact_name: tsan-logs-free-threading |