-
Notifications
You must be signed in to change notification settings - Fork 460
217 lines (210 loc) · 8.32 KB
/
build.yml
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
name: Build and Test
# NOTE: If making changes to most of the steps, please also look to update
# regular_conformance.yml also.
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
core:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Looking at https://hub.docker.com/_/swift, the version only tags (i.e.
# - 5.9.2) can use different Ubuntu releases. But just to be safe we use
# the specific OS release.
#
# We could use less specific tags (i.e. - 5.9), so they "float" as
# new point release come, but to help make history/logs more clear,
# being explicit (at the cost of having to update with point releases)
# seems better. This should also ensure protobuf caching changes with
# each new image incase system in the Swift image are changed/updated.
swift:
- version: 6.0.3-noble
hook: "SWIFT_BUILD_TEST_HOOK=\"-Xswiftc -warnings-as-errors\""
- version: 5.10.1-noble
# No "hook", see https://github.com/apple/swift-protobuf/issues/1560 for the
# current issue with using -warnings-as-errors on linux.
- version: 5.9.2-focal
hook: "SWIFT_BUILD_TEST_HOOK=\"-Xswiftc -warnings-as-errors\""
- version: 5.8.1-focal
hook: "SWIFT_BUILD_TEST_HOOK=\"-Xswiftc -warnings-as-errors\""
# protobuf_git can reference a commit, tag, or branch
# commit: "commits/6935eae45c99926a000ecbef0be20dfd3d159e71"
# tag: "ref/tags/v3.11.4"
# branch: "ref/heads/main"
protobuf_git: ["ref/heads/main"]
container:
image: swift:${{ matrix.swift.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: swift-protobuf
- name: Update and install dependencies
# dependencies from https://github.com/protocolbuffers/protobuf/blob/main/src/README.md
# this step is run before get-sha because we need curl and jq for get-sha
run: apt-get update && apt-get install -y curl make g++ cmake jq
- name: Get Protobuf Commit SHA
id: get-sha
run: |
set -eu
url="https://api.github.com/repos/protocolbuffers/protobuf/git/${{ matrix.protobuf_git }}"
case ${{ matrix.protobuf_git }} in
ref/*)
echo "sha=$( curl -s -u "u:${{ github.token }}" "${url}" | jq -r .object.sha )" >> $GITHUB_OUTPUT
;;
commits/*)
echo "sha=$( curl -s -u "u:${{ github.token }}" "${url}" | jq -r .sha )" >> $GITHUB_OUTPUT
;;
esac
- name: Build
working-directory: swift-protobuf
run: make build ${{ matrix.swift.hook }}
- name: Test runtime
working-directory: swift-protobuf
run: make test-runtime ${{ matrix.swift.hook }}
- name: Cache protobuf
id: cache-protobuf
uses: actions/cache@v4
with:
path: protobuf
# NOTE: for refs that can float like 'main' the cache might be out of date!
key: ${{ runner.os }}-${{ matrix.swift.version}}-protobuf-${{ steps.get-sha.outputs.sha }}
- name: Checkout protobuf repo
if: steps.cache-protobuf.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
repository: protocolbuffers/protobuf
ref: ${{ steps.get-sha.outputs.sha }}
submodules: true
path: protobuf
- name: Build protobuf
if: steps.cache-protobuf.outputs.cache-hit != 'true'
working-directory: protobuf
# https://github.com/protocolbuffers/protobuf/blob/main/cmake/README.md#c-version
run: |
mkdir cmake_build
cd cmake_build
cmake \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_BUILD_TYPE=Release \
-Dprotobuf_BUILD_TESTS=OFF \
-Dprotobuf_INSTALL=OFF \
-Dprotobuf_BUILD_CONFORMANCE=ON \
-S ..
NUM_CPUS=$(getconf _NPROCESSORS_ONLN)
make -j "${NUM_CPUS}" protoc conformance_test_runner
- name: Test plugin
working-directory: swift-protobuf
run: make test-plugin PROTOC=../protobuf/cmake_build/protoc
- name: Test conformance
working-directory: swift-protobuf
run: make test-conformance CONFORMANCE_TEST_RUNNER=../protobuf/cmake_build/conformance_test_runner
- name: Test SPM plugin
working-directory: swift-protobuf
run: make test-spm-plugin PROTOC=../protobuf/cmake_build/protoc
- name: Compilation Tests
working-directory: swift-protobuf
run: make compile-tests PROTOC=../protobuf/cmake_build/protoc
- name: Test SPM plugin in Swift 6 mode
# This is a temporary step that basically allows us to test compiling the
# generated code in Swift 6 mode to keep an eye on the work needed.
if: startsWith(matrix.swift.version, '6.')
# This will fail until things are fixed, so don't break for it.
continue-on-error: true
working-directory: swift-protobuf
run: |
swift package tools-version --package-path PluginExamples --set 6.0
swift package tools-version --set 6.0
git diff
make test-spm-plugin PROTOC=../protobuf/cmake_build/protoc
api-breakage:
name: Api Breakage Compared to main branch
# Only on pull requests
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
container:
# Test on the latest Swift release. This could run on all the support
# Swift versions, but that doesn't seem worth it until there are Swift
# version specific conditionals to justify it.
image: swift:latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Mark the workspace as safe
# https://github.com/actions/checkout/issues/766
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
- name: Check for API breaking changes
run: swift package diagnose-api-breaking-changes origin/main
format-check:
name: swift-format Check
# Only on pull requests
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
container:
# Use use the latest Swift release and that's the version of swift-format
# people should use.
image: swift:latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Mark the workspace as safe
# https://github.com/actions/checkout/issues/766
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
- name: Run format check
run: |
set -eu
git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place
GIT_PAGER='' git diff --exit-code '*.swift'
# Disabled as it produces multiple warnings at the moment.
# - name: Run format lint check
# run: |
# set -eu
# git ls-files -z '*.swift' | xargs -0 swift format lint --strict --parallel
sanitizer_testing:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sanitizer: ["address", "thread"]
swiftpm_config: ["debug", "release"]
container:
# Test on the latest Swift release.
image: swift:latest
steps:
- uses: actions/checkout@v4
- name: Test
run: |
set -eu
# Trim out the generate files that are just compile tests, they take a while to compile and
# are covered in core instead.
rm Tests/SwiftProtobufTests/generated_swift_names*
# On linux, the tests seem to always see leaks that don't show up on macOS. Disable the
# leak detection and just assume it is a Linux Swift issue. This still gets validation
# for other memory errors. Maybe https://bugs.swift.org/browse/SR-6848.
if [ "${{ matrix.sanitizer }}" = "address" ] ; then
export ASAN_OPTIONS=detect_leaks=0
fi
# 'release' doesn't support @testable, force it on.
if [ "${{ matrix.swiftpm_config }}" = "release" ] ; then
EXTRAS="-Xswiftc -enable-testing"
fi
swift test -c ${{ matrix.swiftpm_config }} --sanitize=${{ matrix.sanitizer }} ${EXTRAS:-}
fuzzing_regressions:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swiftpm_config: ["debug", "release"]
container:
# Test on the latest Swift release.
image: swift:latest
steps:
- uses: actions/checkout@v4
- name: Build
run: FuzzTesting/do_build.sh --${{ matrix.swiftpm_config }}-only --run-regressions