-
Notifications
You must be signed in to change notification settings - Fork 4
191 lines (186 loc) · 7.44 KB
/
main.yaml
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
name: CI Pipeline
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches:
- "**"
tags:
- "*.*.*"
paths:
- "**"
- "!docs/**"
- "!examples/**"
- "!interaction_experiments/**"
- "!k8s/**"
pull_request:
paths:
- "**"
- "!docs/**"
- "!examples/**"
- "!interaction_experiments/**"
- "!k8s/**"
env:
TERM: xterm
# enable Docker push only if the required secrets are defined
ENABLE_DOCKER_PUSH: ${{ secrets.DOCKERHUB_USER != null && secrets.DOCKERHUB_TOKEN != null }}
jobs:
# Verifies pep8, pyflakes and circular complexity
flake8:
name: Lint Python Code (Flake8) (python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- name: Set up Python v${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install flake8
run: pip install flake8
- name: Run checks
run: flake8 -v .
# Validate OpenAPI specs
openapi_specs:
name: Lint OpenAPI Specs (python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11"]
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- name: Set up Python v${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install OpenAPI Spec Validator
run: pip install openapi-spec-validator
- name: Run checks
run: openapi-spec-validator specs/api.yaml
build:
name: "Build, Test and Push Docker Image"
runs-on: ubuntu-latest
needs: [flake8, openapi_specs]
steps:
- name: "List Docker images"
run: "docker images"
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Generate certificates
run: make certs
# So now you can use Actions' own caching!
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: "Set software version"
run: |
git fetch --unshallow
sw_version=$(python3 -c 'import lifemonitor; print(lifemonitor.__version__)')
echo "Current Software Version: ${sw_version}"
echo "SOFTWARE_VERSION=${sw_version}" >> $GITHUB_ENV
echo "SOFTWARE_VERSION_AS_DOCKER_TAG=$( echo ${sw_version} | tr + _ )" >> $GITHUB_ENV
echo "USE_SOFTWARE_VERSION=$( if [[ $(git tag --points-at HEAD) ]]; then echo true; else echo false; fi )" >> $GITHUB_ENV
# Set Docker image
- name: Set Docker repository
run: |
echo "DOCKERHUB_REPO=$( if [[ -n "${{ secrets.DOCKERHUB_REPO }}" ]]; then
echo "${{ secrets.DOCKERHUB_REPO }}";
else echo "${{ github.repository_owner }}/lifemonitor"; fi )" >> $GITHUB_ENV
# Extract Docker metadata and set labels and tags
- name: Extract Docker metadata
id: docker_meta
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKERHUB_REPO }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,enable=${{env.USE_SOFTWARE_VERSION}},pattern={{version}}
type=semver,enable=${{env.USE_SOFTWARE_VERSION}},event=tag,pattern={{major}}.{{minor}}
type=semver,enable=${{env.USE_SOFTWARE_VERSION}},pattern={{major}}.{{minor}}.build${{ github.run_number }}
type=raw,event=tag,value=${{ env.SOFTWARE_VERSION_AS_DOCKER_TAG }}
type=raw,event=tag,value=${{ env.SOFTWARE_VERSION_AS_DOCKER_TAG}}.build${{ github.run_number }}
type=sha
labels: |
org.opencontainers.image.version=${{ env.SOFTWARE_VERSION }}.build${{ github.run_number }}
# Build and tag LifeMonitor Docker image
- name: Build Docker image
uses: docker/build-push-action@v3
with:
context: .
file: docker/lifemonitor.Dockerfile
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
load: true
build-args: |
SW_VERSION=${{ env.SOFTWARE_VERSION }}
BUILD_NUMBER=${{ github.run_number }}
- name: Update cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
# Setup testing environment
- name: Set up testing environment
# Tag the latest built image as `crs4/lifemonitor:latest`
# which is the default used by `make run-tests` to run tests
run: |
docker images ;
docker tag ${{ env.DOCKERHUB_REPO }}:${{ env.SOFTWARE_VERSION_AS_DOCKER_TAG }} crs4/lifemonitor:latest ;
docker images ;
SKIP_BUILD=1 SW_VERSION=${{ env.SOFTWARE_VERSION }} BUILD_NUMBER=${{ github.run_number }} make start-testing
env:
TRAVIS_TESTING_SERVICE_URL: ${{ secrets.TRAVIS_TESTING_SERVICE_URL }}
TRAVIS_TESTING_SERVICE_TOKEN: ${{ secrets.TRAVIS_TESTING_SERVICE_TOKEN }}
TRAVIS_TESTING_SERVICE_TYPE: travis
GH_TESTING_SERVICE_URL: ${{ secrets.GH_TESTING_SERVICE_URL }}
GH_TESTING_SERVICE_TOKEN: ${{ secrets.GH_TESTING_SERVICE_TOKEN }}
GH_TESTING_SERVICE_TYPE: github
# Run tests
- name: Run tests
run: SKIP_BUILD=1 SKIP_RESET_COMPOSE=1 SW_VERSION=${{ env.SOFTWARE_VERSION }} BUILD_NUMBER=${{ github.run_number }} make run-tests
env:
TRAVIS_TESTING_SERVICE_URL: ${{ secrets.TRAVIS_TESTING_SERVICE_URL }}
TRAVIS_TESTING_SERVICE_TOKEN: ${{ secrets.TRAVIS_TESTING_SERVICE_TOKEN }}
TRAVIS_TESTING_SERVICE_TYPE: travis
GH_TESTING_SERVICE_URL: ${{ secrets.GH_TESTING_SERVICE_URL }}
GH_TESTING_SERVICE_TOKEN: ${{ secrets.GH_TESTING_SERVICE_TOKEN }}
GH_TESTING_SERVICE_TYPE: github
# Teardown testing environment
- name: Teardown testing environment
run: make down
# Log in to DockerHub
- name: Login to Docker Hub
uses: docker/login-action@v2
if: ${{ env.ENABLE_DOCKER_PUSH == 'true' }}
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Push LifeMonitor Docker image
- name: Build and push
uses: docker/build-push-action@v3
if: ${{ env.ENABLE_DOCKER_PUSH == 'true' }}
with:
context: .
file: docker/lifemonitor.Dockerfile
platforms: linux/amd64
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
build-args: |
SW_VERSION=${{ env.SOFTWARE_VERSION }}
BUILD_NUMBER=${{ github.run_number }}