2626 type : number
2727 default : -1
2828 pull_request :
29- paths :
30- - ' src/**'
31- - ' tests/**'
32- - ' composer.json'
33- - ' composer.lock'
34- - ' .github/actions/**'
35- - ' .github/workflows/tests.yml'
29+ types : [opened, synchronize, reopened]
3630 push :
3731 branches : [ "main" ]
3832
@@ -41,7 +35,7 @@ permissions:
4135
4236concurrency :
4337 group : ${{ github.event_name == 'pull_request' && format('tests-pr-{0}', github.event.pull_request.number) || format('tests-{0}', github.ref) }}
44- cancel-in-progress : ${{ github.event_name == 'pull_request' }}
38+ cancel-in-progress : false
4539
4640env :
4741 FORCE_COLOR : ' 1'
5448 php-version : ${{ steps.resolve.outputs.php-version }}
5549 php-version-source : ${{ steps.resolve.outputs.php-version-source }}
5650 test-matrix : ${{ steps.resolve.outputs.test-matrix }}
51+ run-tests : ${{ steps.scope.outputs.run-tests }}
52+ test-scope-reason : ${{ steps.scope.outputs.reason }}
5753
5854 steps :
5955 - uses : actions/checkout@v6
56+ with :
57+ fetch-depth : 0
6058 - name : Checkout dev-tools workflow action source
6159 uses : actions/checkout@v6
6260 with :
7068 id : resolve
7169 uses : ./.dev-tools-actions/.github/actions/php/resolve-version
7270
71+ - name : Resolve test workflow scope
72+ id : scope
73+ shell : bash
74+ env :
75+ BASE_SHA : ${{ github.event.pull_request.base.sha || '' }}
76+ run : |
77+ set -euo pipefail
78+
79+ if [ "${GITHUB_EVENT_NAME}" != "pull_request" ]; then
80+ {
81+ echo "run-tests=true"
82+ echo "reason=non-pull-request-event"
83+ } >> "$GITHUB_OUTPUT"
84+
85+ exit 0
86+ fi
87+
88+ git fetch --no-tags --depth=1 origin "${BASE_SHA}"
89+ git diff --name-only "${BASE_SHA}...HEAD" > changed-files.txt
90+
91+ run_tests=false
92+ while IFS= read -r changed_file; do
93+ case "${changed_file}" in
94+ src/*|tests/*|composer.json|composer.lock|.github/actions/*|.github/workflows/tests.yml|resources/github-actions/tests.yml)
95+ run_tests=true
96+ break
97+ ;;
98+ esac
99+ done < changed-files.txt
100+
101+ if [ "${run_tests}" = "true" ]; then
102+ reason="test-sensitive-pr-diff"
103+ else
104+ reason="no-test-sensitive-pr-diff"
105+ fi
106+
107+ {
108+ echo "run-tests=${run_tests}"
109+ echo "reason=${reason}"
110+ } >> "$GITHUB_OUTPUT"
111+
73112 tests :
74113 needs : resolve_php
75114 name : Run Tests
80119 TESTS_ROOT_VERSION : ${{ github.event_name == 'pull_request' && format('dev-{0}', github.event.pull_request.head.ref) || 'dev-main' }}
81120 steps :
82121 - uses : actions/checkout@v6
122+ if : needs.resolve_php.outputs.run-tests == 'true'
83123 - name : Checkout dev-tools workflow action source
124+ if : needs.resolve_php.outputs.run-tests == 'true'
84125 uses : actions/checkout@v6
85126 with :
86127 repository : php-fast-forward/dev-tools
90131 .github/actions
91132
92133 - name : Setup PHP and install dependencies
134+ if : needs.resolve_php.outputs.run-tests == 'true'
93135 uses : ./.dev-tools-actions/.github/actions/php/setup-composer
94136 with :
95137 php-version : ${{ matrix.php-version }}
@@ -99,21 +141,29 @@ jobs:
99141 install-options : --prefer-dist --no-progress --no-interaction --no-plugins --no-scripts
100142
101143 - name : Composer Audit
144+ if : needs.resolve_php.outputs.run-tests == 'true'
102145 env :
103146 COMPOSER_ROOT_VERSION : ${{ env.TESTS_ROOT_VERSION }}
104147 run : composer audit
105148
106149 - name : Resolve minimum coverage
150+ if : needs.resolve_php.outputs.run-tests == 'true'
107151 id : minimum-coverage
108152 run : echo "value=${INPUT_MIN_COVERAGE:-80}" >> "$GITHUB_OUTPUT"
109153 env :
110154 INPUT_MIN_COVERAGE : ${{ inputs.min-coverage }}
111155
112156 - name : Run PHPUnit tests
157+ if : needs.resolve_php.outputs.run-tests == 'true'
113158 env :
114159 COMPOSER_ROOT_VERSION : ${{ env.TESTS_ROOT_VERSION }}
115160 run : composer dev-tools tests -- --coverage=.dev-tools/coverage --min-coverage=${{ steps.minimum-coverage.outputs.value }}
116161
162+ - name : Mark tests intentionally skipped
163+ if : needs.resolve_php.outputs.run-tests != 'true'
164+ run : |
165+ echo "No test-sensitive PR diff detected; required test context completed without running PHPUnit."
166+
117167 dependency-health :
118168 needs : resolve_php
119169 name : Dependency Health
@@ -122,7 +172,9 @@ jobs:
122172 TESTS_ROOT_VERSION : ${{ github.event_name == 'pull_request' && format('dev-{0}', github.event.pull_request.head.ref) || 'dev-main' }}
123173 steps :
124174 - uses : actions/checkout@v6
175+ if : needs.resolve_php.outputs.run-tests == 'true'
125176 - name : Checkout dev-tools workflow action source
177+ if : needs.resolve_php.outputs.run-tests == 'true'
126178 uses : actions/checkout@v6
127179 with :
128180 repository : php-fast-forward/dev-tools
@@ -132,17 +184,24 @@ jobs:
132184 .github/actions
133185
134186 - name : Setup PHP and install dependencies
187+ if : needs.resolve_php.outputs.run-tests == 'true'
135188 uses : ./.dev-tools-actions/.github/actions/php/setup-composer
136189 with :
137190 php-version : ${{ needs.resolve_php.outputs.php-version }}
138191 root-version : ${{ env.TESTS_ROOT_VERSION }}
139192 install-options : --prefer-dist --no-progress --no-interaction --no-plugins --no-scripts
140193
141194 - name : Run dependency health check
195+ if : needs.resolve_php.outputs.run-tests == 'true'
142196 env :
143197 COMPOSER_ROOT_VERSION : ${{ env.TESTS_ROOT_VERSION }}
144198 run : composer dev-tools dependencies -- --max-outdated=${{ inputs.max-outdated || -1 }}
145199
200+ - name : Mark dependency health intentionally skipped
201+ if : needs.resolve_php.outputs.run-tests != 'true'
202+ run : |
203+ echo "No test-sensitive PR diff detected; dependency health completed without running dependency analysis."
204+
146205 summarize :
147206 if : ${{ always() }}
148207 name : Summarize Test Workflow
@@ -170,6 +229,8 @@ jobs:
170229 - Workflow PHP version: `${{ needs.resolve_php.outputs.php-version }}`
171230 - PHP version source: `${{ needs.resolve_php.outputs.php-version-source }}`
172231 - Test matrix: `${{ needs.resolve_php.outputs.test-matrix }}`
232+ - Test-sensitive diff: `${{ needs.resolve_php.outputs.run-tests }}`
233+ - Test scope reason: `${{ needs.resolve_php.outputs.test-scope-reason }}`
173234 - Minimum coverage threshold: `${{ inputs.min-coverage || 80 }}`
174235 - Dependency health `max-outdated`: `${{ inputs.max-outdated || -1 }}`
175236 - Tests job result: `${{ needs.tests.result }}`
0 commit comments