-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (122 loc) · 4.95 KB
/
Copy pathci.yml
File metadata and controls
145 lines (122 loc) · 4.95 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
name: Sensor CI
on:
push:
branches: [main, master]
pull_request:
schedule:
# Every Monday at 02:00 UTC
- cron: '0 2 * * 1'
jobs:
test:
runs-on: macos-15
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Show Xcode and simulator info
run: |
xcodebuild -version
swift --version
xcrun simctl list runtimes
xcrun simctl list devices available
- name: Resolve package dependencies
run: swift package resolve
- name: Detect scheme and simulator
run: |
SCHEME=$(swift package dump-package | python3 -c "import json,sys; print(json.load(sys.stdin)['name'])")
echo "SCHEME=$SCHEME" >> "$GITHUB_ENV"
# Find the latest available iPhone simulator name (name-based, more robust than UDID)
SIM_NAME=$(xcrun simctl list devices available --json | python3 -c "
import json, sys
devs = json.load(sys.stdin)['devices']
iphones = [
(rt, d['name'])
for rt, dl in devs.items()
for d in dl
if 'iOS' in rt and 'iPhone' in d['name'] and d.get('isAvailable', True)
]
iphones.sort(reverse=True)
print(iphones[0][1] if iphones else 'iPhone 16')
")
echo "SIM_NAME=$SIM_NAME" >> "$GITHUB_ENV"
echo "Detected scheme: $SCHEME"
echo "Detected simulator: $SIM_NAME"
- name: Build
id: build
run: |
xcodebuild build \
-scheme "$SCHEME" \
-destination "platform=iOS Simulator,name=$SIM_NAME" \
-sdk iphonesimulator \
2>&1 | tee build_output.txt; exit "${PIPESTATUS[0]}"
continue-on-error: true
- name: Test
id: test
if: steps.build.outcome == 'success'
run: |
xcodebuild test \
-scheme "$SCHEME" \
-destination "platform=iOS Simulator,name=$SIM_NAME" \
-sdk iphonesimulator \
-configuration Debug \
-enableCodeCoverage YES \
2>&1 | tee test_output.txt; exit "${PIPESTATUS[0]}"
continue-on-error: true
- name: Create or update issue on failure
if: steps.build.outcome == 'failure' || steps.test.outcome == 'failure'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ steps.build.outcome }}" = "failure" ]; then
FAILED="build"
LOG_FILE="build_output.txt"
else
FAILED="test"
LOG_FILE="test_output.txt"
fi
ERRORS=$(grep -E 'error:|FAILED|\*\* BUILD FAILED' "$LOG_FILE" 2>/dev/null | head -60 || true)
[ -z "$ERRORS" ] && ERRORS="(no error lines captured — see full logs above)"
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
TODAY=$(date -u +%Y-%m-%d)
BODY="## :x: Automated CI ${FAILED} failure
| | |
|---|---|
| **Workflow run** | [View logs](${RUN_URL}) |
| **Trigger** | \`${{ github.event_name }}\` |
| **Ref** | \`${{ github.ref }}\` |
| **Commit** | \`${SHORT_SHA}\` |
## Error summary
\`\`\`
${ERRORS}
\`\`\`"
# Ensure ci-failure label exists (ignore error if already present)
gh label create ci-failure --color d73a4a --description "Automated CI test failure" 2>/dev/null || true
# Find existing open ci-failure issue number
ISSUE_NUMBER=$(gh issue list --state open --label ci-failure --json number --jq '.[0].number // empty')
if [ -n "$ISSUE_NUMBER" ]; then
gh issue comment "$ISSUE_NUMBER" --body "### :warning: New failure (${TODAY})
${BODY}"
else
gh issue create \
--title "[CI] ${FAILED} failure detected" \
--body "$BODY" \
--label ci-failure
fi
- name: Close ci-failure issue on success
if: steps.build.outcome == 'success' && steps.test.outcome == 'success'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
ISSUE_NUMBERS=$(gh issue list --state open --label ci-failure --json number --jq '.[].number')
for ISSUE_NUMBER in $ISSUE_NUMBERS; do
gh issue comment "$ISSUE_NUMBER" \
--body ":white_check_mark: All tests are passing again. See [run ${{ github.run_id }}](${RUN_URL})."
gh issue close "$ISSUE_NUMBER"
done
- name: Fail job if build or tests failed
if: steps.build.outcome == 'failure' || steps.test.outcome == 'failure'
run: |
echo "Build outcome: ${{ steps.build.outcome }}"
echo "Test outcome: ${{ steps.test.outcome }}"
exit 1