-
-
Notifications
You must be signed in to change notification settings - Fork 601
266 lines (260 loc) · 9.95 KB
/
pythonpackage.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
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Python Packaging
on:
push:
branches:
- master
- develop
- test-deploy
tags:
- "20*"
pull_request:
branches:
- develop
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: false
env:
SLEEP: 60
DOCKER_BUILDKIT: '1'
DOCKER_TEST_TAG: sickchill/sickchill:test
DOCKER_CONTAINER_NAME: sickchill_test
TARGET_PLATFORMS: "linux/amd64,linux/arm64"
CRYPTOGRAPHY_DONT_BUILD_RUST: 1
PYTHON_TEST_VERSION: "3.11"
defaults:
run:
shell: bash
jobs:
Environment:
runs-on: ubuntu-latest
outputs:
docker_tags: ${{ steps.docker.outputs.tags }}
docker_labels: ${{ steps.docker.outputs.labels }}
steps:
- name: Cache environment files
uses: actions/cache@v4
with:
path: /tmp/buildkitd.toml
key: ${{ github.workflow }}-environment
- name: Create buildkitd config
run: |
echo 'experimantal = true' > /tmp/buildkitd.toml
echo 'debug = true' >> /tmp/buildkitd.toml
echo 'insecure-entitlements = [ "security.insecure" ]' >> /tmp/buildkitd.toml
# echo '[worker.oci]' >> /tmp/buildkitd.toml
# echo 'max-parallelism = 1' >> /tmp/buildkitd.toml
cat /tmp/buildkitd.toml
- name: Docker meta
id: docker
uses: docker/metadata-action@v5
with:
images: |
${{ github.repository }}
ghcr.io/${{ github.repository }}
labels: |
org.opencontainers.image.source=https://github.com/sickchill/sickchill
org.opencontainers.image.url=https://sickchill.github.io
org.opencontainers.image.licenses=GPL-3.0+
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,prefix=${{ github.ref_name }},suffix=,value=${{ github.run_id }},event=push
type=raw,prefix=${{ github.ref_name }},suffix=,value=${{ github.sha }},event=push
type=raw,prefix=,suffix=,value=${{ github.head_ref }},event=pr
type=raw,prefix=,suffix=,value=${{ github.ref_name }},event=push,enable=${{ github.event_name != 'pull_request' }}
type=edge,branch=develop
type=semver,pattern={{version}},enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
type=semver,pattern={{major}}.{{minor}},enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
Test:
strategy:
matrix:
os: [ ubuntu-latest ]
python-version: [ 3.8, 3.9, "3.10", "3.11" ]
experimental: [ false ]
include:
- os: windows-latest
python-version: "3.11"
experimental: false
- os: macos-latest
python-version: "3.11"
experimental: false
fail-fast: true
continue-on-error: ${{ matrix.experimental }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
persist-credentials: false
- if: success() && startsWith(runner.os, 'Linux') && matrix.python-version == env.PYTHON_TEST_VERSION
name: Lint shell scripts
uses: ludeeus/action-shellcheck@master
with:
format: diff
- name: Setup Poetry
uses: 5yutan5/setup-poetry-env@v1.1.0
with:
python-version: ${{ matrix.python-version }}
python-cache-dependency-path: pyproject.toml
- if: success() && startsWith(runner.os, 'Linux') && matrix.python-version == env.PYTHON_TEST_VERSION
name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'yarn'
- if: success() && startsWith(runner.os, 'Linux') && matrix.python-version == env.PYTHON_TEST_VERSION
name: Install yarn
run: npm install -g yarn
- name: Install python dependency tools
run: |
poetry run pip install --upgrade setuptools wheel
poetry run pip install --upgrade pytest-github-actions-annotate-failures
- name: Output tooling environment information
run: |
echo -e "$(poetry --version --ansi) is at $(which poetry)\n$(poetry env info --ansi)\n\v$(poetry --ansi run pip -V)"
- name: Install sickchill
run: |
poetry install --no-interaction --with dev --with speedups
- if: success() && startsWith(runner.os, 'Linux') && matrix.python-version == env.PYTHON_TEST_VERSION
name: Run yarn
run: poetry run poe yarn
- if: success() && startsWith(runner.os, 'Linux') && matrix.python-version == env.PYTHON_TEST_VERSION
name: Lint Python
run: poetry run poe lint
- if: success() && startsWith(runner.os, 'Linux') && matrix.python-version == env.PYTHON_TEST_VERSION
name: Lint and test Javascript
run: poetry run poe yarn test
- name: Test Python
run: poetry run poe pytest
- if: github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'
name: Coverage
run: poetry run poe codecov --env OS=${{ runner.os }} Interpreter="$(poetry run python -V)" -t ${{ secrets.CODECOV_TOKEN }}
Test-Docker:
needs: [ Environment, Test ]
runs-on: ubuntu-22.04
steps:
- name: Restore environment files
uses: actions/cache@v4
with:
path: /tmp/buildkitd.toml
key: ${{ github.workflow }}-environment
restore-keys: ${{ github.workflow }}-environment
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config: /tmp/buildkitd.toml
- name: Test Docker Build
uses: docker/build-push-action@v5
with:
platforms: linux/amd64
push: false
tags: ${{ env.DOCKER_TEST_TAG }}
load: true
labels: ${{ needs.Environment.outputs.docker_labels }}
target: sickchill-final
cache-from: type=gha
build-args: |
SOURCE=1
allow: |
security.insecure
- name: Test Docker Image
run: |
docker run -d --rm -p 8081:8081 --name ${{ env.DOCKER_CONTAINER_NAME }} ${{ env.DOCKER_TEST_TAG }}
echo "Waiting ${{ env.SLEEP }} seconds for the container to start..." && sleep ${{ env.SLEEP }}
echo "Checking if container is alive..."
[ $(curl http://localhost:8081/ui/get_messages -s) == "{}" ] && echo "Success!" || (echo "Failed" && exit 1)
echo "Checking if we have a working home page..."
$(curl http://localhost:8081/home/ -s | grep -q "site-notification-modal") && echo "Success!" || (echo "Failed" && exit 1)
echo "Stopping and removing container..."
docker stop ${{ env.DOCKER_CONTAINER_NAME }}
Deploy:
needs: [ Environment, Test, Test-Docker ]
runs-on: ubuntu-22.04
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Cache environment files
uses: actions/cache@v4
with:
path: /tmp/buildkitd.toml
key: ${{ github.workflow }}-environment
restore-keys: ${{ github.workflow }}-environment
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config: /tmp/buildkitd.toml
- if: success() && !env.ACT
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- if: success() && !env.ACT
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.GITHUB_TOKEN }}
- if: success()
name: Build and Push
uses: docker/build-push-action@v5
with:
platforms: ${{ env.TARGET_PLATFORMS }}
push: ${{ github.event_name != 'pull_request' && !env.ACT }}
tags: ${{ needs.Environment.outputs.docker_tags }}
labels: ${{ needs.Environment.outputs.docker_labels }}
target: sickchill-final
cache-to: type=gha,mode=max
cache-from: type=gha
build-args: |
SOURCE=1
allow: |
security.insecure
- if: success()
name: Snag wheels
uses: docker/build-push-action@v5
with:
file: Dockerfile
platforms: ${{ env.TARGET_PLATFORMS }}
push: false
outputs: type=local,dest=/tmp/sickchill-wheels
target: sickchill-wheels
cache-from: type=gha
build-args: |
SOURCE=1
allow: |
security.insecure
- if: success()
name: List wheels directory
run: |
ls -R /tmp/sickchill-wheels
- name: Upload linux/amd64 wheels
uses: actions/upload-artifact@v4
with:
name: amd64
path: /tmp/sickchill-wheels/linux_amd64
- name: Upload linux/arm64 wheels
uses: actions/upload-artifact@v4
with:
name: arm64
path: /tmp/sickchill-wheels/linux_arm64
- name: Upload linux/arm/v7 wheels
uses: actions/upload-artifact@v4
with:
name: armv7
path: /tmp/sickchill-wheels/linux_arm_v7
complete:
name: Packaging tests completed
runs-on: [ ubuntu-latest ]
needs: [ Environment, Test, Test-Docker, Deploy ]
steps:
- run: echo "Success!"