-
Notifications
You must be signed in to change notification settings - Fork 1
345 lines (327 loc) · 13.2 KB
/
ci.yml
File metadata and controls
345 lines (327 loc) · 13.2 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
name: JBird CI
permissions:
contents: read
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
changes:
name: Analyze Changes
runs-on: ubuntu-latest
outputs:
swift: ${{ steps.set.outputs.swift }}
c: ${{ steps.set.outputs.c }}
yaml: ${{ steps.set.outputs.yaml }}
markdown: ${{ steps.set.outputs.markdown }}
code: ${{ steps.set.outputs.code }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get changed files
id: changed
run: |
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
echo "swift=true" >> $GITHUB_OUTPUT
echo "c=true" >> $GITHUB_OUTPUT
echo "yaml=true" >> $GITHUB_OUTPUT
echo "markdown=true" >> $GITHUB_OUTPUT
echo "code=true" >> $GITHUB_OUTPUT
exit 0
fi
git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1
CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }})
echo "Changed files:"
echo "$CHANGED_FILES"
HAS_SWIFT=false
HAS_C=false
HAS_YAML=false
HAS_MD=false
ONLY_MD=true
for file in $CHANGED_FILES; do
[[ "$file" =~ \.swift$ ]] && HAS_SWIFT=true
[[ "$file" =~ \.c$ || "$file" =~ \.h$ ]] && HAS_C=true
[[ "$file" =~ \.ya?ml$ ]] && HAS_YAML=true
[[ "$file" =~ \.md$ ]] && HAS_MD=true
if [[ ! "$file" =~ \.md$ ]]; then
ONLY_MD=false
fi
done
echo "swift=$([[ $HAS_SWIFT == true ]] && echo true || echo false)" >> $GITHUB_OUTPUT
echo "c=$([[ $HAS_C == true ]] && echo true || echo false)" >> $GITHUB_OUTPUT
echo "yaml=$([[ $HAS_YAML == true ]] && echo true || echo false)" >> $GITHUB_OUTPUT
echo "markdown=$([[ $HAS_MD == true ]] && echo true || echo false)" >> $GITHUB_OUTPUT
echo "code=$([[ $ONLY_MD == true ]] && echo false || echo true)" >> $GITHUB_OUTPUT
- name: Set final outputs
id: set
run: |
echo "swift=${{ steps.changed.outputs.swift }}" >> $GITHUB_OUTPUT
echo "c=${{ steps.changed.outputs.c }}" >> $GITHUB_OUTPUT
echo "yaml=${{ steps.changed.outputs.yaml }}" >> $GITHUB_OUTPUT
echo "markdown=${{ steps.changed.outputs.markdown }}" >> $GITHUB_OUTPUT
echo "code=${{ steps.changed.outputs.code }}" >> $GITHUB_OUTPUT
build-xcode:
strategy:
matrix:
platform: [macos, maccatalyst, ios, watchos, tvos, visionos]
scheme: [JBird, JBirdCore, JBirdBuilders]
name: Build with Xcode (${{ matrix.platform }}, ${{ matrix.scheme }})
needs: changes
if: ${{ needs.changes.outputs.code == 'true' }}
runs-on: macos-26
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Select Xcode Version
run: ./.scripts/xcode-select
- name: Build JBird
run: ./.scripts/build-${{ matrix.platform }}-xcode ${{ matrix.scheme }}
swiftformat:
name: Run SwiftFormat
needs: changes
if: ${{ needs.changes.outputs.swift == 'true' || needs.changes.outputs.yaml == 'true' }}
runs-on: macos-26
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Select Xcode Version
run: ./.scripts/xcode-select
- name: Lint with SwiftFormat
run: ./.scripts/lint-swiftformat
build-macos-spm:
name: Build JBird (macOS)
strategy:
matrix:
swift: [6.1, 6.2]
needs: changes
if: ${{ needs.changes.outputs.swift == 'true' || needs.changes.outputs.c == 'true' || needs.changes.outputs.yaml == 'true' }}
runs-on: ${{ matrix.swift == '6.1' && 'macos-15' || 'macos-26' }}
outputs:
artifact-name: macos-build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Select Xcode Version
run: ./.scripts/xcode-select ${{ matrix.swift == '6.1' && '16.4' || '26.0' }}
- name: Build JBird
run: swift build -v --build-path .build
- name: Compress Build
run: zip -r build.zip .build
- name: Upload Build
uses: actions/upload-artifact@v4
with:
name: macos-build-${{ matrix.swift }}
path: build.zip
test-macos-spm:
name: Test JBird (macOS)
strategy:
matrix:
swift: [6.1, 6.2]
needs: [build-macos-spm, changes]
if: ${{ needs.changes.outputs.swift == 'true' || needs.changes.outputs.c == 'true' || needs.changes.outputs.yaml == 'true' }}
runs-on: ${{ matrix.swift == '6.1' && 'macos-15' || 'macos-26' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Xcode Version
run: ./.scripts/xcode-select ${{ matrix.swift == '6.1' && '16.4' || '26.0' }}
- name: Download Build
uses: actions/download-artifact@v4
with:
name: macos-build-${{ matrix.swift }}
path: .
- name: Decompress Build
run: unzip build.zip
- name: Test JBird
run: swift test --enable-code-coverage
- name: Generate Coverage Report
run: |
COVERAGE_JSON=$(swift test --show-codecov-path)
echo "Coverage report location: $COVERAGE_JSON"
# Create filtered coverage JSON with only project source files
# This excludes Swift package dependencies from the coverage report
FILTERED_JSON="${COVERAGE_JSON}.filtered"
jq '.data[0].files |= map(select(.filename | contains("/Sources/")))' "$COVERAGE_JSON" > "$FILTERED_JSON"
# Recalculate totals from filtered data
jq '.data[0].totals = {
lines: {
count: ([.data[0].files[].summary.lines.count] | add // 0),
covered: ([.data[0].files[].summary.lines.covered] | add // 0),
percent: (([.data[0].files[].summary.lines.covered] | add // 0) * 100.0 / ([.data[0].files[].summary.lines.count] | add // 1))
},
functions: {
count: ([.data[0].files[].summary.functions.count] | add // 0),
covered: ([.data[0].files[].summary.functions.covered] | add // 0),
percent: (([.data[0].files[].summary.functions.covered] | add // 0) * 100.0 / ([.data[0].files[].summary.functions.count] | add // 1))
},
regions: {
count: ([.data[0].files[].summary.regions.count] | add // 0),
covered: ([.data[0].files[].summary.regions.covered] | add // 0),
percent: (([.data[0].files[].summary.regions.covered] | add // 0) * 100.0 / ([.data[0].files[].summary.regions.count] | add // 1))
}
}' "$FILTERED_JSON" > "${FILTERED_JSON}.tmp" && mv "${FILTERED_JSON}.tmp" "$FILTERED_JSON"
# Extract coverage statistics from filtered data
LINES_PERCENT=$(jq -r '.data[0].totals.lines.percent' "$FILTERED_JSON")
LINES_COVERED=$(jq -r '.data[0].totals.lines.covered' "$FILTERED_JSON")
LINES_TOTAL=$(jq -r '.data[0].totals.lines.count' "$FILTERED_JSON")
FUNCTIONS_PERCENT=$(jq -r '.data[0].totals.functions.percent' "$FILTERED_JSON")
FUNCTIONS_COVERED=$(jq -r '.data[0].totals.functions.covered' "$FILTERED_JSON")
FUNCTIONS_TOTAL=$(jq -r '.data[0].totals.functions.count' "$FILTERED_JSON")
REGIONS_PERCENT=$(jq -r '.data[0].totals.regions.percent' "$FILTERED_JSON")
REGIONS_COVERED=$(jq -r '.data[0].totals.regions.covered' "$FILTERED_JSON")
REGIONS_TOTAL=$(jq -r '.data[0].totals.regions.count' "$FILTERED_JSON")
# Round percentages to 2 decimal places
LINES_PERCENT=$(printf "%.2f" "$LINES_PERCENT")
FUNCTIONS_PERCENT=$(printf "%.2f" "$FUNCTIONS_PERCENT")
REGIONS_PERCENT=$(printf "%.2f" "$REGIONS_PERCENT")
# Create markdown summary
cat >> $GITHUB_STEP_SUMMARY << EOF
## 📊 Code Coverage Report (macOS, Swift ${{ matrix.swift }})
| Metric | Coverage | Covered | Total |
|--------|----------|---------|-------|
| **Lines** | **${LINES_PERCENT}%** | ${LINES_COVERED} | ${LINES_TOTAL} |
| **Functions** | **${FUNCTIONS_PERCENT}%** | ${FUNCTIONS_COVERED} | ${FUNCTIONS_TOTAL} |
| **Regions** | **${REGIONS_PERCENT}%** | ${REGIONS_COVERED} | ${REGIONS_TOTAL} |
✨ Coverage report generated successfully!
EOF
echo "Lines Coverage: ${LINES_PERCENT}%"
echo "Functions Coverage: ${FUNCTIONS_PERCENT}%"
echo "Regions Coverage: ${REGIONS_PERCENT}%"
# Save filtered coverage path for Codecov upload
echo "COVERAGE_JSON=$FILTERED_JSON" >> $GITHUB_ENV
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: ${{ env.COVERAGE_JSON }}
flag: swift-${{ matrix.swift }}
name: macos-swift-${{ matrix.swift }}
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
build-ubuntu-spm:
name: Build JBird (Ubuntu)
strategy:
matrix:
swift: [6.1, 6.2]
needs: changes
if: ${{ needs.changes.outputs.swift == 'true' || needs.changes.outputs.c == 'true' || needs.changes.outputs.yaml == 'true' }}
runs-on: ubuntu-latest
outputs:
artifact-name: ubuntu-build
container:
image: swift:${{ matrix.swift }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build JBird
run: swift build -v --build-path .build
- name: Install `zip`
run: apt-get update && apt-get install -y zip
- name: Compress Build
run: zip -r build.zip .build
- name: Upload Build
uses: actions/upload-artifact@v4
with:
name: ubuntu-build-${{ matrix.swift }}
path: build.zip
test-ubuntu-spm:
name: Test JBird (Ubuntu)
strategy:
matrix:
swift: [6.1, 6.2]
needs: [build-ubuntu-spm, changes]
if: ${{ needs.changes.outputs.swift == 'true' || needs.changes.outputs.c == 'true' || needs.changes.outputs.yaml == 'true' }}
runs-on: ubuntu-latest
container:
image: swift:${{ matrix.swift }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Build
uses: actions/download-artifact@v4
with:
name: ubuntu-build-${{ matrix.swift }}
path: .
- name: Install `unzip`
run: apt-get update && apt-get install -y unzip
- name: Decompress Build
run: unzip build.zip
- name: Test JBird
run: swift test
clang-format:
name: Run clang-format
needs: changes
if: ${{ needs.changes.outputs.c == 'true' || needs.changes.outputs.yaml == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install clang-format
run: |
sudo apt-get update
sudo apt-get install -y clang-format
- name: Validate formatting
run: ./.scripts/lint-clang-format
lint-docc:
name: Validate Documentation
needs: changes
if: ${{ needs.changes.outputs.swift == 'true' || needs.changes.outputs.yaml == 'true' || needs.changes.outputs.markdown == 'true' }}
runs-on: macos-26
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Select Xcode Version
run: ./.scripts/xcode-select
- name: Validate Documentation
run: ./.scripts/lint-docc
build-xcframework:
strategy:
matrix:
target: [JBird, JBirdCore, JBirdBuilders]
name: Build XCFramework (${{ matrix.target }})
needs: changes
if: ${{ needs.changes.outputs.code == 'true' }}
runs-on: macos-26
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Select Xcode Version
run: ./.scripts/xcode-select
- name: Build XCFramework
run: ./.scripts/build-xcframework ${{ matrix.target }}
validate-pr:
name: Validate Pull Request
if: ${{ always() && github.event_name == 'pull_request' }}
needs:
- build-xcode
- build-macos-spm
- test-macos-spm
- build-ubuntu-spm
- test-ubuntu-spm
- build-xcframework
- swiftformat
- clang-format
- lint-docc
runs-on: ubuntu-latest
steps:
- name: Check upstream jobs
run: |
# If any job failed, this status will not be 'success'
if [[ "${{ needs.build-xcode.result }}" == "failure" ]] || \
[[ "${{ needs.build-macos-spm.result }}" == "failure" ]] || \
[[ "${{ needs.test-macos-spm.result }}" == "failure" ]] || \
[[ "${{ needs.build-ubuntu-spm.result }}" == "failure" ]] || \
[[ "${{ needs.test-ubuntu-spm.result }}" == "failure" ]] || \
[[ "${{ needs.build-xcframework.result }}" == "failure" ]] || \
[[ "${{ needs.swiftformat.result }}" == "failure" ]] || \
[[ "${{ needs.clang-format.result }}" == "failure" ]] || \
[[ "${{ needs.lint-docc.result }}" == "failure" ]]; then
echo "❌ Upstream job failed."
exit 1
else
echo "✅ All required jobs completed successfully."
fi