forked from arnika-project/arnika
-
Notifications
You must be signed in to change notification settings - Fork 0
249 lines (213 loc) · 7.28 KB
/
Copy pathci.yml
File metadata and controls
249 lines (213 loc) · 7.28 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
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
# Supersede in-flight runs for the same PR, so a rapid second push does not
# queue behind the run it already obsoletes. Pushes to main are never
# cancelled: every commit there keeps its own result.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.11.3
args: --timeout=5m
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Download dependencies
run: go mod download
- name: Run tests
env:
GOEXPERIMENT: runtimesecret
run: go test -v ./...
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, darwin]
goarch: [amd64, arm64]
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Download dependencies
run: go mod download
- name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
GOEXPERIMENT: runtimesecret
run: |
go build ./...
writers:
name: Key writer builds
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Download dependencies
run: go mod download
- name: Build, vet and conflict-check every writer
env:
GOEXPERIMENT: runtimesecret
CGO_ENABLED: 0
run: |
set -euo pipefail
# "<build tag>:<space-separated supported GOOS values>"
# Adding a writer means adding one line here. See KEYCONTROL.md.
WRITERS=(
"wireguard_netlink:linux darwin"
"wireguard_mikrotik:linux darwin"
)
ALL_GOOS=(linux darwin)
TAGS=()
for entry in "${WRITERS[@]}" ; do TAGS+=("${entry%%:*}") ; done
echo "::group::Build each writer for its supported platforms"
for entry in "${WRITERS[@]}" ; do
tag="${entry%%:*}"
for goos in ${entry#*:} ; do
for goarch in amd64 arm64 ; do
echo "-> $tag $goos/$goarch"
GOOS="$goos" GOARCH="$goarch" go build -tags "$tag" -o /dev/null .
done
done
done
echo "::endgroup::"
echo "::group::Vet each writer"
for entry in "${WRITERS[@]}" ; do
tag="${entry%%:*}"
first_goos="$(echo "${entry#*:}" | awk '{print $1}')"
echo "-> $tag (GOOS=$first_goos)"
GOOS="$first_goos" go vet -tags "$tag" ./...
done
echo "::endgroup::"
echo "::group::Unsupported platforms must NOT build"
for entry in "${WRITERS[@]}" ; do
tag="${entry%%:*}"
supported=" ${entry#*:} "
for goos in "${ALL_GOOS[@]}" ; do
case "$supported" in *" $goos "*) continue ;; esac
if GOOS="$goos" GOARCH=arm64 go build -tags "$tag" -o /dev/null . 2>/dev/null ; then
echo "::error::$tag built for $goos, which it does not support - its platform constraint has been lost"
exit 1
fi
echo "-> $tag correctly refuses $goos"
done
done
echo "::endgroup::"
echo "::group::Two writer tags must never compile together"
for ((i = 0; i < ${#TAGS[@]}; i++)) ; do
for ((j = i + 1; j < ${#TAGS[@]}; j++)) ; do
pair="${TAGS[i]} ${TAGS[j]}"
if go build -tags "$pair" -o /dev/null . 2>/dev/null ; then
echo "::error::tags '$pair' built; expected duplicate getKeyWriterService"
exit 1
fi
echo "-> '$pair' correctly fails"
done
done
echo "::endgroup::"
integration-test:
name: Integration Test with Containerlab
runs-on: ubuntu-latest
needs: [build, test]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Built before the keys are generated, for two reasons: ci/setup-keys.sh
# borrows the `wg` binary from this image instead of installing
# wireguard-tools on the runner, and keeping the freshly generated keys
# out of the build context stops them invalidating the COPY layer.
- name: Build Arnika node image
uses: docker/build-push-action@v6
with:
context: .
file: ci/Dockerfile.node
tags: arnika-node:ci
load: true
cache-from: type=gha,scope=arnika-node
cache-to: type=gha,mode=max,scope=arnika-node
- name: Build QKD simulator image
uses: docker/build-push-action@v6
with:
context: .
file: ci/Dockerfile.simulator
tags: qkd-simulator:ci
load: true
cache-from: type=gha,scope=qkd-simulator
cache-to: type=gha,mode=max,scope=qkd-simulator
- name: Generate WireGuard keys
run: |
chmod +x ci/setup-keys.sh
./ci/setup-keys.sh
- name: Install Containerlab
run: |
bash -c "$(curl -sL https://get.containerlab.dev)"
- name: Deploy containerlab topology
run: |
sudo containerlab deploy -t ci/clab-ci.yaml
- name: Start QKD simulator
run: |
docker exec clab-arnika-ci-test-qkd-simulator /usr/local/bin/qkd-simulator &
sleep 5
- name: Start node-a
run: |
docker exec clab-arnika-ci-test-node-a /bin/bash /etc/arnika/start.sh
- name: Start node-b
run: |
docker exec clab-arnika-ci-test-node-b /bin/bash /etc/arnika/start.sh
# ci/verify-keys.sh polls for convergence itself, so there is no separate
# fixed wait here any more.
- name: Verify key injection
run: |
chmod +x ci/verify-keys.sh
./ci/verify-keys.sh
- name: Collect logs on failure
if: failure()
run: |
echo "====== QKD Simulator Logs ======"
docker logs clab-arnika-ci-test-qkd-simulator || true
echo "====== Node-A Logs ======"
docker exec clab-arnika-ci-test-node-a cat /tmp/arnika.log || true
echo "====== Node-B Logs ======"
docker exec clab-arnika-ci-test-node-b cat /tmp/arnika.log || true
- name: Cleanup containerlab
if: always()
run: |
sudo containerlab destroy -t ci/clab-ci.yaml --cleanup