Skip to content

Commit 7a1d56c

Browse files
ci: Add unit tests required check (#5885)
Use dorny path filters to have one single job failing or succeeding when the unit tests passed or were skipped so we can enable unit tests as required checks for PRs. Fixes GH-5868
1 parent 3efaf5e commit 7a1d56c

File tree

2 files changed

+67
-16
lines changed

2 files changed

+67
-16
lines changed

.github/file-filters.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,27 @@ high_risk_code: &high_risk_code
1515
- "Sources/Sentry/SentryFileManager.m"
1616
- "Sources/Sentry/SentrySerialization.m"
1717
- "Sources/Sentry/SentrySerialization.h"
18+
19+
run_unit_tests_for_prs: &run_unit_tests_for_prs # Code
20+
- "Sources/**"
21+
- "Tests/**"
22+
- "SentryTestUtils/**"
23+
- "SentryTestUtilsDynamic/**"
24+
25+
# GH Actions
26+
- ".github/workflows/test.yml"
27+
- ".github/file-filters.yml"
28+
29+
# Scripts
30+
- "scripts/ci-select-xcode.sh"
31+
- "scripts/sentry-xcodebuild.sh"
32+
- "scripts/tests-with-thread-sanitizer.sh"
33+
34+
# Other
35+
- "test-server/**"
36+
- "Sentry.xcodeproj"
37+
- "**/*.xctestplan"
38+
- "fastlane/**"
39+
- ".codecov.yml"
40+
- "Brewfile*" # Dependency installation affects test environment
41+
- "Makefile" # Make commands used for CI build setup

.github/workflows/test.yml

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,6 @@ on:
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

3721
jobs:
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

Comments
 (0)