66 - release/**
77
88 pull_request :
9- paths :
10- - " Sources/**"
11- - " Tests/**"
12- - " SentryTestUtils/**"
13- - " SentryTestUtilsDynamic/**" # Dynamic test utilities used by tests
14- - " test-server/**"
15- - " .github/workflows/test.yml"
16- - " fastlane/**"
17- - " scripts/tests-with-thread-sanitizer.sh"
18- - " scripts/ci-select-xcode.sh"
19- - " scripts/sentry-xcodebuild.sh"
20- - " .codecov.yml"
21- - " Sentry.xcodeproj"
22- - " **/*.xctestplan"
23- - " Makefile" # Make commands used for CI build setup
24- - " Brewfile*" # Dependency installation affects test environment
259
2610# Concurrency configuration:
2711# - We use workflow-specific concurrency groups to allow independent test runs across different workflows
@@ -35,8 +19,29 @@ concurrency:
3519 cancel-in-progress : ${{ github.event_name == 'pull_request' }}
3620
3721jobs :
22+ # This job detects if the PR contains changes that require running unit tests.
23+ # If yes, the job will output a flag that will be used by the next job to run the unit tests.
24+ # If no, the job will output a flag that will be used by the next job to skip running the unit tests.
25+ # At the end of this workflow, we run a check that validates that either all unit tests passed or were
26+ # called unit-tests-required-check.
27+ files-changed :
28+ name : Detect File Changes
29+ runs-on : ubuntu-latest
30+ # Map a step output to a job output
31+ outputs :
32+ run_unit_tests_for_prs : ${{ steps.changes.outputs.run_unit_tests_for_prs }}
33+ steps :
34+ - uses : actions/checkout@v4
35+ - name : Get changed files
36+ id : changes
37+ uses : dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
38+ with :
39+ token : ${{ github.token }}
40+ filters : .github/file-filters.yml
3841 build-test-server :
3942 name : Build test server
43+ if : needs.files-changed.outputs.run_unit_tests_for_prs == 'true'
44+ needs : files-changed
4045 runs-on : macos-15
4146 steps :
4247 - uses : actions/checkout@v4
@@ -306,3 +311,25 @@ jobs:
306311 verbose : true
307312 name : sentry-cocoa-unit-tests
308313 flags : unittests-${{ matrix.platform }}-${{ matrix.xcode }}-${{ matrix.test-destination-os }}, unittests
314+
315+ # This check validates that either all unit tests passed or were skipped, which allows us
316+ # to make unit tests a required check with only running the unit tests when required.
317+ # So, we don't have to run unit tests, for example, for Changelog or ReadMe changes.
318+
319+ unit-tests-required-check :
320+ needs :
321+ [
322+ build-test-server,
323+ unit-tests,
324+ ]
325+ name : Unit Tests
326+ # This is necessary since a failed/skipped dependent job would cause this job to be skipped
327+ if : always()
328+ runs-on : ubuntu-latest
329+ steps :
330+ # If any jobs we depend on fails gets cancelled or times out, this job will fail.
331+ # Skipped jobs are not considered failures.
332+ - name : Check for failures
333+ if : contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
334+ run : |
335+ echo "One of the unit test jobs has failed." && exit 1
0 commit comments