Repository navigation
240 lines (212 loc) · 9.99 KB
/
Copy pathci.yml
File metadata and controls
240 lines (212 loc) · 9.99 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
name: CI
# After a stacked PR is retargeted (e.g. its feat/* base merged), push a commit or
# close and reopen it: a base change fires only `edited`, which this workflow does not
# listen to, because CodeRabbit's body edits would rebuild on every one of them.
on:
pull_request:
push:
branches:
- master
permissions:
contents: read
concurrency:
# One group per commit on master, so a burst of merges does not cancel the
# queued run of the commit in the middle.
group: ci-${{ github.event_name == 'push' && github.sha || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
build:
name: "Build: iOS device + macOS"
runs-on: macos-26
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: ./.github/actions/select-xcode
# Release for devices is what ships. The Debug simulator build (previews
# included) happens in Test.
- name: Build Release
run: |
xcodebuild -scheme DashUIKit \
-destination 'generic/platform=iOS' \
-configuration Release \
CODE_SIGNING_ALLOWED=NO \
-quiet build
# The documented local build; also compiles the macOS/AppKit branches.
- name: Build for macOS
run: swift build
test:
name: Unit tests (iOS Simulator)
runs-on: macos-26
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: ./.github/actions/select-xcode
# On the simulator, not macOS: UIKit-only files are compiled out on macOS.
# Without -quiet so the failure reason and the executed-test count are in the log;
# no diagnostics collection, which adds ~10 minutes to every failing run.
- name: Run tests
run: |
udid=$(.github/scripts/pick-simulator.sh)
xcodebuild -scheme DashUIKit \
-destination "platform=iOS Simulator,id=${udid}" \
-collect-test-diagnostics never \
CODE_SIGNING_ALLOWED=NO \
test
snapshots:
# fetch-snapshots.sh finds the job by this name.
name: Snapshot tests (iOS Simulator)
runs-on: macos-26
timeout-minutes: 30
steps:
# The PR head, not the merge with master: the references it records are committed
# to the branch, so they must show the branch's own code.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
persist-credentials: false
- uses: ./.github/actions/select-xcode
- name: Note what is rendered
env:
BASE_REF: ${{ github.base_ref }}
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
run: |
if [ -n "$BASE_REF" ]; then
echo "Rendered the PR head \`${HEAD_SHA:0:10}\`, not its merge with \`${BASE_REF}\`: after \`${BASE_REF}\` changes a covered component, merge it in and re-record before merging (docs/snapshot-tests.md)." >> "$GITHUB_STEP_SUMMARY"
fi
# Xcode versions resolve and name packages differently (swift-issue-reporting,
# formerly xctest-dynamic-overlay), so the clones are kept per Xcode.
- id: xcode
run: echo "version=$(xcodebuild -version | tr '\n' ' ' | tr -c 'A-Za-z0-9.' '-')" >> "$GITHUB_OUTPUT"
# swift-snapshot-testing pulls swift-syntax into the graph; keep the clones.
# Restore and save are separate steps because a recording run fails on purpose.
- id: packages
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ runner.temp }}/SourcePackages
key: snapshot-packages-${{ runner.os }}-${{ steps.xcode.outputs.version }}-${{ hashFiles('SnapshotTests/Package.resolved') }}
# Package.resolved is the one this Xcode writes: a version it would change, or any
# edit to SnapshotTests/Package.swift (the file carries a hash of the manifest),
# fails here, with the file to commit in the log. Another Xcode (a local Xcode 27, say)
# rewrites it; don't commit that.
- name: Resolve packages
working-directory: SnapshotTests
env:
PACKAGES: ${{ runner.temp }}/SourcePackages
run: |
xcodebuild -resolvePackageDependencies \
-scheme DashUIKitSnapshotTests-Package \
-clonedSourcePackagesDirPath "$PACKAGES"
if ! git diff --quiet -- Package.resolved; then
echo "::error file=SnapshotTests/Package.resolved::Package.resolved is not what $(xcodebuild -version | sed -n 1p) resolves. Commit this file:"
cat Package.resolved
exit 1
fi
- name: Save the package clones
if: ${{ steps.packages.outputs.cache-hit != 'true' }}
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ runner.temp }}/SourcePackages
key: ${{ steps.packages.outputs.cache-primary-key }}
# The references are rendered here and only compared here (docs/snapshot-tests.md).
# REQUIRE turns a runner on another iOS runtime into a failure, not a skip.
# RECORD=failed rewrites a missing or changed reference in the checkout and still
# fails the test; the upload step below sends the rewritten set to
# .github/scripts/fetch-snapshots.sh. xcodebuild passes a run where every test was
# skipped, so the summary line is checked too.
- name: Run snapshot tests
id: test
working-directory: SnapshotTests
env:
LOG: ${{ runner.temp }}/snapshot-tests.log
PACKAGES: ${{ runner.temp }}/SourcePackages
TEST_RUNNER_SNAPSHOT_REQUIRE_REFERENCE_ENVIRONMENT: "1"
TEST_RUNNER_SNAPSHOT_TESTING_RECORD: failed
run: |
set -o pipefail
# One device, so code that reads the screen size renders the same every time.
udid=$(../.github/scripts/pick-simulator.sh "iPhone 17")
xcodebuild -scheme DashUIKitSnapshotTests-Package \
-destination "platform=iOS Simulator,id=${udid}" \
-clonedSourcePackagesDirPath "$PACKAGES" \
-disableAutomaticPackageResolution \
-testLanguage en -testRegion US \
-parallel-testing-enabled NO \
-collect-test-diagnostics never \
CODE_SIGNING_ALLOWED=NO \
test 2>&1 | tee "$LOG"
summary=$(grep -E "Executed [0-9]+ tests?," "$LOG" | tail -1 || true)
case "$summary" in
*"Executed 0 tests"* | *skipped* | "")
echo "::error::Snapshot tests did not all run: ${summary:-no summary line}"
exit 1 ;;
esac
# Only when a reference was written: a run that failed before rendering (build
# error, environment mismatch) has nothing to fetch.
- name: Check for re-recorded references
id: recorded
if: ${{ failure() && steps.test.outcome == 'failure' }}
run: |
if [ -n "$(git status --porcelain --untracked-files=all -- SnapshotTests/Tests/DashUIKitSnapshotTests/__Snapshots__)" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "::notice::No reference was re-recorded; see the test log for the failure."
fi
- name: Upload re-recorded references
if: ${{ failure() && steps.recorded.outputs.changed == 'true' }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: snapshots
path: SnapshotTests/Tests/DashUIKitSnapshotTests/__Snapshots__
if-no-files-found: error
# A re-run of the job replaces the set of the earlier attempt.
overwrite: true
retention-days: 14
conventions:
name: "Conventions: assets, colors, strings"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- id: checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Asset catalog ↔ DashIcon / Color.dash, asset and string bundles, hardcoded
# colors, @available at or below the floor (see the script header).
- name: Check conventions
run: .github/scripts/conventions.sh
# Breaks a copy of the tree once per rule, so a rule that stops matching fails here.
# It needs a clean baseline, so it runs only when the check above passed.
- name: Test the conventions script
run: .github/scripts/tests/conventions-test.sh
# The PR-description check runs from the base branch, so its rules are tested here,
# also when a conventions step above failed.
- name: Test the Before / After screenshots check
if: ${{ !cancelled() && steps.checkout.outcome == 'success' }}
run: python3 .github/scripts/tests/screenshots-test.py
actionlint:
name: Lint CI config (actionlint, shellcheck)
runs-on: ubuntu-latest
timeout-minutes: 10
env:
ACTIONLINT_VERSION: "1.7.12"
ACTIONLINT_SHA256: 8aca8db96f1b94770f1b0d72b6dddcb1ebb8123cb3712530b08cc387b349a3d8
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# actionlint ships no action. Dependabot cannot see this pin: bump it by hand.
- name: Install actionlint
run: |
tarball="actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz"
curl -sSfLo "$tarball" "https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}/${tarball}"
echo "${ACTIONLINT_SHA256} ${tarball}" | sha256sum -c -
tar xzf "$tarball" actionlint
- name: Run actionlint
run: ./actionlint -color
# actionlint only checks inline run: blocks.
- name: Run shellcheck on scripts
run: shellcheck .github/scripts/*.sh .github/scripts/tests/*.sh