2020-11-06 17:46:25 +00:00
|
|
|
# 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:
|
2022-08-26 16:27:05 +00:00
|
|
|
workflow_dispatch: ~
|
|
|
|
pull_request: ~
|
2020-11-06 17:46:25 +00:00
|
|
|
push:
|
2020-12-03 19:31:33 +00:00
|
|
|
branches:
|
|
|
|
- master
|
2020-11-06 17:46:25 +00:00
|
|
|
|
2020-11-06 18:55:27 +00:00
|
|
|
env:
|
2020-12-03 17:45:07 +00:00
|
|
|
CACHE_VERSION: 1
|
2023-07-28 03:05:40 +00:00
|
|
|
DEFAULT_PYTHON: 3.8
|
2020-11-06 18:55:27 +00:00
|
|
|
|
2020-11-06 17:46:25 +00:00
|
|
|
jobs:
|
2020-11-17 19:50:13 +00:00
|
|
|
lint-flake8:
|
|
|
|
name: Check flake8
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2020-12-02 21:52:40 +00:00
|
|
|
- name: Check out code from Github
|
2023-09-17 20:58:55 +00:00
|
|
|
uses: actions/checkout@v4
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2020-12-02 17:21:59 +00:00
|
|
|
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
|
2020-12-03 16:29:13 +00:00
|
|
|
id: python
|
2023-12-22 21:23:00 +00:00
|
|
|
uses: actions/setup-python@v5
|
2020-11-17 19:50:13 +00:00
|
|
|
with:
|
|
|
|
python-version: ${{ env.DEFAULT_PYTHON }}
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2023-07-28 03:05:40 +00:00
|
|
|
- name: Restore Python ${{ steps.python.outputs.python-version }} virtual environment
|
2020-12-03 16:23:44 +00:00
|
|
|
id: cache-venv
|
2024-02-04 20:29:23 +00:00
|
|
|
uses: actions/cache@v4
|
2020-12-02 17:21:59 +00:00
|
|
|
with:
|
2020-12-03 16:23:44 +00:00
|
|
|
path: venv
|
|
|
|
key: >-
|
2020-12-03 17:08:48 +00:00
|
|
|
${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{
|
2020-12-03 16:23:44 +00:00
|
|
|
steps.python.outputs.python-version }}-${{
|
|
|
|
hashFiles('requirements_dev.txt') }}
|
2023-07-28 03:05:40 +00:00
|
|
|
restore-keys: >-
|
|
|
|
${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{
|
|
|
|
steps.python.outputs.python-version }}-
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2020-12-03 17:08:48 +00:00
|
|
|
- name: Create Python virtual environment
|
2020-12-03 16:23:44 +00:00
|
|
|
if: steps.cache-venv.outputs.cache-hit != 'true'
|
2020-11-17 19:50:13 +00:00
|
|
|
run: |
|
2020-12-03 17:03:01 +00:00
|
|
|
python -m venv venv
|
|
|
|
. venv/bin/activate
|
|
|
|
pip install -U pip
|
|
|
|
pip install -r requirements_dev.txt
|
|
|
|
pip install -e .
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2020-11-17 19:50:13 +00:00
|
|
|
- name: Lint with flake8
|
|
|
|
run: |
|
2020-12-03 16:43:24 +00:00
|
|
|
. venv/bin/activate
|
2020-11-17 19:50:13 +00:00
|
|
|
# stop the build if there are Python syntax errors or undefined names
|
2023-08-29 03:29:39 +00:00
|
|
|
echo "::group::flake8 pass 1"
|
|
|
|
flake8 --count --select=E9,F63,F7,F82 --show-source --statistics
|
|
|
|
echo "::endgroup::"
|
2020-11-17 19:50:13 +00:00
|
|
|
# The GitHub editor is 127 chars wide
|
2023-08-29 03:29:39 +00:00
|
|
|
echo "::group::flake8 pass 2"
|
|
|
|
flake8 --count --max-complexity=12 --max-line-length=127 --statistics
|
|
|
|
echo "::endgroup::"
|
2020-11-06 17:46:25 +00:00
|
|
|
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2020-12-02 20:42:51 +00:00
|
|
|
pytest:
|
2023-07-28 03:05:40 +00:00
|
|
|
name: pytest (${{ matrix.plex }})
|
2020-11-17 21:56:34 +00:00
|
|
|
needs: lint-flake8
|
2020-11-06 17:46:25 +00:00
|
|
|
runs-on: ubuntu-latest
|
2020-12-02 03:21:00 +00:00
|
|
|
env:
|
2020-12-02 21:52:40 +00:00
|
|
|
PLEXAPI_AUTH_SERVER_BASEURL: http://127.0.0.1:32400
|
2023-10-04 03:30:43 +00:00
|
|
|
PLEXAPI_PLEXAPI_TIMEOUT: "60"
|
2020-12-03 15:16:12 +00:00
|
|
|
PLEX_CONTAINER: plexinc/pms-docker
|
2020-12-02 21:52:40 +00:00
|
|
|
PLEX_CONTAINER_TAG: latest
|
2020-11-06 17:46:25 +00:00
|
|
|
strategy:
|
2020-12-02 20:42:51 +00:00
|
|
|
fail-fast: false
|
2020-12-04 03:05:06 +00:00
|
|
|
max-parallel: 3
|
2020-11-06 17:46:25 +00:00
|
|
|
matrix:
|
2020-12-02 20:42:51 +00:00
|
|
|
plex: ['unclaimed', 'claimed']
|
|
|
|
is-master:
|
|
|
|
- ${{ github.ref == 'refs/heads/master' }}
|
|
|
|
exclude:
|
|
|
|
- is-master: false
|
|
|
|
plex: claimed
|
2020-11-06 17:46:25 +00:00
|
|
|
steps:
|
2020-12-02 21:52:40 +00:00
|
|
|
- name: Check out code from Github
|
2023-09-17 20:58:55 +00:00
|
|
|
uses: actions/checkout@v4
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2023-07-28 03:05:40 +00:00
|
|
|
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
|
2020-12-03 16:23:44 +00:00
|
|
|
id: python
|
2023-12-22 21:23:00 +00:00
|
|
|
uses: actions/setup-python@v5
|
2020-11-06 17:46:25 +00:00
|
|
|
with:
|
2023-07-28 03:05:40 +00:00
|
|
|
python-version: ${{ env.DEFAULT_PYTHON }}
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2023-07-28 03:05:40 +00:00
|
|
|
- name: Restore Python ${{ steps.python.outputs.python-version }} virtual environment
|
2020-12-03 16:23:44 +00:00
|
|
|
id: cache-venv
|
2024-02-04 20:29:23 +00:00
|
|
|
uses: actions/cache@v4
|
2020-12-02 17:21:59 +00:00
|
|
|
with:
|
2020-12-03 16:23:44 +00:00
|
|
|
path: venv
|
|
|
|
key: >-
|
2020-12-03 17:08:48 +00:00
|
|
|
${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{
|
2020-12-03 16:23:44 +00:00
|
|
|
steps.python.outputs.python-version }}-${{
|
|
|
|
hashFiles('requirements_dev.txt') }}
|
2023-07-28 03:05:40 +00:00
|
|
|
restore-keys: >-
|
|
|
|
${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{
|
|
|
|
steps.python.outputs.python-version }}-
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2020-12-03 17:08:48 +00:00
|
|
|
- name: Create Python virtual environment
|
2020-12-03 16:23:44 +00:00
|
|
|
if: steps.cache-venv.outputs.cache-hit != 'true'
|
2020-11-06 17:46:25 +00:00
|
|
|
run: |
|
2020-12-03 17:03:01 +00:00
|
|
|
python -m venv venv
|
|
|
|
. venv/bin/activate
|
|
|
|
pip install -U pip
|
|
|
|
pip install -r requirements_dev.txt
|
|
|
|
pip install -e .
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2020-12-03 15:16:12 +00:00
|
|
|
- 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"
|
2022-11-09 02:01:42 +00:00
|
|
|
echo "digest=$digest" >> $GITHUB_OUTPUT
|
2020-12-03 15:16:12 +00:00
|
|
|
|
|
|
|
- name: Cache PMS Docker image
|
|
|
|
id: docker-cache
|
2024-02-04 20:29:23 +00:00
|
|
|
uses: actions/cache@v4
|
2020-12-03 15:16:12 +00:00
|
|
|
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
|
|
|
|
|
2020-12-02 20:42:51 +00:00
|
|
|
- name: Set Plex credentials
|
|
|
|
if: matrix.plex == 'claimed'
|
2020-11-06 17:46:25 +00:00
|
|
|
run: |
|
2020-12-04 17:37:19 +00:00
|
|
|
echo "PLEXAPI_AUTH_SERVER_TOKEN=${{ secrets.PLEXAPI_AUTH_SERVER_TOKEN }}" >> $GITHUB_ENV
|
2020-12-02 21:07:36 +00:00
|
|
|
|
|
|
|
- name: Bootstrap ${{ matrix.plex }} Plex server
|
2024-02-04 20:29:31 +00:00
|
|
|
uses: nick-fields/retry@v3.0.0
|
2023-09-17 21:45:24 +00:00
|
|
|
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)
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2020-12-02 20:42:51 +00:00
|
|
|
- name: Main tests with ${{ matrix.plex }} server
|
|
|
|
env:
|
|
|
|
TEST_ACCOUNT_ONCE: ${{ matrix.plex == 'unclaimed' }}
|
2020-12-02 03:21:00 +00:00
|
|
|
run: |
|
2020-12-03 16:43:24 +00:00
|
|
|
. venv/bin/activate
|
2020-11-17 20:40:45 +00:00
|
|
|
pytest \
|
|
|
|
-rxXs \
|
|
|
|
--ignore=tests/test_sync.py \
|
|
|
|
--tb=native \
|
|
|
|
--verbose \
|
|
|
|
--cov=plexapi \
|
|
|
|
tests
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2020-12-02 03:40:07 +00:00
|
|
|
- name: Unlink PMS from MyPlex account
|
2020-12-02 20:42:51 +00:00
|
|
|
if: matrix.plex == 'claimed' && always()
|
2020-12-03 16:43:24 +00:00
|
|
|
run: |
|
|
|
|
. venv/bin/activate
|
|
|
|
python -u tools/plex-teardowntest.py
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2020-12-02 03:21:00 +00:00
|
|
|
- name: Upload coverage artifact
|
2023-12-22 21:44:54 +00:00
|
|
|
uses: actions/upload-artifact@v4
|
2020-12-02 03:21:00 +00:00
|
|
|
with:
|
2023-07-28 03:05:40 +00:00
|
|
|
name: coverage-${{ matrix.plex }}-${{ steps.python.outputs.python-version }}
|
2020-12-02 03:21:00 +00:00
|
|
|
path: .coverage
|
|
|
|
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2020-12-02 03:21:00 +00:00
|
|
|
coverage:
|
2020-12-17 07:06:22 +00:00
|
|
|
name: Process test coverage (${{ matrix.plex }})
|
2020-12-02 03:21:00 +00:00
|
|
|
runs-on: ubuntu-latest
|
2020-12-02 20:42:51 +00:00
|
|
|
needs: pytest
|
2020-12-02 21:52:40 +00:00
|
|
|
if: always()
|
2020-12-17 07:06:22 +00:00
|
|
|
strategy:
|
|
|
|
matrix:
|
|
|
|
plex: ['unclaimed', 'claimed']
|
|
|
|
is-master:
|
|
|
|
- ${{ github.ref == 'refs/heads/master' }}
|
|
|
|
exclude:
|
|
|
|
- is-master: false
|
|
|
|
plex: claimed
|
2020-12-02 03:21:00 +00:00
|
|
|
steps:
|
2020-12-02 17:21:59 +00:00
|
|
|
- name: Check out code from GitHub
|
2023-09-17 20:58:55 +00:00
|
|
|
uses: actions/checkout@v4
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2020-12-02 17:21:59 +00:00
|
|
|
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
|
2020-12-03 16:23:44 +00:00
|
|
|
id: python
|
2023-12-22 21:23:00 +00:00
|
|
|
uses: actions/setup-python@v5
|
2020-12-02 17:21:59 +00:00
|
|
|
with:
|
|
|
|
python-version: ${{ env.DEFAULT_PYTHON }}
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2023-07-28 03:05:40 +00:00
|
|
|
- name: Restore Python ${{ steps.python.outputs.python-version }} virtual environment
|
2020-12-03 16:23:44 +00:00
|
|
|
id: cache-venv
|
2024-02-04 20:29:23 +00:00
|
|
|
uses: actions/cache@v4
|
2020-12-03 16:23:44 +00:00
|
|
|
with:
|
|
|
|
path: venv
|
|
|
|
key: >-
|
2023-07-28 03:05:40 +00:00
|
|
|
${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{
|
2020-12-03 16:23:44 +00:00
|
|
|
steps.python.outputs.python-version }}-${{
|
|
|
|
hashFiles('requirements_dev.txt') }}
|
2023-07-28 03:05:40 +00:00
|
|
|
restore-keys: >-
|
|
|
|
${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{
|
|
|
|
steps.python.outputs.python-version }}-
|
|
|
|
fail-on-cache-miss: true
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2020-12-02 17:21:59 +00:00
|
|
|
- name: Download all coverage artifacts
|
2023-12-22 21:45:07 +00:00
|
|
|
uses: actions/download-artifact@v4
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2020-12-17 07:06:22 +00:00
|
|
|
- name: Combine ${{ matrix.plex }} coverage results
|
2020-12-02 17:21:59 +00:00
|
|
|
run: |
|
2020-12-03 16:43:24 +00:00
|
|
|
. venv/bin/activate
|
2020-12-17 07:06:22 +00:00
|
|
|
coverage combine coverage-${{ matrix.plex }}*/.coverage*
|
2020-12-02 17:21:59 +00:00
|
|
|
coverage report --fail-under=50
|
|
|
|
coverage xml
|
2020-12-02 21:07:36 +00:00
|
|
|
|
2020-12-17 07:06:22 +00:00
|
|
|
- name: Upload ${{ matrix.plex }} coverage to Codecov
|
2024-03-31 16:31:10 +00:00
|
|
|
uses: codecov/codecov-action@v4
|
|
|
|
env:
|
|
|
|
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
2020-12-17 07:06:22 +00:00
|
|
|
with:
|
|
|
|
flags: ${{ matrix.plex }}
|