-
Notifications
You must be signed in to change notification settings - Fork 10
351 lines (306 loc) · 11.6 KB
/
test-or-deploy.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
#-----------------------------------------------------------------------------
# Title : test-or-deploy
#-----------------------------------------------------------------------------
# File : test-or-deploy.yml
# Created : 2020-11-23
#-----------------------------------------------------------------------------
# Description:
# Test or deploy releases of pysmurf using GitHub Actions.
#-----------------------------------------------------------------------------
# This file is part of the smurf software platform. It is subject to
# the license terms in the LICENSE.txt file found in the top-level directory
# of this distribution and at:
# https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
# No part of the smurf software platform, including this file, may be
# copied, modified, propagated, or distributed except according to the terms
# contained in the LICENSE.txt file.
#-----------------------------------------------------------------------------
name: test-or-deploy
on: [push, pull_request]
jobs:
# Tests
# Run flake8 on all .py files. Should block deploys to Read The Docs.
flake8:
name: Flake8 Tests
runs-on: ubuntu-20.04
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v2
# Setup python3
- name: setup python 3.8.10
uses: actions/setup-python@v2
with:
python-version: 3.8.10
# Install flake8 modules
- name: Install dependencies
run: |
python -m pip install \
flake8-rst-docstrings \
flake8-sfs \
flake8-import-order
# Run Flake 8 tests
- name: Flake8
run: flake8 --count python/
# Validate the server docker image definitions
docker-definitions:
name: Docker Definition Tests
runs-on: ubuntu-20.04
steps:
# Checkout the code.
# We use ssh key authentication to be able to access other private
# repositories (like the firmware repository).
- name: Checkout code
uses: actions/checkout@v2
with:
ssh-key: ${{ secrets.SLACLAB_KEY }}
# Validate the server 'definitions.sh' file.
# Note about tokens: In this stage we need to use the SLACLAB TOKEN
# to be able to access the other private repositories (GITHUB_TOKEN
# only gives access to this repository).
- name: Validate the server definitions
shell: bash
env:
SWH76_TOKEN: ${{ secrets.SWH76_TOKEN }}
run: |
cd docker/server/
./validate.sh
cd -
# Documentation automatic build tests
test-docs:
name: Documentation Build Tests
runs-on: ubuntu-20.04
needs: [flake8, docker-definitions] # Run only if all checks passed
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v2
# Setup python 3.8.10
- name: Setup python 3.8.10
uses: actions/setup-python@v2
with:
python-version: 3.8.10
# Install requirements, pysmurf, and sphinx
- name: Install dependencies
run: |
python -m pip install -r requirements.txt
python -m pip install .
python -m pip install sphinx
# Try to build the documentation
- name: Build documentation
run: |
cd docs
make html
# Server tests
test-server:
name: Server Tests
runs-on: ubuntu-20.04
needs: [flake8, docker-definitions] # Run only if all checks passed
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v2
# Setup Docker build environment
- name: Set up docker build enviroment
uses: docker/setup-buildx-action@v1
# Extract the branch name.
# - For PR, the branch name is "github.head_ref"
# - For non-pull-request builds, the BRANCH_NAME env var will be empty.
# Extract it from GITHUB_REF in the format of refs/heads/<branch-name>
- name: Get branch name
id: branch_name
env:
BRANCH_NAME: ${{ github.head_ref }}
run: |
echo ::set-output name=branch::"${BRANCH_NAME:-$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { $1=$2=""; sub(" ",""); gsub(" ","/"); print }')}"
# Build docker image
- name: Build docker image
run: |
mkdir docker/server/local_files
docker image build \
--file ./docker/server/Dockerfile \
--build-arg branch=${{ steps.branch_name.outputs.branch }} \
--tag server_docker \
./docker/server
# Start the docker container
- name: Start docker container
run: |
docker container run -dti --rm --name server \
--entrypoint bash \
server_docker
# Run tests in the server docker container:
# - Try to import the smurf module in the server container
- name: Test importing the smurf module
run: |
docker container exec server \
/bin/bash -c "python3 -c 'import rogue; import smurf;'"
# - Try to instantiate the pysmurf's SmurfProcessor module in the server container
- name: Test instantiating the SmurfProcessor module
run: |
docker container exec server \
/bin/bash -c "python3 -c 'import pysmurf.core.devices; \
s = pysmurf.core.devices.SmurfProcessor(name=\"\", description=\"\")'"
# - Run the 'validate_filter.py' test script
- name: Validate the SmurfProcessor filter
run: |
docker container exec server \
/bin/bash -c "/usr/local/src/pysmurf/tests/core/validate_filter.py"
# - Run the 'validate_unwrapper.py' test script
- name: Validate the SmurfProcessor unwrapper
run: |
docker container exec server \
/bin/bash -c "/usr/local/src/pysmurf/tests/core/validate_unwrapper.py"
# - Run the 'validate_base_tx.py' test script
- name: Validate the SmurfProcessor base transmitter
run: |
docker container exec server \
/bin/bash -c "/usr/local/src/pysmurf/tests/core/validate_base_tx.py"
# Client tests
test-client:
name: Client Tests
runs-on: ubuntu-20.04
needs: [flake8, docker-definitions] # Run only if all checks passed
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v2
# Setup Docker build environment
- name: Set up docker build enviroment
uses: docker/setup-buildx-action@v1
# Extract the branch name.
# - For PR, the branch name is "github.head_ref"
# - For non-pull-request builds, the BRANCH_NAME env var will be empty.
# Extract it from GITHUB_REF in the format of refs/heads/<branch-name>
- name: Get branch name
id: branch_name
env:
BRANCH_NAME: ${{ github.head_ref }}
run: |
echo ::set-output name=branch::"${BRANCH_NAME:-$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { $1=$2=""; sub(" ",""); gsub(" ","/"); print }')}"
# Build docker image
- name: Build docker Image
run: |
docker image build \
--file ./docker/client/Dockerfile \
--build-arg branch=${{ steps.branch_name.outputs.branch }} \
--tag client_docker \
./docker/client
# Start the docker container
- name: Start docker container
run: |
docker container run -dti --rm --name client \
--entrypoint bash \
client_docker
# Test docker image
# - Try to import the pysmurf.client module in the client container
# Note: we need to disable the matplotlib graphics backend in order
# to be able to run in the runner.
- name: Test docker container
run: |
docker container exec client \
/bin/bash -c "python3 -c 'import matplotlib; matplotlib.use(\"Agg\"); import pysmurf.client'"
# Deploy
# Deploy new release notes to GitHub
deploy-release-notes:
name: Generate Release Notes
runs-on: ubuntu-20.04
needs: [test-docs, test-server, test-client] # Run only if all tests passed
if: startsWith(github.ref, 'refs/tags/') # Run only on tagged releases
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
# Get the git tag from the environmental variables
# It will used to tag the docker image
- name: Get release tag
id: get_tag
run: echo ::set-output name=tag::"${GITHUB_REF#refs/tags/}"
# Setup python3
- name: Setup python 3.8.10
uses: actions/setup-python@v2
with:
python-version: 3.8.10
# Install dependencies of the releaseGen.py script
- name: Install dependencies
run: |
python -m pip install \
GitPython \
PyGithub
# Generate a release using the releaseGen.py script
- name: Generate release notes
env:
REPO_SLUG: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.get_tag.outputs.tag }}
run: python releaseGen.py
# Server docker
deploy-server:
name: Build Server Docker Image
runs-on: ubuntu-20.04
needs: [test-docs, test-server, test-client] # Run only if all tests passed
if: startsWith(github.ref, 'refs/tags/') # Run only on tagged releases
steps:
# Checkout the code.
# We use ssh key authentication to be able to access other private
# repositories (like the firmware repository).
- name: Checkout code
uses: actions/checkout@v2
with:
ssh-key: ${{ secrets.SLACLAB_KEY }}
# Setup docker build environment
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# Login to Dockerhub
- name: Login to Dockerhub
uses: docker/login-action@v1
with:
username: tidair
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Build and push the docker image
# Note about tokens: In this stage we need to use the SLACLAB TOKEN
# to be able to access the other private repositories (GITHUB_TOKEN
# only gives access to this repository).
- name: Build and push image to Dockerhub
id: build
shell: bash
env:
SWH76_TOKEN: ${{ secrets.SWH76_TOKEN }}
run: |
cd docker/server/
./build.sh
cd -
# Client docker
deploy-client:
name: Build Client Docker Image
runs-on: ubuntu-20.04
needs: [test-docs, test-server, test-client] # Run only if all tests passed
if: startsWith(github.ref, 'refs/tags/') # Run only on tagged releases
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v2
# Get the git tag from the environmental variables
# It will used to tag the docker image
- name: Get release tag
id: get_tag
run: echo ::set-output name=tag::"${GITHUB_REF#refs/tags/}"
# Setup Docker build environment
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# Login to Dockerhub
- name: Login to Dockerhub
uses: docker/login-action@v1
with:
username: tidair
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Build and push the docker image
- name: Build and push image to Dockerhub
uses: docker/build-push-action@v2
with:
context: ./docker/client
file: ./docker/client/Dockerfile
push: true
tags: tidair/pysmurf-client:${{ steps.get_tag.outputs.tag }}
build-args: branch=${{ steps.get_tag.outputs.tag }}