-
Notifications
You must be signed in to change notification settings - Fork 6
390 lines (314 loc) · 15.5 KB
/
ci-build-test-publish.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
name: ci-build-test-publish
on:
push:
branches: [dev, master]
pull_request:
branches: [dev, master]
workflow_dispatch:
env:
SECRET_GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
SECRET_RESULTS_SHEET_ID: ${{ secrets.RESULTS_SHEET_ID }}
jobs:
docker-buildx-test-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v2
- name: Set environment variables
shell: bash
run: |
GITHUB_COMMIT=`sed -n 's/.*NMOS_CPP_VERSION=\(.......\).*/\1/p' Dockerfile`
echo "GITHUB_COMMIT=$GITHUB_COMMIT" >> $GITHUB_ENV
GITHUB_BRANCH=`echo "${{ github.ref }}" | cut -d'/' -f3`
echo "GITHUB_BRANCH=$GITHUB_BRANCH" >> $GITHUB_ENV
echo "GITHUB_WORKSPACE=${{ github.workspace }}" >> $GITHUB_ENV
echo "RUNNER_WORKSPACE=${{ runner.workspace }}" >> $GITHUB_ENV
echo "BUILD_NAME=ubuntu-latest_avahi" >> $GITHUB_ENV
echo "TEST_FAIL=FALSE" >> $GITHUB_ENV
- name: Set docker image name
shell: bash
run: |
if [[ "${{ secrets.Docker_Image_Name }}" ]]; then
echo "DOCKER_IMAGE_NAME=${{ secrets.Docker_Image_Name }}" >> $GITHUB_ENV
else
echo "DOCKER_IMAGE_NAME=rhastie/nmos-cpp" >> $GITHUB_ENV
fi
- name: Set platforms and tags
shell: bash
run: |
if [[ "${{ secrets.BUILD_PLATFORMS }}" ]] && [[ "${{ env.GITHUB_BRANCH }}" == "master" ]]; then
echo "BUILD_PLATFORMS=${{ secrets.BUILD_PLATFORMS }}" >> $GITHUB_ENV
else
echo "BUILD_PLATFORMS=linux/amd64" >> $GITHUB_ENV
fi
if [[ "${{ secrets.PUSH_LATEST }}" == "TRUE" ]] && [[ "${{ env.GITHUB_BRANCH }}" == "master" ]]; then
echo "BUILD_TAGS=${{ env.GITHUB_BRANCH }}-${{ env.GITHUB_COMMIT }},latest" >> $GITHUB_ENV
else
echo "BUILD_TAGS=${{ env.GITHUB_BRANCH }}-${{ env.GITHUB_COMMIT }}" >> $GITHUB_ENV
fi
- name: Setup Google credentials
if: env.SECRET_GOOGLE_CREDENTIALS
shell: bash
working-directory: ${{ env.GITHUB_WORKSPACE }}
run: |
mkdir -p gdrive
echo "${{ env.SECRET_GOOGLE_CREDENTIALS }}" | openssl base64 -d -A -out gdrive/credentials.json
echo "GDRIVE_CREDENTIALS=`pwd`/gdrive/credentials.json" >> $GITHUB_ENV
- name: Get IP Host Address
run: |
hostip=$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
echo "HOST_IP_ADDRESS=$hostip" >> $GITHUB_ENV
echo "Using HOST IP Address: $hostip"
ip address
- name: Available Docker Buildx platforms
run: echo ${{ steps.buildx.outputs.platforms }}
- name: Docker Buildx and load x86 image to Docker images
uses: ilteoood/docker_buildx@master
with:
dockerfile: Dockerfile
publish: false
load: true
imageName: ${{ env.DOCKER_IMAGE_NAME }}
tag: ${{ env.GITHUB_BRANCH }}
buildArg: makemt=3
platform: linux/amd64
- name: List docker images
shell: bash
run: docker images
- name: Ubuntu avahi and mosquitto-clients setup
run: |
sudo apt-get update
sudo apt-get install -f libavahi-compat-libdnssd-dev mosquitto-clients
# make avahi only respond on the "eth0" interface
sudo sed -i 's/#*allow-interfaces=.*/allow-interfaces=eth0/g' /etc/avahi/avahi-daemon.conf
sudo systemctl restart avahi-daemon
- name: Install python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install pip
run: |
python -m pip install --upgrade pip
- name: Configure node.json and registry.json files for tests and .local mDNS domain
working-directory: ${{ env.RUNNER_WORKSPACE }}
run: |
echo "{\"pri\":0, \"http_port\":11000, \"how_many\":6, \"domain\":\"local.\", \"logging_level\":0}" > $(pwd)/node.json
echo "{\"pri\":0, \"http_port\":8010, \"domain\":\"local.\", \"logging_level\":0}" > $(pwd)/registry.json
cat $(pwd)/node.json $(pwd)/registry.json
- name: Remove IP Address from Docker0 to force AMWA Test Suite mDNS to use eth0
run: sudo ip address del 172.17.0.1/16 dev docker0 || echo "Docker IP Address del failed"
- name: Start Node Docker container for Node tests
working-directory: ${{ env.RUNNER_WORKSPACE }}
run: docker run -it -d --net=host --name nmos-cpp-node -v="$(pwd)/node.json:/home/node.json" -e "RUN_NODE=TRUE" ${{ env.DOCKER_IMAGE_NAME }}:${{ env.GITHUB_BRANCH }}
- name: Install AMWA Test suite
shell: bash
working-directory: ${{ env.RUNNER_WORKSPACE }}
run:
|
set -x
root_dir=`pwd`
# Install AMWA test suite.
git clone https://github.com/AMWA-TV/nmos-testing.git
cd nmos-testing
# Create output directories
mkdir results
mkdir badges
# run test suite directly
pip install wheel
pip install -r requirements.txt
# Install SDPoker
npm install -g git+https://git@github.com/AMWA-TV/sdpoker.git
pip install -r utilities/run-test-suites/gsheetsImport/requirements.txt
- name: Run AMWA Test suite against Node
shell: bash
working-directory: ${{ env.RUNNER_WORKSPACE }}
run:
|
set -x
root_dir=`pwd`
# Set AMWA Test suite runtime executable path
run_test="python nmos-test.py"
cd nmos-testing
function do_run_test() {
suite=$1
shift
case $($run_test suite ${suite} --selection all "$@" --output "results/${{ env.GITHUB_COMMIT }}-${{ env.BUILD_NAME }}-${{ env.GITHUB_BRANCH }}-${suite}.json" >> results/testoutput 2>&1; echo $?) in
[0-1]) echo "Pass" > badges/${suite}.txt ;;
*) echo "Fail" > badges/${suite}.txt; echo "TEST_FAIL=TRUE" >> $GITHUB_ENV ;;
esac
}
do_run_test IS-04-01 --host "${{ env.HOST_IP_ADDRESS }}" --port 11000 --version v1.3
do_run_test IS-04-03 --host "${{ env.HOST_IP_ADDRESS }}" --port 11000 --version v1.3
do_run_test IS-05-01 --host "${{ env.HOST_IP_ADDRESS }}" --port 11000 --version v1.1
do_run_test IS-05-02 --host "${{ env.HOST_IP_ADDRESS }}" "${{ env.HOST_IP_ADDRESS }}" --port 11000 11000 --version v1.3 v1.1
do_run_test IS-07-01 --host "${{ env.HOST_IP_ADDRESS }}" --port 11000 --version v1.0
do_run_test IS-07-02 --host "${{ env.HOST_IP_ADDRESS }}" "${{ env.HOST_IP_ADDRESS }}" "${{ env.HOST_IP_ADDRESS }}" --port 11000 11000 11000 --version v1.3 v1.1 v1.0
do_run_test IS-08-01 --host "${{ env.HOST_IP_ADDRESS }}" --port 11000 --version v1.0 --selector null
do_run_test IS-08-02 --host "${{ env.HOST_IP_ADDRESS }}" "${{ env.HOST_IP_ADDRESS }}" --port 11000 11000 --version v1.3 v1.0 --selector null null
do_run_test IS-09-02 --host "${{ env.HOST_IP_ADDRESS }}" null --port 0 0 --version null v1.0
echo ${{ env.TEST_FAIL }}
exit 0
- name: Start Registry Docker container and re-start Node Docker container for Registry tests
working-directory: ${{ env.RUNNER_WORKSPACE }}
run: |
docker container stop nmos-cpp-node
docker container rm nmos-cpp-node
docker run -it -d --net=host --name nmos-cpp-registry -v="$(pwd)/registry.json:/home/registry.json" -e "RUN_NODE=FALSE" ${{ env.DOCKER_IMAGE_NAME }}:${{ env.GITHUB_BRANCH }}
sleep 5
docker run -it -d --net=host --name nmos-cpp-node -v="$(pwd)/node.json:/home/node.json" -e "RUN_NODE=TRUE" ${{ env.DOCKER_IMAGE_NAME }}:${{ env.GITHUB_BRANCH }}
- name: Run AMWA Test suite against Registry
shell: bash
working-directory: ${{ env.RUNNER_WORKSPACE }}
run:
|
set -x
root_dir=`pwd`
# Set AMWA Test suite runtime executable path
run_test="python nmos-test.py"
cd nmos-testing
function do_run_test() {
suite=$1
shift
case $($run_test suite ${suite} --selection all "$@" --output "results/${{ env.GITHUB_COMMIT }}-${{ env.BUILD_NAME }}-${{ env.GITHUB_BRANCH }}-${suite}.json" >> results/testoutput 2>&1; echo $?) in
[0-1]) echo "Pass" > badges/${suite}.txt ;;
*) echo "Fail" > badges/${suite}.txt; echo "TEST_FAIL=TRUE" >> $GITHUB_ENV ;;
esac
}
# short delay to give the Registry a chance to start up and the Node a chance to register before running the Registry test suite
sleep 2
# add a persistent Query WebSocket API subscription before running the Registry test suite
curl "http://localhost:8010/x-nmos/query/v1.3/subscriptions" -H "Content-Type: application/json" -d "{\"max_update_rate_ms\": 100, \"resource_path\": \"/nodes\", \"params\": {\"label\": \"host1\"}, \"persist\": true, \"secure\": false}"
do_run_test IS-04-02 --host "${{ env.HOST_IP_ADDRESS }}" "${{ env.HOST_IP_ADDRESS }}" --port 8010 8010 --version v1.3 v1.3
do_run_test IS-09-01 --host "${{ env.HOST_IP_ADDRESS }}" --port 8010 --version v1.0
echo ${{ env.TEST_FAIL }}
exit 0
- name: Test MQTT Broker for basic connectivity and function
shell: bash
working-directory: ${{ env.RUNNER_WORKSPACE }}
run:
|
set -x
mqtt_error=FALSE
cd nmos-testing
# Start a subscriber, connect to MQTT Broker and listen on topic
mosquitto_sub -h "${{ env.HOST_IP_ADDRESS }}" -p 1883 -t test -C 1 > ./mqtt_pub_output &
if [ $? -ne 0 ]; then
mqtt_error=TRUE
fi
sleep 1
# Start a publisher, connect to MQTT Broker and post a message
mosquitto_pub -h "${{ env.HOST_IP_ADDRESS }}" -p 1883 -t test -m "Ping MQTT test"
if [ $? -ne 0 ]; then
mqtt_error=TRUE
fi
# Short delay to allow connections, transfer of message and closure of subscriber
sleep 1
sub_output=$(cat ./mqtt_pub_output)
rm ./mqtt_pub_output
#Check if we got the expected message from the subscriber
if [ "$sub_output" == 'Ping MQTT test' ] && [ "$mqtt_error" == 'FALSE' ]; then
echo "Passed MQTT Broker Test"
echo "Pass" > badges/MQTT-Broker.txt
else
echo "Failed MQTT Broker Test"
echo "Fail" > badges/MQTT-Broker.txt
fi
exit 0
- name: Stop Registry and Node containers
shell: bash
working-directory: ${{ env.RUNNER_WORKSPACE }}
run:
|
docker container stop nmos-cpp-registry
docker container stop nmos-cpp-node
docker container rm nmos-cpp-registry
docker container rm nmos-cpp-node
- name: Re-add IP address for Docker0 interface
run:
|
sudo ip address add 172.17.0.1/16 broadcast 172.17.255.255 dev docker0 || echo "Docker IP Address add failed"
ip address
- name: If Passes tests, Docker Buildx and publish x86 image to Docker Hub
if: env.TEST_FAIL == 'FALSE' && (env.GITHUB_BRANCH == 'master' || env.GITHUB_BRANCH == 'dev')
uses: ilteoood/docker_buildx@master
with:
dockerfile: Dockerfile
publish: true
load: false
imageName: ${{ env.DOCKER_IMAGE_NAME }}
tag: ${{ env.BUILD_TAGS }}
buildArg: makemt=3
platform: ${{ env.BUILD_PLATFORMS }}
dockerUser: ${{ secrets.DockerHub_User }}
dockerPassword: ${{ secrets.DockerHub_Password }}
- name: Upload results to google sheets
if: env.TEST_FAIL == 'FALSE' && (env.GITHUB_BRANCH == 'master' || env.GITHUB_BRANCH == 'dev')
working-directory: ${{ env.RUNNER_WORKSPACE }}
shell: bash
run: |
# Move to nmos-testing/results directory and operate relative to truncate "filenames in spreadsheet"
cd nmos-testing/results
export SHEET=https://docs.google.com/spreadsheets/d/${{ env.SECRET_RESULTS_SHEET_ID }}
python ../utilities/run-test-suites/gsheetsImport/resultsImporter.py --credentials ${{ env.GDRIVE_CREDENTIALS }} --sheet "$SHEET" --insert --json ${{ env.GITHUB_COMMIT }}-*.json || echo "upload failed"
# - name: If Passes tests and branch == master, update Docker Hub README file using GitHub README.md
# if: env.TEST_FAIL == 'FALSE' && env.GITHUB_BRANCH == 'master'
# uses: meeDamian/sync-readme@v1.0.6
# with:
# user: ${{ secrets.DockerHub_User }}
# pass: ${{ secrets.DockerHub_Password }}
# slug: ${{ env.DOCKER_IMAGE_NAME }}
- name: If Passes tests, build image file of x86 container
if: env.TEST_FAIL == 'FALSE'
working-directory: ${{ env.RUNNER_WORKSPACE }}
shell: bash
run: |
# Make directory and build image from container in Docker image repository
mkdir container-image
cd container-image
docker save ${{ env.DOCKER_IMAGE_NAME }}:${{ env.GITHUB_BRANCH }}| gzip > nmos-cpp_${{ env.GITHUB_BRANCH }}-${{ env.GITHUB_COMMIT }}.img.tar.gz
- name: If Passes tests, upload container image as an artifact
if: env.TEST_FAIL == 'FALSE'
uses: actions/upload-artifact@v2
with:
name: ${{ env.BUILD_NAME }}_container
path: ${{ runner.workspace }}/container-image/nmos-cpp_${{ env.GITHUB_BRANCH }}-${{ env.GITHUB_COMMIT }}.img.tar.gz
- name: Upload badges as artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ env.BUILD_NAME }}_badges
path: ${{ runner.workspace }}/nmos-testing/badges
- name: Upload results as artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ env.BUILD_NAME }}_results
path: ${{ runner.workspace }}/nmos-testing/results
make-badges:
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
needs: docker-buildx-test-publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: set environment variables
shell: bash
run: |
GITHUB_COMMIT=`echo "${{ github.sha }}" | cut -c1-7`
echo "GITHUB_COMMIT=$GITHUB_COMMIT" >> $GITHUB_ENV
echo "GITHUB_WORKSPACE=${{ github.workspace }}" >> $GITHUB_ENV
echo "RUNNER_WORKSPACE=${{ runner.workspace }}" >> $GITHUB_ENV
- uses: actions/download-artifact@v2
with:
path: ${{ runner.workspace }}/artifacts
- name: make badges
run: |
# combine badges from all builds
${{ github.workspace }}/.github/scripts/make_badges.sh ${{ github.workspace }} ${{ runner.workspace }}/artifacts
# force push to github onto an orphan 'badges' branch
cd ${{ github.workspace }}
git checkout --orphan badges-${{ env.GITHUB_COMMIT }}
git rm -rfq --ignore-unmatch .
git add *.svg
git remote set-url --push `git remote` https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/${{ github.repository }}
git config --global user.name 'test-results-uploader'
git config --global user.email 'test-results-uploader@nmos-cpp.iam.gserviceaccount.com'
git commit -qm "Badges for README at ${{ env.GITHUB_COMMIT }}"
git push -f `git remote` badges-${{ env.GITHUB_COMMIT }}:badges