Skip to content

Fix plugin tests

Fix plugin tests #2237

Workflow file for this run

name: build
on:
push:
paths-ignore:
- 'README.md'
pull_request:
paths-ignore:
- 'README.md'
schedule:
- cron: '0 6 * * *'
jobs:
check_source:
if: github.event_name != 'schedule'
runs-on: ubuntu-latest
outputs:
python-changed: ${{ steps.changed.outputs.python }}
gui-changed: ${{ steps.changed.outputs.gui }}
language-changed: ${{ steps.changed.outputs.language }}
translation-changed: ${{ steps.po.outputs.po_changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check code changes
uses: dorny/paths-filter@v3
id: changed
with:
filters: |
python:
- '*.py'
- 'src/*.py'
- 'test/*.py'
gui:
- 'src/compat.py'
- 'src/YouTubeUi.py'
- 'src/YouTubeDownload.py'
- 'src/YouTubeSearch.py'
- 'src/YouTubeApi.py'
- 'src/YouTubeVideoUrl.py'
- 'src/OAuth.py'
language:
- 'po/*.po'
translation:
- 'src/plugin.py'
- 'src/YouTubeUi.py'
- 'src/YouTubeDownload.py'
- 'src/YouTubeSearch.py'
- name: Install dependencies
if: steps.changed.outputs.translation == 'true'
run: |
sudo apt install gettext
- name: Check translation phrase changes
if: steps.changed.outputs.translation == 'true'
id: po
run: |
xgettext --no-wrap --no-location --omit-header -L Python --from-code=UTF-8 -kpgettext:1c,2 --add-comments="TRANSLATORS:" -d YouTube -s -o ./po/YouTube.pot `find ./src -type f -name '*.py'`
if git status -s | grep 'M'; then
echo "po_changed=true" >> $GITHUB_OUTPUT
fi
test-python:
needs: check_source
if: needs.check_source.outputs.python-changed == 'true' || contains(github.event.head_commit.message,'force-test')
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['2.7', '3.12']
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3
if: matrix.python-version != '2.7'
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade Python 3 pip
if: matrix.python-version != '2.7'
run: |
python -m pip install --upgrade pip
- name: Set up Python 2
if: matrix.python-version == '2.7'
run: |
sudo apt install -y python2
sudo ln -sf /usr/bin/python2 /usr/bin/python
curl -L -O "https://bootstrap.pypa.io/pip/2.7/get-pip.py"
python get-pip.py
- name: Install dependencies
run: |
pip install flake8 pytest pytest-cov
- name: Compile sources
run: |
python -O -m compileall ./src/
- name: Check code with flake8
run: |
flake8 --ignore=W191,W504,E126,E127,E128,E501 --show-source --exclude=./src/compat.py,./src/jsinterp.py,./test/enigmahelper.py,./test/try_plugin.py,./src/__init__.py
flake8 --ignore=W191,E501 --show-source --filename=./src/jsinterp.py,./test/enigmahelper.py,./test/try_plugin.py,./src/__init__.py
flake8 --ignore=W191,F401,F821 --show-source --filename=./src/compat.py
- name: Remove enigma2 imports and variables for test
run: |
echo "" > src/__init__.py
sed -i 's/from Components/# from Components/g' src/YouTubeVideoUrl.py
sed -i 's/config.plugins.YouTube.maxResolution.value/"22"/g' src/YouTubeVideoUrl.py
sed -i 's/config.plugins.YouTube.useDashMP4.value/video_id != "bWgPKTOMoSY"/g' src/YouTubeVideoUrl.py
sed -i 's/config.plugins.YouTube.searchLanguage.value/"en"/g' src/YouTubeVideoUrl.py
sed -i 's/ != video_id/ != video_id or video_id in ("bWgPKTOMoSY", "9UMxZofMNbA")/g' src/YouTubeVideoUrl.py
- name: Test code with pytest
run: |
YOUTUBE_PLUGIN_TOKEN=${{ secrets.YOUTUBE_PLUGIN_TOKEN }} pytest -rx -v --cov=src --cov-report=xml --cov-report=html
mv .coverage .coverage_${{ matrix.python-version }}
- name: Upload code coverage results
uses: actions/upload-artifact@v4
with:
name: coverage_${{ matrix.python-version }}
path: .coverage_${{ matrix.python-version }}
test-gui:
needs: test-python
if: always() && (github.event_name == 'schedule' && github.ref == 'refs/heads/master') || ((needs.check_source.outputs.gui-changed == 'true' || contains(github.event.head_commit.message,'force-test')) && (needs.test-python.result == 'success' || needs.test-python.result == 'skipped'))
runs-on: ubuntu-latest
strategy:
matrix:
enigma2-version: ['OpenPLi develop 3.10', 'OpenPLi release-9.0 3.10', 'OpenPLi release-8.3 2.7', 'OpenPLi release-6.2 2.7', 'openatv master 3.12', 'openatv 6.4 2.7', 'OpenViX Developer 3.12', 'Taapat bh 2.7']
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set enigma2 repository
uses: jungwinter/split@v2
id: split
with:
msg: ${{ matrix.enigma2-version }}
- name: Checkout ${{ steps.split.outputs._0 }} ${{ steps.split.outputs._1 }} repository
uses: actions/checkout@v4
with:
repository: '${{ steps.split.outputs._0 }}/enigma2'
ref: ${{ steps.split.outputs._1 }}
path: './enigma2'
fetch-depth: 0
- name: Set up Python 3
if: steps.split.outputs._2 != '2.7'
uses: actions/setup-python@v5
with:
python-version: ${{ steps.split.outputs._2 }}
- name: Upgrade Python 3 pip
if: steps.split.outputs._2 != '2.7'
run: |
python -m pip install --upgrade pip
- name: Set up Python 2
if: steps.split.outputs._2 == '2.7'
run: |
sudo apt install -y python2
sudo ln -sf /usr/bin/python2 /usr/bin/python
curl -L -O "https://bootstrap.pypa.io/pip/2.7/get-pip.py"
python get-pip.py
- name: Install dependencies
run: |
[ '${{ steps.split.outputs._2 }}' == '3.12' ] && tw_ver="" || tw_ver="==20.3.0"
pip install twisted${tw_ver} pyopenssl service_identity
- name: Install additional dependencies
if: matrix.enigma2-version == 'openatv master 3.12' || matrix.enigma2-version == 'OpenViX Developer 3.12'
run: |
pip install requests chardet six
- name: Link plugin files for test
working-directory: './enigma2/lib/python/Plugins/Extensions'
run: |
ln -s ../../../../../src YouTube
- name: Patch enigma step 1
if: matrix.enigma2-version != 'OpenPLi release-6.2 2.7' && matrix.enigma2-version != 'openatv 6.4 2.7' && matrix.enigma2-version != 'Taapat bh 2.7'
run: |
sed -i 's/, domStyle, /, domStyle.getroot(), /g' enigma2/lib/python/skin.py
- name: Patch enigma step 2
if: steps.split.outputs._0 == 'openatv' || steps.split.outputs._0 == 'OpenViX'
run: |
cp test/RcModel.py enigma2/lib/python/Components
cp test/skin_display.xml ./
sed -i 's/\/home/./g' enigma2/lib/python/Components/UsageConfig.py
sed -i 's/config.crash.pystackonspinner.addNotifier/# config.crash.pystackonspinner.addNotifier/g' enigma2/lib/python/Components/UsageConfig.py
echo "model=duo4k" > enigma2/enigma.info
echo "architecture=arm" >> enigma2/enigma.info
echo "socfamily=brcmstb" >> enigma2/enigma.info
echo "brand=vu" >> enigma2/enigma.info
echo "displaytype=lcd" >> enigma2/enigma.info
echo "mtdrootfs=hdd" >> enigma2/enigma.info
echo "displaymodel=vu" >> enigma2/enigma.info
echo "machinebuild=vu" >> enigma2/enigma.info
echo "imagetype=developer" >> enigma2/enigma.info
echo "hdmifhdin=no" >> enigma2/enigma.info
echo "avjack=no" >> enigma2/enigma.info
echo "rca=no" >> enigma2/enigma.info
echo "scart=no" >> enigma2/enigma.info
echo "scartyuv=no" >> enigma2/enigma.info
echo "yuv=no" >> enigma2/enigma.info
- name: Patch enigma step 3
if: steps.split.outputs._0 == 'OpenViX'
run: |
cp test/skin_display.xml enigma2/data/skin_user.xml
sed -i 's/\/root/./g' enigma2/lib/python/Components/UsageConfig.py
sed -i 's/\/usr/./g' enigma2/lib/python/Components/UsageConfig.py
sed -i 's/addNotifier(iAVSwitch/addNotifier(iAVSwitch.setPolicy169) #/g' enigma2/lib/python/Components/AVSwitch.py
sed -i 's/instance, eListbox/instance, type(eListbox)/g' enigma2/lib/python/Components/GUIComponent.py
- name: Patch enigma step 4
if: matrix.enigma2-version == 'OpenPLi develop 3.10' || matrix.enigma2-version == 'OpenPLi release-9.0 3.10' || matrix.enigma2-version == 'OpenViX Developer 3.12'
working-directory: './enigma2/data'
run: |
python convert-iso-639-3.py
- name: ========== Test plugin screens load ==========
if: github.event_name == 'schedule'
run: |
YOUTUBE_PLUGIN_TOKEN=${{ secrets.YOUTUBE_PLUGIN_TOKEN }} E2_VERSION=${{ steps.split.outputs._0 }} PYTHONPATH=./test:./enigma2:./enigma2/lib/python python ./test/try_plugin.py
- name: Install coverage dependencies
if: github.event_name != 'schedule'
run: |
pip install pytest pytest-cov
- name: ========== Coverage code ==========
if: github.event_name != 'schedule'
run: |
YOUTUBE_PLUGIN_TOKEN=${{ secrets.YOUTUBE_PLUGIN_TOKEN }} E2_VERSION=${{ steps.split.outputs._0 }} PYTHONPATH=./test:./enigma2:./enigma2/lib/python python -m pytest -rx -v --cov=src --cov-report=xml --cov-report=html test/try_plugin.py -s
mv .coverage .coverage_${{ steps.split.outputs._0 }}_${{ steps.split.outputs._1 }}
- name: Upload code coverage results
if: github.event_name != 'schedule'
uses: actions/upload-artifact@v4
with:
name: coverage_${{ steps.split.outputs._0 }}_${{ steps.split.outputs._1 }}
path: .coverage_${{ steps.split.outputs._0 }}_${{ steps.split.outputs._1 }}
sonarcloud:
needs: [test-python, test-gui]
if: always() && needs.test-python.result == 'success' && needs.test-gui.result == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install coverage dependencies
run: |
pip install coverage
- name: Download code coverage results
uses: actions/download-artifact@v4
with:
pattern: coverage_*
merge-multiple: true
- name: Combine coverage results
run: |
coverage combine .coverage_*
coverage xml
- name: Override coverage source path for Sonarcloud
run: |
sed -i "s/<source>\/home\/runner\/work\/enigma2-plugin-youtube\/enigma2-plugin-youtube<\/source>/<source>\/github\/workspace<\/source>/g" coverage.xml
- name: Sonarcloud scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
test-language:
needs: check_source
if: needs.check_source.outputs.language-changed == 'true' || contains(github.event.head_commit.message,'force-test')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install dependencies
run: |
sudo apt install gettext
- name: Compile language files
run: |
for i in $(ls -1 ./po/*.po); do $(msgfmt "$i" -o "$i".mo); done
update-translation:
needs: check_source
if: needs.check_source.outputs.translation-changed == 'true' || contains(github.event.head_commit.message,'force-test')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
- name: Install dependencies
run: |
sudo apt install gettext
- name: Update translation files
run: |
xgettext --no-wrap --no-location -L Python --from-code=UTF-8 -kpgettext:1c,2 --add-comments="TRANSLATORS:" -d ./po/YouTube -s -o ./po/YouTube.pot `find ./src -type f -name '*.py'`
find ./po -type f -name '*.po' -print -exec msgmerge --backup=none --no-wrap -s -U {} ./po/YouTube.pot \;
find ./po -type f -name '*.po' -print -exec msgattrib --no-obsolete --no-wrap -o {} {} \;
xgettext --no-wrap --no-location --omit-header -L Python --from-code=UTF-8 -kpgettext:1c,2 --add-comments="TRANSLATORS:" -d YouTube -s -o ./po/YouTube.pot `find ./src -type f -name '*.py'`
- name: Compile language files
run: |
for i in $(ls -1 ./po/*.po); do $(msgfmt "$i" -o "$i".mo); done
rm ./po/*.mo
- name: Commit and push translation updates
uses: Taapat/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
message: 'Update language files'
branch: 'master'
deploy:
needs: [test-python, test-gui, test-language]
if: always() && !contains(github.event.head_commit.message,'skip-release') && github.event_name == 'push' && (needs.test-python.result == 'success' || needs.test-python.result == 'skipped') && (needs.test-gui.result == 'success' || needs.test-gui.result == 'skipped') && (needs.test-language.result == 'success' || needs.test-language.result == 'skipped') && github.repository == 'Taapat/enigma2-plugin-youtube' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Set up Python 2
run: |
sudo apt install -y python2
- name: Install dependencies
run: |
sudo apt install gettext
- name: Build sources
run: |
python setup.py build --build-lib=build/lib
- name: Set git variables
run: |
echo "SRCPV=git$(git rev-list --count HEAD)" >> $GITHUB_ENV
echo "PKGV=-git$(git rev-list --count HEAD)-${GITHUB_SHA::7}-r0.0" >> $GITHUB_ENV
echo "COMMIT_SUBJECT=$(git log -1 --pretty=format:%s)" >> $GITHUB_ENV
- name: Create plugin package files
run: |
mkdir -p deploy/data/usr/lib/enigma2/python/Plugins
cp -r build/lib/* deploy/data/usr/lib/enigma2/python/Plugins
mkdir -p deploy/data/etc/enigma2
sed -i 's/Version:/Version: py3${{ env.PKGV }}/' deploy/control/control
mkdir ipk
- name: Compile Python 3 sources
run: |
python3 -m compileall -b deploy/data/usr/lib/enigma2/python/Plugins/Extensions/YouTube/
- name: Build Python 3 data package
working-directory: './deploy/data'
run: |
tar --numeric-owner --group=0 --owner=0 -czf ../data.tar.gz ./*
- name: Build Python 3 control package
working-directory: './deploy/control'
run: |
tar --numeric-owner --group=0 --owner=0 -czf ../control.tar.gz ./*
- name: Build Python 3 ipk package
working-directory: './deploy'
run: |
echo 2.0 > debian-binary
ar rv ../ipk/enigma2-plugin-extensions-youtube_py3${{ env.PKGV }}.ipk debian-binary data.tar.gz control.tar.gz
- name: Delete compiled Python 3 files
run: |
rm deploy/data/usr/lib/enigma2/python/Plugins/Extensions/YouTube/*.pyc
- name: Compile Python 2 sources
run: |
python2 -O -m compileall deploy/data/usr/lib/enigma2/python/Plugins/Extensions/YouTube/
- name: Build Python 2 data package
working-directory: './deploy/data'
run: |
tar --numeric-owner --group=0 --owner=0 -czf ../data.tar.gz ./*
- name: Build Python 2 control package
working-directory: './deploy/control'
run: |
sed -i 's/Version: py3+/Version: h1+/' control
sed -i 's/python3-/python-/g' control
tar --numeric-owner --group=0 --owner=0 -czf ../control.tar.gz ./*
- name: Build Python 2 ipk package
working-directory: './deploy'
run: |
ar rv ../ipk/enigma2-plugin-extensions-youtube_h1${{ env.PKGV }}.ipk debian-binary data.tar.gz control.tar.gz
- name: Create release
uses: Taapat/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ env.SRCPV }}
name: ${{ env.COMMIT_SUBJECT }}
gzip: false
files: >
ipk/enigma2-plugin-extensions-youtube_h1${{ env.PKGV }}.ipk
ipk/enigma2-plugin-extensions-youtube_py3${{ env.PKGV }}.ipk
- name: Upload ipk via ftp
uses: sebastianpopp/ftp-action@releases/v2
with:
host: ${{ secrets.FTP_SERVER }}
user: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
localDir: 'ipk'
remoteDir: ${{ secrets.FTP_DIR }}