-
Notifications
You must be signed in to change notification settings - Fork 198
263 lines (233 loc) · 8.27 KB
/
ci.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
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
# 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: CI
on:
workflow_dispatch: ~
pull_request: ~
push:
branches:
- master
env:
CACHE_VERSION: 1
DEFAULT_PYTHON: 3.8
jobs:
lint-flake8:
name: Check flake8
runs-on: ubuntu-latest
steps:
- name: Check out code from Github
uses: actions/checkout@v4
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore Python ${{ steps.python.outputs.python-version }} virtual environment
id: cache-venv
uses: actions/cache@v4
with:
path: venv
key: >-
${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{
steps.python.outputs.python-version }}-${{
hashFiles('requirements_dev.txt') }}
restore-keys: >-
${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{
steps.python.outputs.python-version }}-
- name: Create Python virtual environment
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
python -m venv venv
. venv/bin/activate
pip install -U pip
pip install -r requirements_dev.txt
pip install -e .
- name: Lint with flake8
run: |
. venv/bin/activate
# stop the build if there are Python syntax errors or undefined names
echo "::group::flake8 pass 1"
flake8 --count --select=E9,F63,F7,F82 --show-source --statistics
echo "::endgroup::"
# The GitHub editor is 127 chars wide
echo "::group::flake8 pass 2"
flake8 --count --max-complexity=12 --max-line-length=127 --statistics
echo "::endgroup::"
pytest:
name: pytest (${{ matrix.plex }})
needs: lint-flake8
runs-on: ubuntu-latest
env:
PLEXAPI_AUTH_SERVER_BASEURL: http://127.0.0.1:32400
PLEXAPI_PLEXAPI_TIMEOUT: "60"
PLEX_CONTAINER: plexinc/pms-docker
PLEX_CONTAINER_TAG: latest
strategy:
fail-fast: false
max-parallel: 3
matrix:
plex: ['unclaimed', 'claimed']
is-master:
- ${{ github.ref == 'refs/heads/master' }}
exclude:
- is-master: false
plex: claimed
steps:
- name: Check out code from Github
uses: actions/checkout@v4
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore Python ${{ steps.python.outputs.python-version }} virtual environment
id: cache-venv
uses: actions/cache@v4
with:
path: venv
key: >-
${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{
steps.python.outputs.python-version }}-${{
hashFiles('requirements_dev.txt') }}
restore-keys: >-
${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{
steps.python.outputs.python-version }}-
- name: Create Python virtual environment
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
python -m venv venv
. venv/bin/activate
pip install -U pip
pip install -r requirements_dev.txt
pip install -e .
- name: Get PMS Docker image digest
id: docker-digest
run: |
mkdir -p ~/.cache/docker/${{ env.PLEX_CONTAINER }}
echo "Image: ${{ env.PLEX_CONTAINER }}"
echo "Tag: ${{ env.PLEX_CONTAINER_TAG }}"
token=$(curl \
--silent \
"https://auth.docker.io/token?scope=repository:${{ env.PLEX_CONTAINER }}:pull&service=registry.docker.io" \
| jq -r '.token')
digest=$(curl \
--silent \
--header "Accept: application/vnd.docker.distribution.manifest.v2+json" \
--header "Authorization: Bearer $token" \
"https://registry-1.docker.io/v2/${{ env.PLEX_CONTAINER }}/manifests/${{ env.PLEX_CONTAINER_TAG }}" \
| jq -r '.config.digest')
echo "Digest: $digest"
echo "digest=$digest" >> $GITHUB_OUTPUT
- name: Cache PMS Docker image
id: docker-cache
uses: actions/cache@v4
with:
path: ~/.cache/docker/plexinc
key: ${{ runner.os }}-docker-pms-${{ steps.docker-digest.outputs.digest }}
- name: Pull PMS Docker image
if: steps.docker-cache.outputs.cache-hit != 'true'
run: |
docker pull ${{ env.PLEX_CONTAINER }}:${{ env.PLEX_CONTAINER_TAG }}
docker save -o ~/.cache/docker/${{ env.PLEX_CONTAINER }}-${{ env.PLEX_CONTAINER_TAG }}.tar ${{ env.PLEX_CONTAINER }}:${{ env.PLEX_CONTAINER_TAG }}
echo "Saved image: ${{ env.PLEX_CONTAINER }}:${{ env.PLEX_CONTAINER_TAG }}"
- name: Load PMS Docker image
if: steps.docker-cache.outputs.cache-hit == 'true'
run: |
docker load -i ~/.cache/docker/${{ env.PLEX_CONTAINER }}-${{ env.PLEX_CONTAINER_TAG }}.tar
- name: Set Plex credentials
if: matrix.plex == 'claimed'
run: |
echo "PLEXAPI_AUTH_SERVER_TOKEN=${{ secrets.PLEXAPI_AUTH_SERVER_TOKEN }}" >> $GITHUB_ENV
- name: Bootstrap ${{ matrix.plex }} Plex server
uses: nick-fields/retry@v3.0.0
with:
max_attempts: 3
timeout_minutes: 2
command: |
. venv/bin/activate
python \
-u tools/plex-bootstraptest.py \
--destination plex \
--advertise-ip 127.0.0.1 \
--bootstrap-timeout 540 \
--docker-tag ${{ env.PLEX_CONTAINER_TAG }} \
--${{ matrix.plex }}
on_retry_command: |
if ["${{ matrix.plex }}" == "claimed"]; then
python -u tools/plex-teardowntest.py
fi
# remove docker container
docker rm -f $(docker ps --latest)
- name: Main tests with ${{ matrix.plex }} server
env:
TEST_ACCOUNT_ONCE: ${{ matrix.plex == 'unclaimed' }}
id: test
run: |
. venv/bin/activate
pytest \
-rxXs \
--ignore=tests/test_sync.py \
--tb=native \
--verbose \
--color=yes \
--cov=plexapi \
tests
- name: Unlink PMS from MyPlex account
if: matrix.plex == 'claimed' && always()
run: |
. venv/bin/activate
python -u tools/plex-teardowntest.py
- name: Upload coverage artifact
if: always() && (steps.test.outcome == 'success' || steps.test.outcome == 'failure')
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.plex }}-${{ steps.python.outputs.python-version }}
path: .coverage
coverage:
name: Process test coverage (${{ matrix.plex }})
runs-on: ubuntu-latest
needs: pytest
if: always()
strategy:
matrix:
plex: ['unclaimed', 'claimed']
is-master:
- ${{ github.ref == 'refs/heads/master' }}
exclude:
- is-master: false
plex: claimed
steps:
- name: Check out code from GitHub
uses: actions/checkout@v4
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/setup-python@v5
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore Python ${{ steps.python.outputs.python-version }} virtual environment
id: cache-venv
uses: actions/cache@v4
with:
path: venv
key: >-
${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{
steps.python.outputs.python-version }}-${{
hashFiles('requirements_dev.txt') }}
restore-keys: >-
${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{
steps.python.outputs.python-version }}-
fail-on-cache-miss: true
- name: Download all coverage artifacts
uses: actions/download-artifact@v4
- name: Combine ${{ matrix.plex }} coverage results
run: |
. venv/bin/activate
coverage combine coverage-${{ matrix.plex }}*/.coverage*
coverage report --fail-under=50
coverage xml
- name: Upload ${{ matrix.plex }} coverage to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
flags: ${{ matrix.plex }}