-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (84 loc) · 2.74 KB
/
Copy pathci.yml
File metadata and controls
100 lines (84 loc) · 2.74 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
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
# Cancel in-progress runs for the same branch/PR to save resources
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
build-and-test:
name: Build & Test (Swift 6.2+)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Swift
uses: swift-actions/setup-swift@v2
with:
swift-version: '6.2'
- name: Verify Swift installation
run: swift --version
- name: Cache SPM dependencies
uses: actions/cache@v4
with:
path: .build
key: ${{ runner.os }}-spm-${{ hashFiles('Package.swift', 'Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
- name: Build
run: |
set -o pipefail
swift build 2>&1 | tee build.log
- name: Run tests with coverage
run: |
set -o pipefail
swift test --enable-code-coverage 2>&1 | tee test-output.log
- name: Check code coverage
run: |
CODECOV_JSON=$(swift test --show-codecov-path)
if [ ! -f "$CODECOV_JSON" ]; then
echo "Could not find coverage JSON at $CODECOV_JSON"
exit 1
fi
COVERAGE=$(python3 -c "
import json, sys
with open('$CODECOV_JSON') as f:
data = json.load(f)
files = data.get('data', [{}])[0].get('files', [])
covered = 0
total = 0
for f in files:
# Only count project source files, not dependencies
if '/Sources/JPEGLS/' in f['filename'] or '/Sources/jpeglscli/' in f['filename']:
covered += f['summary']['lines']['covered']
total += f['summary']['lines']['count']
pct = (covered / total * 100) if total else 0
print(f'{pct:.2f}')
")
echo "Source code coverage: ${COVERAGE}%"
THRESHOLD=95
if [ "$(echo "$COVERAGE < $THRESHOLD" | bc -l)" -eq 1 ]; then
echo "FAIL: Code coverage ${COVERAGE}% is below the ${THRESHOLD}% threshold."
exit 1
else
echo "PASS: Code coverage ${COVERAGE}% meets the ${THRESHOLD}% threshold."
fi
- name: Upload build log
if: failure()
uses: actions/upload-artifact@v4
with:
name: build-log
path: build.log
retention-days: 7
- name: Upload test output
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-output
path: test-output.log
retention-days: 7