-
-
Notifications
You must be signed in to change notification settings - Fork 41
187 lines (162 loc) · 5.65 KB
/
python-tests.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
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python tests
on:
push:
# branches: [ "main" ]
pull_request:
branches: [ "main", "dev" ]
permissions:
contents: read
# To cancel a currently running workflow from the same PR, branch or tag when a new workflow is triggered you can use:
# Taken from https://stackoverflow.com/a/72408109
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
working-directory: ./hikvision-doorbell
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
working-directory: ./hikvision-doorbell
- name: Test with pytest
run: |
pytest
working-directory: ./hikvision-doorbell
docker-image_amd64:
needs: test
name: Docker image (amd64)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and export
uses: docker/build-push-action@v4
with:
context: ./hikvision-doorbell
file: ./hikvision-doorbell/Dockerfile
build-args: |
BUILD_ARCH=amd64
push: false
outputs: |
type=docker,dest=/tmp/image.tar
platforms: linux/amd64
tags: hikvision-doorbell:latest
- name: Upload image
uses: actions/upload-artifact@v3
with:
name: image amd64
path: /tmp/image.tar
retention-days: 1
docker-image_aarch64:
needs: test
name: Docker image (aarch64)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and export
uses: docker/build-push-action@v4
with:
context: ./hikvision-doorbell
file: ./hikvision-doorbell/Dockerfile
build-args: |
BUILD_ARCH=aarch64
push: false
outputs: |
type=docker,dest=/tmp/image.tar
platforms: linux/arm64
tags: hikvision-doorbell:latest
- name: Upload image
uses: actions/upload-artifact@v3
with:
name: image aarch64
path: /tmp/image.tar
retention-days: 1
test-image-amd64:
runs-on: ubuntu-latest
needs: docker-image_amd64
name: Test image (amd64)
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: image amd64
path: /tmp
- name: Load image
run: |
docker load --input /tmp/image.tar
docker image ls -a
- name: Test image
env:
SYSTEM__LOG_LEVEL: DEBUG
SYSTEM__SDK_LOG_LEVEL: DEBUG
run: |
echo -n "" | docker run -i -e SYSTEM__LOG_LEVEL -e SYSTEM__SDK_LOG_LEVEL hikvision-doorbell:latest
test-image-aarch64:
runs-on: ubuntu-latest
needs: docker-image_aarch64
name: Test image (aarch64)
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: image aarch64
path: "artifacts/"
- uses: uraimo/run-on-arch-action@v2
name: Run aarch64 commands
id: runcmd
with:
arch: aarch64
distro: ubuntu22.04
# Create an artifacts directory
setup: |
mkdir -p "${PWD}/artifacts"
# Mount the artifacts directory as /artifacts in the container
dockerRunArgs: |
--volume "${PWD}/artifacts:/artifacts"
env: |
SYSTEM__LOG_LEVEL: DEBUG
SYSTEM__SDK_LOG_LEVEL: DEBUG
install: |
# Setup Docker APT repository
apt-get update -q -y
apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release
mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list
apt-get update -q -y
apt-get install -y docker-ce docker-ce-cli containerd.io
run: |
docker load --input /artifacts/image.tar
docker image ls -a
echo "Loaded image.tar"
echo -n "" | docker run -i -e SYSTEM__LOG_LEVEL -e SYSTEM__SDK_LOG_LEVEL hikvision-doorbell:latest