Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
ci(tests): bootstrap plex server (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored Sep 22, 2023
1 parent 66215e8 commit aacfbe9
Show file tree
Hide file tree
Showing 24 changed files with 1,441 additions and 74 deletions.
164 changes: 143 additions & 21 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
uses: LizardByte/.github/actions/setup_python2@nightly

- name: Set up Python 2.7 Dependencies
shell: bash
working-directory: Themerr-plex.bundle
run: |
echo "Installing Requirements"
Expand All @@ -66,35 +67,15 @@ jobs:
mv ./node_modules ./Contents/Resources/web
- name: Build plist
shell: bash
working-directory: Themerr-plex.bundle
env:
BUILD_VERSION: ${{ needs.check_changelog.outputs.next_version }}
run: |
python ./scripts/build_plist.py
- name: Upload Artifacts
if: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
uses: actions/upload-artifact@v3
with:
name: Themerr-plex.bundle
if-no-files-found: error # 'warn' or 'ignore' are also available, defaults to `warn`
path: |
${{ github.workspace }}
!**/*.git*
!**/*.pyc
!**/__pycache__
!**/plexhints*
!**/Themerr-plex.bundle/.*
!**/Themerr-plex.bundle/cache.sqlite
!**/Themerr-plex.bundle/DOCKER_README.md
!**/Themerr-plex.bundle/Dockerfile
!**/Themerr-plex.bundle/docs
!**/Themerr-plex.bundle/scripts
!**/Themerr-plex.bundle/tests
- name: Package Release
shell: bash
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
run: |
7z \
"-xr!*.git*" \
Expand All @@ -103,6 +84,7 @@ jobs:
"-xr!plexhints*" \
"-xr!Themerr-plex.bundle/.*" \
"-xr!Themerr-plex.bundle/cache.sqlite" \
"-xr!Themerr-plex.bundle/crowdin.yml" \
"-xr!Themerr-plex.bundle/DOCKER_README.md" \
"-xr!Themerr-plex.bundle/Dockerfile" \
"-xr!Themerr-plex.bundle/docs" \
Expand All @@ -113,6 +95,14 @@ jobs:
mkdir artifacts
mv ./Themerr-plex.bundle.zip ./artifacts/
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: Themerr-plex.bundle
if-no-files-found: error # 'warn' or 'ignore' are also available, defaults to `warn`
path: |
${{ github.workspace }}/artifacts
- name: Create Release
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
uses: LizardByte/.github/actions/create_release@master
Expand All @@ -121,3 +111,135 @@ jobs:
next_version: ${{ needs.check_changelog.outputs.next_version }}
last_version: ${{ needs.check_changelog.outputs.last_version }}
release_body: ${{ needs.check_changelog.outputs.release_body }}

pytest:
needs: [build]
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}
env:
PLEXAPI_AUTH_SERVER_BASEURL: http://127.0.0.1:32400
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: Themerr-plex.bundle

- name: Extract artifacts zip
shell: bash
run: |
# extract zip
7z x Themerr-plex.bundle.zip -o.
# move all files from "Themerr-plex.bundle" to root, with no target directory
cp -r ./Themerr-plex.bundle/. .
# remove zip
rm Themerr-plex.bundle.zip
- name: Set up Python
uses: LizardByte/.github/actions/setup_python2@nightly

