forked from nats-io/nats.c
-
Notifications
You must be signed in to change notification settings - Fork 0
243 lines (224 loc) · 8.73 KB
/
build-test.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
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
on:
workflow_call:
inputs:
arch:
type: string
default: "64"
compiler:
type: string
default: "gcc"
coverage:
type: string
default: "OFF"
dev_mode:
type: string
default: "OFF"
pool_dispatch:
type: string
default: "NO-pool"
write_deadline:
type: string
default: "NO-write_deadline"
tls:
type: string
default: "TLS"
verify_host:
type: string
default: "verify_host"
repeat:
type: string
default: "1"
sanitize:
type: string
description: "sanitize option to use, 'address' or 'thread'"
server_version:
type: string
description: "nats-server version to test with"
default: "latest"
streaming:
type: string
default: "ON"
type:
type: string
description: "Debug or Release."
default: "Release"
ubuntu_version:
type: string
description: "Ubuntu version to use, e.g. '20.04'"
default: "latest"
verbose_test_output:
type: string
default: "OFF"
verbose_make_output:
type: string
default: "OFF"
benchmark:
type: string
default: "OFF"
secrets:
CODECOV_TOKEN:
description: "Codecov repo token"
permissions:
contents: write # to comment on coverage.
defaults:
run:
shell: bash --noprofile --norc -x -eo pipefail {0}
jobs:
do:
runs-on: ubuntu-${{ inputs.ubuntu_version }}
name: "${{ inputs.ubuntu_version }} - nats:${{ inputs.server_version }}"
steps:
- name: Checkout nats.c
uses: actions/checkout@v4
- name: "Checkout dependencies (nats.c.deps)"
uses: actions/checkout@v4
with:
repository: nats-io/nats.c.deps
path: deps
# configure the cmake flags and NATS_... environment variables
- id: cmake-flags
name: Configure cmake flags
env:
flags: -DNATS_BUILD_ARCH=${{ inputs.arch }}
-DCMAKE_BUILD_TYPE=${{ inputs.type }}
-DNATS_BUILD_STREAMING=${{ inputs.streaming }}
-DNATS_PROTOBUF_DIR=${{ github.workspace}}/deps/pbuf
-DNATS_BUILD_USE_SODIUM=ON
-DNATS_SODIUM_DIR=${{ github.workspace}}/deps/sodium
run: |
if [[ "${{ inputs.tls }}" == "TLS" ]]; then
flags="$flags -DNATS_BUILD_WITH_TLS=ON"
if [[ "${{ inputs.verify_host }}" == "verify_host" ]]; then
flags="$flags -DNATS_BUILD_TLS_FORCE_HOST_VERIFY=ON"
else
flags="$flags -DNATS_BUILD_TLS_FORCE_HOST_VERIFY=OFF"
fi
else
flags="$flags -DNATS_BUILD_WITH_TLS=OFF"
fi
if [[ -n "${{ inputs.sanitize }}" ]]; then
flags="$flags -DNATS_SANITIZE=ON -DCMAKE_C_FLAGS=-fsanitize=${{ inputs.sanitize }}"
fi
if [[ "${{ inputs.coverage }}" == "ON" ]]; then
flags="$flags -DNATS_COVERAGE=ON"
fi
if [[ "${{ inputs.dev_mode }}" == "ON" ]]; then
flags="$flags -DDEV_MODE=ON"
fi
if [[ "${{ inputs.verbose_make_output }}" == "ON" ]]; then
flags="$flags -DCMAKE_VERBOSE_MAKEFILE=ON"
fi
echo "flags=$flags" >> $GITHUB_OUTPUT
- id: nats-vars
name: Configure NATS_ environment variables
run: |
if [[ -n "${{ inputs.sanitize }}" ]]; then
echo "NATS_TEST_VALGRIND=yes" >> $GITHUB_ENV
fi
if [[ "${{ inputs.pool_dispatch }}" == "pool" ]]; then
echo "NATS_DEFAULT_TO_LIB_MSG_DELIVERY=yes" >> $GITHUB_ENV
fi
if [[ "${{ inputs.write_deadline }}" == "write_deadline" ]]; then
echo "NATS_DEFAULT_LIB_WRITE_DEADLINE=2000" >> $GITHUB_ENV
fi
echo "CC=${{ inputs.compiler }}" >> $GITHUB_ENV
# install build dependencies
- name: Install ${{ inputs.compiler }} if needed
if: startsWith(inputs.compiler, 'clang-') || startsWith(inputs.compiler, 'gcc-')
run: |
sudo apt-get -q update
sudo apt-get -y install ${{ inputs.compiler }}
# otherwise, configure cmake, build, archive and upload
- name: CMake
run: |
mkdir -p build
cd build
cmake .. ${{ steps.cmake-flags.outputs.flags }}
make rebuild_cache && make
# testing
- name: "Download nats-server version ${{ inputs.server_version }}"
if: inputs.server_version
working-directory: ./build
run: |
rel=${{ inputs.server_version }}
if [ "$rel" = "latest" ]; then
rel=$(curl -s https://api.github.com/repos/nats-io/nats-server/releases/latest | jq -r '.tag_name')
fi
if [ "$rel" != "${rel#v}" ] && wget https://github.com/nats-io/nats-server/releases/download/$rel/nats-server-$rel-linux-amd64.tar.gz; then
tar -xzf nats-server-$rel-linux-amd64.tar.gz
cp nats-server-$rel-linux-amd64/nats-server ../deps/nats-server/nats-server
else
for c in 1 2 3 4 5
do
echo "Attempt $c to download binary for main"
rm -f ./nats-server
curl -sf "https://binaries.nats.dev/nats-io/nats-server/v2@$rel" | PREFIX=. sh
# We are sometimes getting nats-server of size 0. Make sure we have a
# working nats-server by making sure we get a version number.
v="$(./nats-server -v)"
if [ "$v" != "" ]; then
break
fi
done
mv ./nats-server ../deps/nats-server/nats-server
fi
- name: "Test"
if: inputs.benchmark == 'OFF'
working-directory: ./build
run: |
export PATH=../deps/nats-server:../deps/nats-streaming-server:$PATH
export NATS_TEST_SERVER_VERSION="$(nats-server -v)"
flags=""
ctest -L 'test' --timeout 60 --output-on-failure --repeat-until-fail ${{ inputs.repeat }}
- name: Upload coverage reports to Codecov
# PRs from external contributors fail: https://github.com/codecov/feedback/issues/301
# Only upload coverage reports for PRs from the same repo (not forks)
if: inputs.coverage == 'ON' && github.event.pull_request.head.repo.full_name == github.repository
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
# verbose: true
- name: "Cache for base benchmark for ${{ github.event.pull_request.base.ref }}"
id: cache-base-bench
if: inputs.benchmark == 'ON' && github.event.pull_request.base.ref
uses: actions/cache@v4
with:
key: bench-${{ github.event.pull_request.base.ref }}
path: ./build/bench-${{ github.event.pull_request.base.ref }}.log
- name: "Benchmark"
if: inputs.benchmark == 'ON'
working-directory: ./build
run: |
export PATH=../deps/nats-server:../deps/nats-streaming-server:$PATH
export NATS_TEST_SERVER_VERSION="$(nats-server -v)"
flags=""
ctest -L 'bench' --timeout 600 -VV | tee bench.log
- name: "Checkout nats.c for ${{ github.event.pull_request.base.ref }}"
if: inputs.benchmark == 'ON' && github.event.pull_request.base.ref && steps.cache-base-bench.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
clean: false
- name: "Benchmark ${{ github.event.pull_request.base.ref }} for comparison"
if: inputs.benchmark == 'ON' && github.event.pull_request.base.ref && steps.cache-base-bench.outputs.cache-hit != 'true'
run: |
mkdir -p build
cd build
rm -rf CMakeFiles CMakeCache.txt
cmake .. ${{ steps.cmake-flags.outputs.flags }}
make rebuild_cache && make
export PATH=../deps/nats-server:../deps/nats-streaming-server:$PATH
export NATS_TEST_SERVER_VERSION="$(nats-server -v)"
flags=""
ctest -L 'bench' --timeout 600 -VV | tee bench-${{ github.event.pull_request.base.ref }}.log
- name: "Checkout HEAD ${{ github.event.pull_request.head.ref }}"
if: inputs.benchmark == 'ON' && github.event.pull_request.head.ref && steps.cache-base-bench.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
clean: false
- name: "Compare benchmark to ${{ github.event.pull_request.base.ref }}"
if: inputs.benchmark == 'ON' && github.event.pull_request.base.ref
run: |
cd build
go run ../test/diffstat_sub_async.go bench-${{ github.event.pull_request.base.ref }}.log bench.log