-
Notifications
You must be signed in to change notification settings - Fork 4
129 lines (117 loc) · 4.3 KB
/
Copy pathexample-tests.yml
File metadata and controls
129 lines (117 loc) · 4.3 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
# Example 集成测试:单仓内 Example(纯 Swift Package Manager,本地引用根目录 Package.swift)。
name: Example iOS Tests
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
concurrency:
group: example-ios-tests-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: macos-15
timeout-minutes: 45
env:
PROJECT: STBaseProjectExample.xcodeproj
SCHEME: STBaseProjectExample
RESULT: build/result.xcresult
steps:
- uses: actions/checkout@v4
- name: Select Xcode
run: bash "${GITHUB_WORKSPACE}/.github/select_xcode_ci.sh"
- name: Pick iOS Simulator
id: sim
shell: bash
run: |
set -euo pipefail
xcrun simctl list devices available -j > /tmp/devices.json
UDID="$(python3 <<'PY'
import json, sys
with open("/tmp/devices.json") as f:
data = json.load(f)["devices"]
for runtime in sorted([k for k in data if "iOS" in k], reverse=True):
for dv in data[runtime]:
if dv.get("isAvailable") and "iPhone" in dv["name"]:
print(dv["udid"]); sys.exit(0)
sys.exit("No available iPhone simulator found")
PY
)"
echo "Picked simulator: $UDID"
echo "udid=$UDID" >> "$GITHUB_OUTPUT"
xcrun simctl boot "$UDID" || true
xcrun simctl bootstatus "$UDID" -b
- name: Resolve SPM dependencies
working-directory: Example
run: |
xcodebuild -resolvePackageDependencies \
-project "$PROJECT" \
-scheme "$SCHEME"
- name: Run tests
working-directory: Example
shell: bash
run: |
set -o pipefail
mkdir -p build
xcodebuild test \
-project "$PROJECT" \
-scheme "$SCHEME" \
-destination "platform=iOS Simulator,id=${{ steps.sim.outputs.udid }}" \
-resultBundlePath "$RESULT" \
-parallel-testing-enabled YES \
-test-iterations 2 \
-retry-tests-on-failure \
CODE_SIGN_STYLE=Manual \
CODE_SIGN_IDENTITY="-" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=YES \
DEVELOPMENT_TEAM="" \
PROVISIONING_PROFILE_SPECIFIER="" \
| tee build/xcodebuild.log
- name: Test summary
if: always()
shell: bash
run: |
if [ ! -d "$RESULT" ]; then
echo "::error::No xcresult bundle produced"; exit 1
fi
xcrun xcresulttool get test-results summary \
--path "$RESULT" --format json > build/summary.json
python3 - <<'PY'
import json, os
with open("build/summary.json") as f:
d = json.load(f)
total = d["passedTests"] + d["failedTests"] + d["skippedTests"]
print(f"Total: {total}")
print(f"Passed: {d['passedTests']}")
print(f"Failed: {d['failedTests']}")
print(f"Skipped: {d['skippedTests']}")
print(f"Result: {d['result']}")
step = os.environ.get("GITHUB_STEP_SUMMARY")
if step:
with open(step, "a") as f:
f.write("## Example iOS Test Summary\n\n")
f.write(f"| Metric | Value |\n|---|---|\n")
f.write(f"| Total | {total} |\n")
f.write(f"| Passed | {d['passedTests']} |\n")
f.write(f"| Failed | {d['failedTests']} |\n")
f.write(f"| Skipped | {d['skippedTests']} |\n")
f.write(f"| Result | **{d['result']}** |\n")
for tf in d.get("testFailures", [])[:50]:
f.write(f"\n- ❌ `{tf.get('testIdentifierString','?')}` — {tf.get('failureText','')}\n")
PY
- name: Upload xcresult on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: xcresult-${{ github.run_id }}
path: build/result.xcresult
retention-days: 14
- name: Upload xcodebuild log
if: always()
uses: actions/upload-artifact@v4
with:
name: xcodebuild-log-${{ github.run_id }}
path: build/xcodebuild.log
retention-days: 7