- name: Install python dependencies
shell: bash
run: |
python -m pip --no-python-version-warning --disable-pip-version-check install --upgrade \
pip setuptools wheel
python -m pip --no-python-version-warning --disable-pip-version-check install -r requirements-dev.txt
- name: Install Plex Media Server
shell: bash
run: |
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
choco install plexmediaserver
elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then
brew install --cask plex-media-server
# starting with pms 1.29.2 servers must be claimed... disable that
# https://forums.plex.tv/t/new-server-claiming-requirement-for-macos/816337
defaults write com.plexapp.plexmediaserver enableLocalSecurity -bool FALSE
# copy plugin before starting plex server
mkdir -p "${HOME}/Library/Application Support/Plex Media Server/Plug-ins"
cp -r ./Themerr-plex.bundle "${HOME}/Library/Application Support/Plex Media Server/Plug-ins/"
open "/Applications/Plex Media Server.app"
elif [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then
curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -
echo deb https://downloads.plex.tv/repo/deb public main | \
sudo tee /etc/apt/sources.list.d/plexmediaserver.list
sudo apt-get update
sudo apt-get install plexmediaserver
# stop service
sudo systemctl stop plexmediaserver
# debug
cat /lib/systemd/system/plexmediaserver.service
# do not edit service directly, use override
override=/etc/systemd/system/plexmediaserver.service.d/override.conf
sudo mkdir -p $(dirname ${override})
sudo touch ${override}
echo "[Service]" | sudo tee ${override}
echo "User=$USER" | sudo tee -a ${override}
# take ownership
sudo chown -R $USER:$USER "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server"
# reload service
sudo systemctl daemon-reload
# start
sudo systemctl start plexmediaserver
else
echo "Unknown OS: ${{ matrix.os }}"
exit 1
fi
- name: Update Plex registry settings
if: ${{ matrix.os == 'windows-latest' }}
run: |
# starting with pmps 1.32.2 servers must be claimed... disable that
# https://forums.plex.tv/t/new-claiming-requirement-for-windows/839096
REG ADD "HKCU\Software\Plex, Inc.\Plex Media Server" /v enableLocalSecurity /t REG_DWORD /d 0 /f
- name: Bootstrap Plex server
id: boostrap
shell: bash
run: |
python \
-u scripts/plex-bootstraptest.py \
--destination plex \
--advertise-ip 127.0.0.1 \
--bootstrap-timeout 540 \
--no-docker \
--server-name plex-test-${{ matrix.os }}-${{ github.run_id }} \
--without-shows \
--without-music \
--without-photos \
--unclaimed
- name: Test with pytest
id: test
shell: bash
run: |
python -m pytest \
-rXs \
--tb=native \
--verbose \
--cov=Contents/Code \
tests
- name: Upload coverage
# any except cancelled or skipped
if: always() && (steps.test.outcome == 'success' || steps.test.outcome == 'failure')
uses: codecov/codecov-action@v3
with:
flags: ${{ runner.os }}
40 changes: 0 additions & 40 deletions .github/workflows/python-tests.yml

This file was deleted.

3 changes: 0 additions & 3 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@

# imports from Libraries\Shared
from typing import Optional
# we need to import youtube_dl.compat to prevent plexapi-backport from screwing with the standard library
# this needs to occur before any plexapi import
from youtube_dl import compat # noqa: F401

# local imports
from default_prefs import default_prefs
Expand Down
20 changes: 17 additions & 3 deletions Contents/Code/general_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
# local imports
from constants import metadata_base_directory, metadata_type_map, themerr_data_directory

# constants
legacy_keys = [
'downloaded_timestamp'
]


def get_media_upload_path(item, media_type):
# type: (any, str) -> str
Expand All @@ -40,6 +45,11 @@ def get_media_upload_path(item, media_type):
str
The path to the theme upload directory.
Raises
------
ValueError
If the ``media_type`` is not one of 'art', 'posters', or 'themes'.
Examples
--------
>>> get_media_upload_path(item=..., media_type='art')
Expand All @@ -49,6 +59,13 @@ def get_media_upload_path(item, media_type):
>>> get_media_upload_path(item=..., media_type='themes')
"...bundle/Uploads/themes..."
"""
allowed_media_types = ['art', 'posters', 'themes']
if media_type not in allowed_media_types:
raise ValueError(
'This error should be reported to https://github.com/LizardByte/Themerr-plex/issues;'
'media_type must be one of: {}'.format(allowed_media_types)
)

guid = item.guid
full_hash = hashlib.sha1(guid).hexdigest()
theme_upload_path = os.path.join(
Expand Down Expand Up @@ -202,9 +219,6 @@ def update_themerr_data_file(item, new_themerr_data):
themerr_data = get_themerr_json_data(item=item)

# remove legacy keys
legacy_keys = [
'downloaded_timestamp'
]
for key in legacy_keys:
try:
del themerr_data[key]
Expand Down
1 change: 0 additions & 1 deletion Contents/Code/tmdb_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def get_tmdb_id_from_collection(search_query):
645
"""
# /search/collection?query=James%20Bond%20Collection&include_adult=false&language=en-US&page=1"

query_url = 'search/collection?query={}'

# Plex returns 500 error if spaces are in collection query, same with `_`, `+`, and `%20`... so use `-`
Expand Down
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Integrations
:alt: Read the Docs
:target: http://themerr-plex.readthedocs.io/

.. image:: https://img.shields.io/codecov/c/gh/LizardByte/Themerr-plex?token=1LYYVYWY9D&style=for-the-badge&logo=codecov&label=codecov
:alt: Codecov
:target: https://codecov.io/gh/LizardByte/Themerr-plex

Downloads
---------

Expand Down
15 changes: 15 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
codecov:
branch: master

coverage:
status:
project:
default:
target: auto
threshold: 10%

comment:
layout: "diff, flags, files"
behavior: default
require_changes: false # if true: only post the comment if coverage changes
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXOPTS ?= -W --keep-going
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
Expand Down
5 changes: 3 additions & 2 deletions docs/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if "%SPHINXBUILD%" == "" (
)
set SOURCEDIR=source
set BUILDDIR=build
set "SPHINXOPTS=-W --keep-going"

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
Expand All @@ -25,11 +26,11 @@ if errorlevel 9009 (

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% || exit /b %ERRORLEVEL%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% || exit /b %ERRORLEVEL%

:end
popd
Loading

0 comments on commit aacfbe9

Please sign in to comment.