Repository navigation
157 lines (134 loc) · 4.33 KB
/
Copy pathcontract-test.yml
File metadata and controls
157 lines (134 loc) · 4.33 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
name: CI
on:
push:
branches: [dev]
pull_request:
workflow_dispatch:
schedule:
# Run daily to catch core-side drift
- cron: '0 6 * * *'
permissions:
contents: read
id-token: write
jobs:
build:
runs-on: macos-26
steps:
- name: Checkout
uses: actions/checkout@v4
with:
lfs: true
- name: Build
run: >
xcodebuild build
-project Sleepypod.xcodeproj
-scheme Sleepypod
-destination 'generic/platform=iOS'
CODE_SIGNING_ALLOWED=NO
SWIFT_TREAT_WARNINGS_AS_ERRORS=YES
-quiet
lint:
runs-on: macos-15
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install SwiftLint
run: brew install swiftlint
- name: Lint
run: swiftlint --strict
contract-test:
runs-on: macos-15
steps:
- name: Checkout iOS
uses: actions/checkout@v4
- name: Checkout core
uses: actions/checkout@v4
with:
repository: sleepypod/core
path: core-checkout
- name: Copy iOS model files into Swift package
run: |
for f in Side DeviceStatus VitalsRecord SleepRecord MovementRecord ServerStatus Settings Schedule Services TemperatureConversion; do
cp "Sleepypod/Models/${f}.swift" contract-tests/Sources/SleepypodModels/
done
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
package_json_file: core-checkout/package.json
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'
cache-dependency-path: core-checkout/pnpm-lock.yaml
- name: Install core dependencies
run: cd core-checkout && pnpm install --frozen-lockfile
- name: Start core server (dev mode)
run: |
cd core-checkout && pnpm dev &
echo "SERVER_PID=$!" >> "$GITHUB_ENV"
- name: Wait for server
run: |
for i in $(seq 1 60); do
if curl -sf "http://localhost:3000/api/trpc/healthcheck?input=%7B%22json%22%3A%7B%7D%7D" > /dev/null 2>&1; then
echo "Server ready after ${i}s"
exit 0
fi
sleep 1
done
echo "Server failed to start within 60s"
exit 1
- name: Seed test data
run: |
cd core-checkout && bash ../contract-tests/scripts/seed-test-data.sh
- name: Snapshot API responses
run: bash contract-tests/scripts/snapshot-responses.sh
- name: Run Swift contract tests
run: cd contract-tests && swift test --enable-code-coverage --xunit-output test-results.xml
- name: Export coverage to lcov
if: always()
run: |
cd contract-tests
BIN_PATH=$(swift build --show-bin-path)
PROFDATA="$BIN_PATH/codecov/default.profdata"
XCTEST_BIN=$(find "$BIN_PATH" -name '*.xctest' -print -quit)
BINARY="$XCTEST_BIN/Contents/MacOS/$(basename "$XCTEST_BIN" .xctest)"
if [ -f "$PROFDATA" ] && [ -f "$BINARY" ]; then
xcrun llvm-cov export -format=lcov \
-instr-profile "$PROFDATA" \
"$BINARY" > lcov.info
else
echo "::warning::profdata or xctest binary missing — skipping lcov export"
: > lcov.info
fi
- name: Upload coverage reports to Codecov
if: always()
uses: codecov/codecov-action@v5
with:
use_oidc: true
slug: sleepypod/ios
files: contract-tests/lcov.info
flags: contract-tests
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
use_oidc: true
slug: sleepypod/ios
files: contract-tests/test-results.xml
- name: Stop server
if: always()
run: kill "$SERVER_PID" 2>/dev/null || true
done:
if: always()
needs: [build, lint, contract-test]
runs-on: ubuntu-latest
steps:
- name: Check results
run: |
if [[ "${{ needs.build.result }}" != "success" ||
"${{ needs.lint.result }}" != "success" ||
"${{ needs.contract-test.result }}" != "success" ]]; then
echo "One or more jobs failed"
exit 1
fi