-
-
Notifications
You must be signed in to change notification settings - Fork 84
340 lines (293 loc) · 10.5 KB
/
integration_test_and_build_all_packages_ci.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
name: Build All Packages CI
on:
push:
branches: [ 'dev-**', 'pr-**', staging, master ]
tags: [ '**' ]
pull_request:
branches: [ staging, master ]
schedule:
# At 02:30 on Saturday
- cron: '30 2 * * 6'
jobs:
integration_tests:
name: Run integration tests
runs-on: ubuntu-latest
steps:
# Fetch shallow git repository
- uses: actions/checkout@v4
# Restore test video's cache
- name: Restore test videos cache
uses: actions/cache@v4
id: test_videos_cache
with:
path: tests/support_/videos
key: ${{ runner.os }}-test_videos-${{ hashFiles('tests/scripts_/download_test_files.sh') }}
restore-keys: |
${{ runner.os }}-test_videos-
# Download any missing test videos
- name: Download any missing test videos
if: success() && steps.test_videos_cache.outputs.cache-hit != 'true'
run: |
bash -c "tests/scripts_/download_test_files.sh"
# Setup python environment
- name: Set up Python 3.8
uses: actions/setup-python@v5
with:
python-version: '3.8'
# Restore the python cache if it exists
- name: Restore python cache
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
# Restore the apt cache if it exists
# TODO: Fix this cache. Its not really working at all. It would be nice to have tho.
- name: Restore python cache
id: apt-cache
uses: actions/cache@v4
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-cache
# Download FFMPEG
- name: Download FFMPEG
if: success()
run: |
[[ ! -z `sudo find /var/cache/apt/archives -type f -name "ffmpeg*.deb"` ]] && echo "no update" || sudo apt-get update
sudo apt-get install -yq --no-install-recommends --download-only ffmpeg
# Install FFMPEG
- name: Install FFMPEG
if: success()
run: |
sudo apt-get install -yq --no-install-recommends ffmpeg
# Install python dependencies for testing unmanic
- name: Install python dependencies
if: success()
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
# Run pytest unit tests
- name: Test with pytest
if: success()
run: |
echo "Using test videos:"
ls -l ./tests/support_/videos/*/
pytest -m integrationtest
py_build:
name: Build Python package
needs: integration_tests
runs-on: ubuntu-latest
steps:
# Fetch full git repository and all submodules
- name: Checkout project
uses: actions/checkout@v4
with:
submodules: 'recursive'
# Checkout tags
- name: Fetch tags
run: |
git fetch --prune --unshallow --tags
echo exit code $?
git tag --list
# Setup python environment
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.10'
# Restore the python cache if it exists
- name: Restore python cache
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
# Install python dependencies for building unmanic
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
# Setup node environment for building unmanic's webui
- uses: actions/setup-node@v4
with:
node-version: '20'
# Build python dist package
- name: Build python dist package
id: build_py
run: |
echo "Short version:"
python ./setup.py --quiet --version
echo "Long version:"
python ./setup.py --quiet fullversion
REPO_URL="https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_REF#refs/heads}/"
sed -i "s|(./docs/|(${REPO_URL:?}/docs/|g" README.md
python -m build --no-isolation --skip-dependency-check --wheel
python -m build --no-isolation --skip-dependency-check --sdist
# Read the python package distribution data (save version to file)
- name: Read python package distribution data
id: py_build_data
run: |
PY_VERSION=$(python ./setup.py --quiet --version)
PY_BDIST_PATH=$(ls dist/*.whl | head -n1)
PY_BDIST_FILE=${PY_BDIST_PATH#*/}
echo "py_version=${PY_VERSION}" >> $GITHUB_OUTPUT
echo "py_bdist_file=${PY_BDIST_FILE}" >> $GITHUB_OUTPUT
echo "py_bdist_path=${PY_BDIST_PATH}" >> $GITHUB_OUTPUT
echo ${PY_VERSION} > dist/VERSION.txt
# Upload python package distribution data artifact
- uses: actions/upload-artifact@v4
with:
name: unmanic-py-dist-data-${{ steps.py_build_data.outputs.py_version }}
path: dist/
build_docker:
name: Build Docker Image
needs: py_build
runs-on: ubuntu-latest
steps:
# Fetch shallow git repository
- name: Checkout
uses: actions/checkout@v4
# Fetch all artifacts
- name: Download Artifact
uses: actions/download-artifact@v4
with:
path: ./artifacts/
# Restore python package distribution data
- name: Restore python package distribution data
id: py_build_data
run: |
mkdir -p ./dist
find ./artifacts/ -type f -name "*.whl" -exec cp -n {} ./dist/ \;
find ./artifacts/ -type f -name "VERSION.txt" -exec cp -n {} ./dist/ \;
ls -l ./dist/
PY_VERSION=$(cat ./dist/VERSION.txt)
echo "py_version=${PY_VERSION}" >> $GITHUB_OUTPUT
# Use QEMU to build for other arch
- name: Set up QEMU
if: success()
id: qemu
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:latest
platforms: all
# Use configure docker to use buildx to build the image
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
if: success()
id: buildx
with:
version: latest
# List available build platforms
- name: Available platforms
if: success()
run: echo ${{ steps.buildx.outputs.platforms }}
# Generate 'prepare' build arguments to be retrieved later on
- name: Prepare
if: success()
id: prepare
run: |
echo "GITHUB_REF:${GITHUB_REF}"
echo "GITHUB_REPOSITORY:${GITHUB_REPOSITORY}"
DOCKER_IMAGE=docker.io/josh5/unmanic
VERSION_TAG=${GITHUB_REF#refs/*/}
DOCKER_TAGS=""
if [[ ${VERSION_TAG%/merge} == 'master' ]]; then
DOCKER_TAGS="${DOCKER_TAGS}${DOCKER_IMAGE}:latest,"
elif [[ ${VERSION_TAG%/merge} == 'staging' ]]; then
DOCKER_TAGS="${DOCKER_TAGS}${DOCKER_IMAGE}:staging,"
elif [[ ${VERSION_TAG%/merge} =~ "dev-"* ]]; then
DOCKER_TAGS="${DOCKER_TAGS}${DOCKER_IMAGE}:${VERSION_TAG%/merge},"
fi
if [[ ${GITHUB_REF} == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
if [[ ${VERSION} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}[-\w]*$ ]]; then
DOCKER_TAGS="${DOCKER_TAGS}${DOCKER_IMAGE}:${VERSION},"
DOCKER_TAGS="${DOCKER_TAGS}${DOCKER_IMAGE}:latest,"
fi
fi
DOCKER_PUSH="true"
if [[ ${DOCKER_IMAGE} != 'docker.io/josh5/unmanic' ]]; then
DOCKER_PUSH="false"
fi
if [[ ${VERSION_TAG%/merge} =~ "pr-"* ]]; then
DOCKER_PUSH="false"
fi
if [[ ${VERSION_TAG%/merge} =~ ^[0-9]+$ ]]; then
DOCKER_PUSH="false"
fi
echo "docker_image=${DOCKER_IMAGE}" >> $GITHUB_OUTPUT
echo "docker_tags=$(echo ${DOCKER_TAGS} | sed 's/,$//')" >> $GITHUB_OUTPUT
echo "docker_platforms=linux/amd64,linux/arm64" >> $GITHUB_OUTPUT
echo "docker_push=${DOCKER_PUSH}" >> $GITHUB_OUTPUT
# Cache the build
- name: Cache Docker layers
uses: actions/cache@v4
id: cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
# Login to Docker Hub
- name: Login to Docker Hub
if: success() && (startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/'))
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Run docker build and push
- name: Docker Build and Push
if: success()
uses: docker/build-push-action@v3
with:
context: .
file: docker/Dockerfile
platforms: ${{ steps.prepare.outputs.docker_platforms }}
pull: true
push: ${{ steps.prepare.outputs.docker_push }}
tags: |
${{ steps.prepare.outputs.docker_tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
# Keep only latest cache
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
if: always()
run: |
if [[ -e /tmp/.buildx-cache-new ]]; then
echo "Cleaning up old cache..."
rm -rf /tmp/.buildx-cache
mv -v /tmp/.buildx-cache-new /tmp/.buildx-cache
fi
build_pypi:
name: Publish package to PyPI
needs: py_build
runs-on: ubuntu-latest
if: github.event_name != 'schedule'
steps:
# Fetch shallow git repository
- name: Checkout
uses: actions/checkout@v4
# Fetch all artifacts
- name: Download Artifact
uses: actions/download-artifact@v4
with:
path: ./artifacts/
# Restore python package distribution data
- name: Restore python package distribution data
id: py_build_data
run: |
mkdir -p ./dist
find ./artifacts/ -type f -name "*.whl" -exec cp -n {} ./dist/ \;
find ./artifacts/ -type f -name "*.tar.gz" -exec cp -n {} ./dist/ \;
ls -l ./dist/
# Push the artifacts to PyPI repo
- name: Publish distribution package to PyPI
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_TOKEN }}