Repository navigation
267 lines (255 loc) · 9.5 KB
/
Copy pathpull_request.yml
File metadata and controls
267 lines (255 loc) · 9.5 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
name: Pull request
permissions:
contents: read
on:
pull_request:
types: [opened, reopened, synchronize]
jobs:
tests:
name: Test
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
with:
linux_exclude_swift_versions: '[{"swift_version": "5.9"}, {"swift_version": "5.10"}, {"swift_version": "6.0"}, {"swift_version": "6.1"}, {"swift_version": "6.2"}]'
enable_windows_checks: false
enable_macos_checks: false
enable_macos_swiftly_checks: true
soundness:
name: Soundness
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
with:
license_header_check_project_name: "Swift.org"
unacceptable_language_check_enabled: false
format_check_enabled: false
bench:
name: Benchmark
runs-on: ubuntu-latest
env:
BUILD_CMD: swift build -c release
BENCH_CMD: .build/release/RegexBenchmark
BASELINE_FILE: benchmark-baseline
MAIN_FILE: benchmark-main
COMPARE_FILE: benchmark-pr
COMPARE_OUT_FILE: benchmark-results.txt
steps:
- name: Check out baseline branch
uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base
fetch-depth: 0
- name: Build baseline branch
working-directory: base
run: |
set -euo pipefail
eval "$BUILD_CMD"
- name: Run baseline benchmark
working-directory: base
run: |
set -euo pipefail
eval "$BENCH_CMD --save $RUNNER_TEMP/$BASELINE_FILE"
test -s "$RUNNER_TEMP/$BASELINE_FILE" || { echo "Baseline not created at $BASELINE_FILE"; exit 1; }
- name: Check out main branch
if: ${{ github.event.pull_request.base.ref != 'main' }}
uses: actions/checkout@v7
with:
ref: main
path: main-branch
fetch-depth: 0
- name: Build main branch
if: ${{ github.event.pull_request.base.ref != 'main' }}
working-directory: main-branch
run: |
set -euo pipefail
eval "$BUILD_CMD"
- name: Run main benchmark
if: ${{ github.event.pull_request.base.ref != 'main' }}
working-directory: main-branch
run: |
set -euo pipefail
eval "$BENCH_CMD --save $RUNNER_TEMP/$MAIN_FILE"
test -s "$RUNNER_TEMP/$MAIN_FILE" || { echo "Baseline (main) not created at $MAIN_FILE"; exit 1; }
- name: Check out PR branch
uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.head.sha }}
path: pr
fetch-depth: 0
- name: Build PR branch
working-directory: pr
run: |
set -euo pipefail
eval "$BUILD_CMD"
- name: Run PR benchmark
working-directory: pr
run: |
set -euo pipefail
eval "$BENCH_CMD --save $RUNNER_TEMP/$COMPARE_FILE"
test -s "$RUNNER_TEMP/$COMPARE_FILE" || { echo "Comparison not created at $COMPARE_FILE"; exit 1; }
eval "$BENCH_CMD --compare $RUNNER_TEMP/$BASELINE_FILE" | tee "$RUNNER_TEMP/$COMPARE_OUT_FILE"
- name: 📊 Compare benchmarks with base
working-directory: pr
run: |
set -euo pipefail
eval "$BENCH_CMD --load $RUNNER_TEMP/$COMPARE_FILE --compare $RUNNER_TEMP/$BASELINE_FILE --compare-compile-time $RUNNER_TEMP/$BASELINE_FILE" | tee "$RUNNER_TEMP/$COMPARE_OUT_FILE"
- name: 📊 Compare benchmarks with `main`
if: ${{ github.event.pull_request.base.ref != 'main' }}
working-directory: pr
run: |
set -euo pipefail
eval "$BENCH_CMD --load $RUNNER_TEMP/$COMPARE_FILE --compare $RUNNER_TEMP/$MAIN_FILE --compare-compile-time $RUNNER_TEMP/$MAIN_FILE"
- name: Upload benchmark artifacts
uses: actions/upload-artifact@v7
with:
name: benchmark-results
path: |
${{ runner.temp }}/${{ env.BASELINE_FILE }}
${{ runner.temp }}/${{ env.COMPARE_FILE }}
${{ runner.temp }}/${{ env.COMPARE_OUT_FILE }}
crossrepo:
name: Cross-Repo Validation
runs-on: ubuntu-latest
container:
image: swift:6.3-jammy
steps:
- name: Checkout repo
uses: actions/checkout@v7
- name: Install apt dependencies
run: apt-get -qq update && apt-get -qq -y install curl ninja-build
- name: Install CMake 3.30.2
run: |
ARCH=`uname -m`
curl -sL https://github.com/Kitware/CMake/releases/download/v3.30.2/cmake-3.30.2-linux-$ARCH.tar.gz -O
tar xzf cmake-3.30.2-linux-$ARCH.tar.gz
export PATH="`pwd`/cmake-3.30.2-linux-$ARCH/bin:$PATH"
echo "PATH=$PATH" >> $GITHUB_ENV
cmake --version
- name: Compare CMakeLists.txt against swiftlang/swift/Runtimes/Supplemental
id: compare
env:
UPSTREAM_DIR: https://raw.githubusercontent.com/swiftlang/swift/refs/heads/main/Runtimes/Supplemental/StringProcessing
MODULES: _StringProcessing _RegexParser
shell: bash
run: |
set -u
# `-f` so a file moving upstream reports a fetch error rather than
# diffing against a 404 page.
for module in $MODULES; do
if ! curl -fsSL "$UPSTREAM_DIR/$module/CMakeLists.txt" \
-o "upstream-$module-CMakeLists.txt"; then
echo "result=fetch-failed" >> "$GITHUB_OUTPUT"
echo "Could not fetch $module/CMakeLists.txt from swiftlang/swift."
exit 1
fi
done
: > "$RUNNER_TEMP/cmake-diff.txt"
status=0
for module in $MODULES; do
if ! diff -u \
--label "swiftlang/swift: Runtimes/Supplemental/StringProcessing/$module/CMakeLists.txt" \
--label "this repo: Sources/$module/CMakeLists.txt" \
"upstream-$module-CMakeLists.txt" \
"Sources/$module/CMakeLists.txt" \
>> "$RUNNER_TEMP/cmake-diff.txt"; then
status=1
fi
done
if [ "$status" -eq 0 ]; then
echo "result=match" >> "$GITHUB_OUTPUT"
echo "Both CMakeLists.txt files match swiftlang/swift."
else
echo "result=differs" >> "$GITHUB_OUTPUT"
cat "$RUNNER_TEMP/cmake-diff.txt"
fi
exit "$status"
- name: Configure CMake
id: configure
if: ${{ !cancelled() }}
run: cmake -G Ninja -S Sources -B build -DCMAKE_BUILD_TYPE=Release
- name: Build
id: build
if: ${{ !cancelled() }}
run: cmake --build build
- name: Verdict
if: ${{ always() }}
env:
COMPARE_OUTCOME: ${{ steps.compare.outcome }}
COMPARE_RESULT: ${{ steps.compare.outputs.result }}
CONFIGURE_OUTCOME: ${{ steps.configure.outcome }}
BUILD_OUTCOME: ${{ steps.build.outcome }}
shell: bash
run: |
set -u
# Report to the step log and to the job summary page.
emit() { printf '%s\n' "$@" | tee -a "$GITHUB_STEP_SUMMARY"; }
failed=0
# --- the CMake build ---
if [ "$CONFIGURE_OUTCOME" = failure ] || [ "$BUILD_OUTCOME" = failure ]; then
failed=1
if [ "$CONFIGURE_OUTCOME" = failure ]; then
stage='CMake configuration'
else
stage='CMake build'
fi
emit \
"## :x: $stage failed" \
'' \
'The CMake build of `_RegexParser` and `_StringProcessing` is broken.' \
"See the \"$stage\" step above for the output." \
''
fi
# --- the comparison against swiftlang/swift ---
case "${COMPARE_RESULT:-}" in
match)
;;
differs)
failed=1
emit \
'## :warning: `CMakeLists.txt` differs from swiftlang/swift' \
'' \
'<details><summary>Diff to apply upstream</summary>' \
'' \
'```diff'
tee -a "$GITHUB_STEP_SUMMARY" < "$RUNNER_TEMP/cmake-diff.txt"
emit '```' '' '</details>' ''
;;
fetch-failed)
failed=1
emit \
'## :x: Could not fetch the upstream `CMakeLists.txt` files'
;;
*)
failed=1
emit \
"## :x: Comparison did not complete (outcome: ${COMPARE_OUTCOME:-unknown})"
;;
esac
# --- all clear ---
if [ "$failed" -eq 0 ]; then
emit \
'## :white_check_mark: Cross-repo validation passed'
fi
exit "$failed"
required:
name: Required
runs-on: ubuntu-latest
needs:
- tests
- soundness
- bench
if: always() # Runs even if previous jobs fail so it can evaluate them
steps:
- name: Install required tools
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends coreutils jq
- name: Check upstream job statuses
env:
NEEDS_JSON: ${{ toJSON(needs) }}
run: |
failed=$(printf '%s' "$NEEDS_JSON" | jq -r 'to_entries | map(select(.value.result != "success")) | .[] | "\(.key): \(.value.result)"')
if [ -n "$failed" ]; then
echo "The following required jobs did not succeed:"
printf '%s\n' "$failed"
exit 1
fi
echo "All required jobs succeeded."