-
-
Notifications
You must be signed in to change notification settings - Fork 5
217 lines (210 loc) · 7.91 KB
/
run-unit-tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
name: Run pure unit tests
on:
workflow_call:
inputs:
package_root:
type: string
required: false
default: ''
description: "Specifies a subpath of the checkout to run tests and upload coverage from."
test_filter:
type: string
required: false
default: ''
description: "Apply a --filter to the tests that will be run."
with_coverage:
type: boolean
required: false
default: true
description: "Set to 'true' to collect and upload code coverage data. Defaults to 'false'."
coverage_ignores:
type: string
required: false
default: '/Tests/'
description: "Additional source-relative paths to ignore when generating code coverage reports."
with_tsan:
type: boolean
required: false
default: true
description: "Set to 'true' to run tests with Thread Sanitizer. Defaults to 'true'."
with_public_api_check:
type: boolean
required: false
default: true
description: "Set to 'true' to run the SwiftPM public API breakage check. Defaults to 'true'."
with_gh_codeql:
type: boolean
required: false
default: true
description: "Set to 'true' to run CodeQL checks. Defaults to 'true'."
with_deps_submission:
type: boolean
required: false
default: true
description: "Set to 'true' to submit a dependency graph to Github. Defaults to 'true'."
extra_flags:
type: string
required: false
default: ''
description: "Additional 'swift test' flags to be applied on when testing on all platforms."
env:
PACKAGE_ROOT: ${{ inputs.package_root != '' && format('--package-path={0}', inputs.package_root) || '' }}
EXTRA_FLAGS: ${{ inputs.extra_flags }}
WITH_TSAN: ${{ inputs.with_tsan && '' || '' }}
TEST_FILTER: ${{ inputs.test_filter != '' && format('--filter={0}', inputs.test_filter) || '' }}
# We use the unversioned "jammy" docker tag to specify the "latest" Swift release in several jobs.
jobs:
api-breakage:
if: ${{ inputs.with_public_api_check && !(github.event.pull_request.draft || false) && github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
container: swift:jammy
timeout-minutes: 20
steps:
- name: Check out code
uses: actions/checkout@v4
with: { 'fetch-depth': 0 }
- name: Run API breakage check
run: |
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
swift package ${PACKAGE_ROOT} diagnose-api-breaking-changes origin/main ${EXTRA_FLAGS}
dependency-graph:
if: ${{ inputs.with_deps_submission && github.event_name == 'push' }}
runs-on: ubuntu-latest
container: swift:jammy
permissions:
contents: write
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Fix Git configuration
run: |
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
apt-get update && apt-get install -y curl
- name: Submit dependency graph
uses: vapor-community/[email protected]
with:
path: ${{ inputs.package_root != '' && inputs.package_root || github.workspace }}
code-coverage:
if: ${{ inputs.with_coverage && !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:jammy
timeout-minutes: 30
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Run unit tests for coverage data
run: |
SWIFT_DETERMINISTIC_HASHING=1 swift test ${PACKAGE_ROOT} ${TEST_FILTER} --enable-code-coverage ${EXTRA_FLAGS}
- name: Upload coverage data
uses: vapor/[email protected]
with:
package_path: ${{ inputs.package_root }}
ignore_paths: ${{ inputs.coverage_ignores }}
build_parameters: ${{ inputs.extra_flags }}
gh-codeql:
if: ${{ (false && inputs.with_gh_codeql) && !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:jammy
permissions: { actions: write, contents: read, security-events: write }
timeout-minutes: 30
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Mark repo safe in non-fake global config
run: |
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
- name: Check Swift compatibility
id: swift-check
uses: vapor/ci/.github/actions/check-compatible-swift@main
with:
package_root: ${{ inputs.package_root }}
- name: Initialize CodeQL
if: ${{ steps.swift-check.outputs.swift-compatible == 'true' }}
uses: github/codeql-action/init@v3
with: { languages: swift }
- name: Perform build
if: ${{ steps.swift-check.outputs.swift-compatible == 'true' }}
run: |
swift build ${PACKAGE_ROOT} ${EXTRA_FLAGS}
- name: Run CodeQL analyze
if: ${{ steps.swift-check.outputs.swift-compatible == 'true' }}
uses: github/codeql-action/analyze@v3
linux-unit:
if: ${{ !(github.event.pull_request.draft || false) }}
strategy:
fail-fast: false
matrix:
swift-image:
- swift:5.8-jammy
- swift:5.9-jammy
- swift:5.10-jammy
- swiftlang/swift:nightly-main-jammy
runs-on: ubuntu-latest
container: ${{ matrix.swift-image }}
timeout-minutes: 60
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Check Swift compatibility
id: swift-check
uses: vapor/ci/.github/actions/check-compatible-swift@main
with:
package_root: ${{ inputs.package_root }}
- name: Run unit tests
if: ${{ steps.swift-check.outputs.swift-compatible == 'true' }}
run: |
SWIFT_DETERMINISTIC_HASHING=1 swift test ${PACKAGE_ROOT} ${WITH_TSAN} ${TEST_FILTER} ${EXTRA_FLAGS}
macos-unit:
if: ${{ !(github.event.pull_request.draft || false) }}
strategy:
fail-fast: false
matrix:
include:
- macos-version: macos-13
xcode-version: '~14.3'
- macos-version: macos-14
xcode-version: latest
runs-on: ${{ matrix.macos-version }}
timeout-minutes: 60
steps:
- name: Select appropriate Xcode version
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ matrix.xcode-version }}
- name: Check out code
uses: actions/checkout@v4
- name: Check Swift compatibility
id: swift-check
uses: vapor/ci/.github/actions/check-compatible-swift@main
with:
package_root: ${{ inputs.package_root }}
- name: Run unit tests
if: ${{ steps.swift-check.outputs.swift-compatible == 'true' }}
run: |
SWIFT_DETERMINISTIC_HASHING=1 swift test ${PACKAGE_ROOT} ${WITH_TSAN} ${TEST_FILTER} ${EXTRA_FLAGS}
# windows-unit:
# if: ${{ !(github.event.pull_request.draft || false) }}
# strategy:
# fail-fast: false
# matrix:
# swift-version:
# - 5.8
# - 5.9
# - 5.10
# include:
# - { swift-version: 5.8, swift-branch: swift-5.8.1-RELEASE, swift-tag: 5.8.1-RELEASE }
# - { swift-version: 5.9, swift-branch: swift-5.9.2-RELEASE, swift-tag: 5.9.2-RELEASE }
# - { swift-version: 5.10, swift-branch: swift-5.10-RELEASE, swift-tag: 5.10-RELEASE }
# runs-on: windows-latest
# timeout-minutes: 60
# steps:
# - name: Install Windows Swift toolchain
# uses: compnerd/gha-setup-swift@main
# with:
# branch: ${{ matrix.swift-branch }}
# tag: ${{ matrix.swift-tag }}
# - name: Check out code
# uses: actions/checkout@v4
# - name: Run unit tests
# run: |
# SWIFT_DETERMINISTIC_HASHING=1 swift test ${PACKAGE_ROOT} ${WITH_TSAN} ${TEST_FILTER} ${EXTRA_FLAGS}