-
Notifications
You must be signed in to change notification settings - Fork 1
277 lines (226 loc) · 7.44 KB
/
ci-cd.yml
File metadata and controls
277 lines (226 loc) · 7.44 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
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
name: CI/CD Pipeline
on:
push:
branches: [master, main, develop]
pull_request:
branches: [master, main, develop]
release:
types: [published]
workflow_dispatch:
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Install system dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y ffmpeg libsm6 libxext6 libxrender1 libglib2.0-0
sudo apt-get install -y cmake build-essential
- name: Install system dependencies (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install ffmpeg cmake
- name: Install system dependencies (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install ffmpeg cmake
- name: Install dependencies
run: |
uv sync --dev
- name: Lint with ruff
run: |
uv run ruff check src/videoannotator tests
- name: Check formatting with ruff
run: |
uv run ruff format --check src/videoannotator tests
- name: Type check with mypy
if: matrix.os == 'ubuntu-latest'
run: |
uv run mypy src/videoannotator
- name: Test with pytest
run: |
uv run pytest -q --cov=src/videoannotator --cov-report=xml --cov-report=term-missing --cov-fail-under=45
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
integration-test:
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake build-essential
sudo apt-get install -y ffmpeg libsm6 libxext6 libxrender1 libglib2.0-0
- name: Install dependencies
run: |
uv sync --dev
- name: Run integration tests
run: |
uv run pytest -q -m integration
- name: Test CLI interface
run: |
uv run videoannotator --help
uv run videoannotator server --help
performance-test:
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Set up uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y ffmpeg libsm6 libxext6 libxrender1 libglib2.0-0
sudo apt-get install -y cmake build-essential
- name: Install dependencies
run: |
uv sync --dev
- name: Run performance tests
run: |
uv run pytest -q -m performance --benchmark-only --benchmark-json=benchmark.json
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
name: Python Benchmark
tool: "pytest"
output-file-path: benchmark.json
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
paper:
runs-on: ubuntu-latest
name: Draft JOSS paper
steps:
- uses: actions/checkout@v4
- name: Build draft PDF
uses: openjournals/openjournals-draft-action@master
with:
journal: joss
paper-path: paper/paper.md
- name: Upload paper PDF
uses: actions/upload-artifact@v4
with:
name: paper
path: paper/paper.pdf
security-scan:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@0.28.0
with:
scan-type: "fs"
scan-ref: "."
format: "sarif"
output: "trivy-results.sarif"
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: "trivy-results.sarif"
build-and-publish:
runs-on: ubuntu-latest
needs: [test, integration-test]
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: |
python -m build
- name: Check package
run: |
twine check dist/*
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
docker-build:
runs-on: ubuntu-latest
needs: [test, integration-test]
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Check Docker Hub secrets
run: |
if [ -z "${{ secrets.DOCKER_USERNAME }}" ] || [ -z "${{ secrets.DOCKER_PASSWORD }}" ]; then
echo "Docker Hub credentials not configured; skipping docker push steps."
else
echo "Docker Hub credentials present."
fi
- name: Login to Docker Hub
if: ${{ env.DOCKER_USERNAME != '' && env.DOCKER_PASSWORD != '' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: videoannotator/videoannotator
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
if: ${{ env.DOCKER_USERNAME != '' && env.DOCKER_PASSWORD != '' }}
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max