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

Commit

Permalink
Modify repository so HEAD contains the Matrix version (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelarnauts authored Feb 2, 2022
1 parent bcb5cac commit 16bb1ce
Show file tree
Hide file tree
Showing 16 changed files with 397 additions and 99 deletions.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ ADDON_PASSWORD=
KODI_HOME=tests/home
KODI_INTERACTIVE=0
KODI_STUB_VERBOSE=1
KODI_STUB_RPC_RESPONSES=tests/rpc

#HTTP_PROXY=
#HTTPS_PROXY=

GH_USERNAME=
GH_TOKEN=
EMAIL=
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ tests/ export-ignore
.pylintrc export-ignore
Makefile export-ignore
requirements.txt export-ignore
scripts/ export-ignore
7 changes: 1 addition & 6 deletions .github/workflows/addon-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@ jobs:
kodi-addon-checker:
name: Addon checker
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
kodi-version: [ leia, matrix ]
steps:
- name: Check out ${{ github.sha }} from repository ${{ github.repository }}
uses: actions/checkout@v2

- name: Run kodi-addon-checker
uses: xbmc/[email protected]
with:
kodi-version: ${{ matrix.kodi-version }}
rewrite-for-matrix: ${{ matrix.kodi-version == 'matrix' }}
kodi-version: matrix
addon-id: ${{ github.event.repository.name }}
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ on:
# Run action when pushed to master, or for commits in a pull request.
push:
branches:
- master
- master
pull_request:
branches:
- master
- master
jobs:
tests:
name: Add-on testing
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
KODI_INTERACTIVE: 0
KODI_STUB_RPC_RESPONSES: ${{ github.workspace }}/tests/rpc
HTTP_PROXY: ${{ secrets.HTTP_PROXY }}
run: pytest -v --cov=./ --cov-report=xml tests
run: pytest -x -v --cov=./ --cov-report=xml tests

- name: Upload code coverage to CodeCov
uses: codecov/codecov-action@v1
Expand Down
64 changes: 11 additions & 53 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,13 @@ on:
jobs:
build:
name: Release plugin.video.viervijfzes
if: startsWith(github.ref, 'refs/tags/') # prevent from running if it's not a tag
runs-on: ubuntu-latest
steps:
- name: Checkout code
- name: Check out ${{ github.sha }} from repository ${{ github.repository }}
uses: actions/checkout@v2

- name: Build zip files
id: build
run: |
sudo apt-get install libxml2-utils
make multizip release=1
echo ::set-output name=leia-filename::$(cd ..;ls plugin.video.viervijfzes*.zip | grep -v '+matrix.' | head -1)
echo ::set-output name=matrix-filename::$(cd ..;ls plugin.video.viervijfzes*+matrix.*.zip | head -1)
- name: Get body
id: get-body
- name: Get changelog
id: get-changelog
run: |
description=$(sed '1,6d;/^## /,$d' CHANGELOG.md)
echo $description
Expand All @@ -30,47 +21,14 @@ jobs:
description="${description//$'\r'/'%0D'}"
echo ::set-output name=body::$description
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Generate distribution zips
run: scripts/build.py

- name: Create Release on Github
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
body: ${{ steps.get-body.outputs.body }}
body: ${{ steps.get-changelog.outputs.body }}
draft: false
prerelease: false

- name: Upload Leia zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_name: ${{ steps.build.outputs.leia-filename }}
asset_path: ../${{ steps.build.outputs.leia-filename }}
asset_content_type: application/zip

- name: Upload Matrix zip
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_name: ${{ steps.build.outputs.matrix-filename }}
asset_path: ../${{ steps.build.outputs.matrix-filename }}
asset_content_type: application/zip

- name: Generate distribution zip and submit to official kodi repository
id: kodi-addon-submitter
uses: xbmc/[email protected]
with:
kodi-repository: repo-plugins
addon-id: plugin.video.viervijfzes
kodi-version: leia
kodi-matrix: true
env:
GH_USERNAME: ${{ secrets.GH_USERNAME }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
EMAIL: ${{ secrets.EMAIL }}
files: "dist/*.zip"
token: ${{ secrets.GH_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ tests/home/userdata/addon_data

Pipfile
Pipfile.lock

dist/
45 changes: 12 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
export KODI_HOME := $(CURDIR)/tests/home
export KODI_INTERACTIVE := 0
PYTHON := python
KODI_PYTHON_ABIS := 3.0.0 2.26.0

# Collect information to build as sensible package name
name = $(shell xmllint --xpath 'string(/addon/@id)' addon.xml)
version = $(shell xmllint --xpath 'string(/addon/@version)' addon.xml)
git_branch = $(shell git rev-parse --abbrev-ref HEAD)
git_hash = $(shell git rev-parse --short HEAD)

ifdef release
zip_name = $(name)-$(version).zip
else
zip_name = $(name)-$(version)-$(git_branch)-$(git_hash).zip
endif
zip_dir = $(name)/

languages = $(filter-out en_gb, $(patsubst resources/language/resource.language.%, %, $(wildcard resources/language/*)))

all: check test build
zip: build
multizip: build

check: check-pylint check-translations

Expand All @@ -30,15 +17,15 @@ check-pylint:
check-translations:
@printf ">>> Running translation checks\n"
@$(foreach lang,$(languages), \
msgcmp resources/language/resource.language.$(lang)/strings.po resources/language/resource.language.en_gb/strings.po; \
msgcmp --use-untranslated resources/language/resource.language.$(lang)/strings.po resources/language/resource.language.en_gb/strings.po; \
)
@tests/check_for_unused_translations.py
@scripts/check_for_unused_translations.py

check-addon: clean build
check-addon: build
@printf ">>> Running addon checks\n"
$(eval TMPDIR := $(shell mktemp -d))
@unzip ../${zip_name} -d ${TMPDIR}
cd ${TMPDIR} && kodi-addon-checker --branch=leia
@unzip dist/plugin.video.viervijfzes-*+matrix.1.zip -d ${TMPDIR}
cd ${TMPDIR} && kodi-addon-checker --branch=matrix
@rm -rf ${TMPDIR}

codefix:
Expand All @@ -56,17 +43,16 @@ clean:
@find . -name '__pycache__' -type d -delete
@rm -rf .pytest_cache/ tests/cdm tests/userdata/temp
@rm -f *.log .coverage
@rm -rf dist/

build: clean
@printf ">>> Building package\n"
@rm -f ../$(zip_name)
@git archive --format zip --worktree-attributes -v -o ../$(zip_name) --prefix $(zip_dir) $(or $(shell git stash create), HEAD)
@printf ">>> Successfully wrote package as: ../$(zip_name)\n"
@printf ">>> Building add-on\n"
@scripts/build.py
@ls -lah dist/*.zip

# You first need to run sudo gem install github_changelog_generator for this
release:
ifneq ($(release),)
@github_changelog_generator -u add-ons -p $(name) --no-issues --exclude-labels duplicate,question,invalid,wontfix release --future-release v$(release);
docker run -it --rm --env CHANGELOG_GITHUB_TOKEN=$(GH_TOKEN) -v "$(shell pwd)":/usr/local/src/your-app githubchangeloggenerator/github-changelog-generator -u add-ons -p plugin.video.viervijfzes --no-issues --exclude-labels duplicate,question,invalid,wontfix,release,testing --future-release v$(release)

@printf "cd /addon/@version\nset $$release\nsave\nbye\n" | xmllint --shell addon.xml; \
date=$(shell date '+%Y-%m-%d'); \
Expand All @@ -80,11 +66,4 @@ else
@printf "Usage: make release release=1.0.0\n"
endif

multizip: clean
@-$(foreach abi,$(KODI_PYTHON_ABIS), \
printf "cd /addon/requires/import[@addon='xbmc.python']/@version\nset $(abi)\nsave\nbye\n" | xmllint --shell addon.xml; \
matrix=$(findstring $(abi), $(word 1,$(KODI_PYTHON_ABIS))); \
if [ $$matrix ]; then version=$(version)+matrix.1; else version=$(version); fi; \
printf "cd /addon/@version\nset $$version\nsave\nbye\n" | xmllint --shell addon.xml; \
make build; \
)
.PHONY: check codefix test clean build release
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.viervijfzes" name="GoPlay" version="0.4.5" provider-name="Michaël Arnauts">
<requires>
<import addon="xbmc.python" version="2.26.0"/>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.dateutil" version="2.6.0"/>
<import addon="script.module.inputstreamhelper" version="0.5.1"/>
<import addon="script.module.pysocks" version="1.6.8" optional="true"/>
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/modules/iptvmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import absolute_import, division, unicode_literals

import logging
from datetime import timedelta, datetime
from datetime import datetime, timedelta

from resources.lib import kodiutils
from resources.lib.viervijfzes import CHANNELS
Expand Down
1 change: 1 addition & 0 deletions resources/lib/viervijfzes/aws/cognito_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from urllib.parse import quote, urlparse
except ImportError: # Python 2
from urllib import quote

from urlparse import urlparse

_LOGGER = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/viervijfzes/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import requests

from resources.lib.kodiutils import html_to_kodi, STREAM_DASH, STREAM_HLS
from resources.lib.kodiutils import STREAM_DASH, STREAM_HLS, html_to_kodi
from resources.lib.viervijfzes import ResolvedStream

try: # Python 3
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/viervijfzes/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import requests

from resources.lib import kodiutils
from resources.lib.viervijfzes.content import Program, ContentApi, CACHE_ONLY
from resources.lib.viervijfzes.content import CACHE_ONLY, ContentApi, Program

_LOGGER = logging.getLogger(__name__)

Expand Down
89 changes: 89 additions & 0 deletions scripts/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Build ZIP files for all brands. """
from __future__ import absolute_import, division, unicode_literals

import os
import shutil
import sys
import xml.etree.ElementTree as ET

BRANDS_DIR = 'brands'
DIST_DIR = 'dist'


def get_files():
""" Get a list of files that we should package. """
# Start with all non-hidden files
files = [f for f in os.listdir() if not f.startswith('.')]

# Exclude files from .gitattributes
with open('.gitattributes', 'r') as f:
for line in f.read().splitlines():
filename, mode = line.split(' ')
filename = filename.strip('/')
if mode == 'export-ignore' and filename in files:
files.remove(filename)

# Exclude files from .gitignore. I know, this won't do matching
with open('.gitignore', 'r') as f:
for filename in f.read().splitlines():
filename = filename.strip('/')
if filename in files:
files.remove(filename)

return files


def modify_xml(file, version, news, python=None):
""" Modify an addon.xml. """
with open(file, 'r+') as f:
tree = ET.fromstring(f.read())

# Update values
tree.set('version', version)
tree.find("./extension[@point='xbmc.addon.metadata']/news").text = news
if python:
tree.find("./requires/import[@addon='xbmc.python']").set('version', python)

# Save file
f.seek(0)
f.truncate()
f.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
ET.tostring(tree, encoding='UTF-8').decode())


if __name__ == '__main__':
# Read base addon.xml info
with open('addon.xml', 'r') as f:
tree = ET.fromstring(f.read())
addon_info = {
'id': tree.get('id'),
'version': tree.get('version'),
'news': tree.find("./extension[@point='xbmc.addon.metadata']/news").text
}

# Make sure dist folder exists
if not os.path.isdir(DIST_DIR):
os.mkdir(DIST_DIR)

# Build addon
brand = addon_info['id']
dest = os.path.join(DIST_DIR, brand)
if not os.path.isdir(dest):
os.mkdir(dest)

# Copy files from add-on source
for f in get_files():
if os.path.isfile(f):
shutil.copy(f, dest)
else:
shutil.copytree(f, os.path.join(dest, f), dirs_exist_ok=True)

# Update addon.xml for matrix and create zip
modify_xml(os.path.join(dest, 'addon.xml'), addon_info['version'] + '+matrix.1', addon_info['news'])
shutil.make_archive(os.path.join(DIST_DIR, "%s-%s+matrix.1" % (brand, addon_info['version'])), 'zip', DIST_DIR, brand)

# Modify addon.xml for leia and create zip
modify_xml(os.path.join(dest, 'addon.xml'), addon_info['version'], addon_info['news'], '2.26.0')
shutil.make_archive(os.path.join(DIST_DIR, "%s-%s" % (brand, addon_info['version'])), 'zip', DIST_DIR, brand)
Loading

0 comments on commit 16bb1ce

Please sign in to comment.