1
1
name : Tests
2
2
3
- # gh-84728: "paths-ignore" is not used to skip documentation-only PRs, because
4
- # it prevents to mark a job as mandatory. A PR cannot be merged if a job is
5
- # mandatory but not scheduled because of "paths-ignore".
6
3
on :
7
4
workflow_dispatch :
8
5
push :
@@ -23,121 +20,19 @@ concurrency:
23
20
24
21
jobs :
25
22
check_source :
26
- name : ' Check for source changes'
27
- runs-on : ubuntu-latest
28
- timeout-minutes : 10
29
- outputs :
30
- # Some of the referenced steps set outputs conditionally and there may be
31
- # cases when referencing them evaluates to empty strings. It is nice to
32
- # work with proper booleans so they have to be evaluated through JSON
33
- # conversion in the expressions. However, empty strings used like that
34
- # may trigger all sorts of undefined and hard-to-debug behaviors in
35
- # GitHub Actions CI/CD. To help with this, all of the outputs set here
36
- # that are meant to be used as boolean flags (and not arbitrary strings),
37
- # MUST have fallbacks with default values set. A common pattern would be
38
- # to add ` || false` to all such expressions here, in the output
39
- # definitions. They can then later be safely used through the following
40
- # idiom in job conditionals and other expressions. Here's some examples:
41
- #
42
- # if: fromJSON(needs.check_source.outputs.run-docs)
43
- #
44
- # ${{
45
- # fromJSON(needs.check_source.outputs.run_tests)
46
- # && 'truthy-branch'
47
- # || 'falsy-branch'
48
- # }}
49
- #
50
- run-docs : ${{ steps.docs-changes.outputs.run-docs || false }}
51
- run-win-msi : ${{ steps.win-msi-changes.outputs.run-win-msi || false }}
52
- run_tests : ${{ steps.check.outputs.run_tests || false }}
53
- run_hypothesis : ${{ steps.check.outputs.run_hypothesis || false }}
54
- run_cifuzz : ${{ steps.check.outputs.run_cifuzz || false }}
55
- config_hash : ${{ steps.config_hash.outputs.hash }} # str
56
- steps :
57
- - uses : actions/checkout@v4
58
- - name : Check for source changes
59
- id : check
60
- run : |
61
- if [ -z "$GITHUB_BASE_REF" ]; then
62
- echo "run_tests=true" >> $GITHUB_OUTPUT
63
- else
64
- git fetch origin $GITHUB_BASE_REF --depth=1
65
- # git diff "origin/$GITHUB_BASE_REF..." (3 dots) may be more
66
- # reliable than git diff "origin/$GITHUB_BASE_REF.." (2 dots),
67
- # but it requires to download more commits (this job uses
68
- # "git fetch --depth=1").
69
- #
70
- # git diff "origin/$GITHUB_BASE_REF..." (3 dots) works with Git
71
- # 2.26, but Git 2.28 is stricter and fails with "no merge base".
72
- #
73
- # git diff "origin/$GITHUB_BASE_REF.." (2 dots) should be enough on
74
- # GitHub, since GitHub starts by merging origin/$GITHUB_BASE_REF
75
- # into the PR branch anyway.
76
- #
77
- # https://github.com/python/core-workflow/issues/373
78
- git diff --name-only origin/$GITHUB_BASE_REF.. | grep -qvE '(\.rst$|^Doc|^Misc|^\.pre-commit-config\.yaml$|\.ruff\.toml$|\.md$|mypy\.ini$)' && echo "run_tests=true" >> $GITHUB_OUTPUT || true
79
- fi
80
-
81
- # Check if we should run hypothesis tests
82
- GIT_BRANCH=${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}}
83
- echo $GIT_BRANCH
84
- if $(echo "$GIT_BRANCH" | grep -q -w '3\.\(8\|9\|10\|11\)'); then
85
- echo "Branch too old for hypothesis tests"
86
- echo "run_hypothesis=false" >> $GITHUB_OUTPUT
87
- else
88
- echo "Run hypothesis tests"
89
- echo "run_hypothesis=true" >> $GITHUB_OUTPUT
90
- fi
91
-
92
- # oss-fuzz maintains a configuration for fuzzing the main branch of
93
- # CPython, so CIFuzz should be run only for code that is likely to be
94
- # merged into the main branch; compatibility with older branches may
95
- # be broken.
96
- FUZZ_RELEVANT_FILES='(\.c$|\.h$|\.cpp$|^configure$|^\.github/workflows/build\.yml$|^Modules/_xxtestfuzz)'
97
- if [ "$GITHUB_BASE_REF" = "main" ] && [ "$(git diff --name-only origin/$GITHUB_BASE_REF.. | grep -qE $FUZZ_RELEVANT_FILES; echo $?)" -eq 0 ]; then
98
- # The tests are pretty slow so they are executed only for PRs
99
- # changing relevant files.
100
- echo "Run CIFuzz tests"
101
- echo "run_cifuzz=true" >> $GITHUB_OUTPUT
102
- else
103
- echo "Branch too old for CIFuzz tests; or no C files were changed"
104
- echo "run_cifuzz=false" >> $GITHUB_OUTPUT
105
- fi
106
- - name : Compute hash for config cache key
107
- id : config_hash
108
- run : |
109
- echo "hash=${{ hashFiles('configure', 'configure.ac', '.github/workflows/build.yml') }}" >> $GITHUB_OUTPUT
110
- - name : Get a list of the changed documentation-related files
111
- if : github.event_name == 'pull_request'
112
- id : changed-docs-files
113
-
114
- with :
115
- filter : |
116
- Doc/**
117
- Misc/**
118
- .github/workflows/reusable-docs.yml
119
- format : csv # works for paths with spaces
120
- - name : Check for docs changes
121
- if : >-
122
- github.event_name == 'pull_request'
123
- && steps.changed-docs-files.outputs.added_modified_renamed != ''
124
- id : docs-changes
125
- run : |
126
- echo "run-docs=true" >> "${GITHUB_OUTPUT}"
127
- - name : Get a list of the MSI installer-related files
128
- id : changed-win-msi-files
129
-
130
- with :
131
- filter : |
132
- Tools/msi/**
133
- .github/workflows/reusable-windows-msi.yml
134
- format : csv # works for paths with spaces
135
- - name : Check for changes in MSI installer-related files
136
- if : >-
137
- steps.changed-win-msi-files.outputs.added_modified_renamed != ''
138
- id : win-msi-changes
139
- run : |
140
- echo "run-win-msi=true" >> "${GITHUB_OUTPUT}"
23
+ name : Change detection
24
+ # To use boolean outputs from this job, parse them as JSON.
25
+ # Here's some examples:
26
+ #
27
+ # if: fromJSON(needs.check_source.outputs.run-docs)
28
+ #
29
+ # ${{
30
+ # fromJSON(needs.check_source.outputs.run_tests)
31
+ # && 'truthy-branch'
32
+ # || 'falsy-branch'
33
+ # }}
34
+ #
35
+ uses : ./.github/workflows/reusable-change-detection.yml
141
36
142
37
check-docs :
143
38
name : Docs
0 commit comments