Skip to content

Commit

Permalink
release: v0.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
newt-sc committed Apr 23, 2020
1 parent ed76f07 commit eff8f67
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .githooks/post-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
#!/bin/bash

if [ -e .commit ]; then
rm .commit
git add -A
Expand Down
7 changes: 5 additions & 2 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

touch .commit

Expand All @@ -10,7 +10,10 @@ prefix='<!-- DO NOT EDIT. -->
suffix='</addons>'
addon=$(tail -n +2 addon.xml)

echo "$prefix\n$addon\n$suffix" > packages/addons.xml
printf "$prefix\n$addon\n$suffix\n" > packages/addons.xml
cat packages/addons.xml | shasum | awk '{print $1}' > packages/addons.xml.crc
truncate --size -1 packages/addons.xml.crc

python ./scripts/update_changelog.py

exit
22 changes: 21 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,50 @@ on:
branches: [ master ]

jobs:
validate:
runs-on: ubuntu-latest
outputs:
commit: ${{ steps.validate.outputs.commit }}

steps:
- uses: actions/checkout@v2

- name: Validate
id: validate
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: |
python ./scripts/validate_commit.py
build:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'chore:')"
needs: validate
strategy:
matrix:
python-version: [2.7, 3.7]

steps:
- uses: actions/checkout@v2
if: "startsWith(needs.validate.outputs.commit, 'release: v')"

- name: Set up Python ${{ matrix.python-version }}
if: "startsWith(needs.validate.outputs.commit, 'release: v')"
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
if: "startsWith(needs.validate.outputs.commit, 'release: v')"
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint
if: "startsWith(needs.validate.outputs.commit, 'release: v')"
run: |
flake8
- name: Test
if: "startsWith(needs.validate.outputs.commit, 'release: v')"
run: |
pytest -v
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ on:
jobs:
build:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'chore:')"
if: "startsWith(github.event.head_commit.message, 'release: v')"

steps:
- uses: actions/checkout@v2

- name: Create release
run: |
sh ./scripts/release.sh ${{ secrets.GITHUB_TOKEN }}
sh ./scripts/release.sh ${{ secrets.GITHUB_TOKEN }} "${{ github.event.head_commit.message }}"
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
* [v0.0.11](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-0.0.11):
* Changelog in KODI

* [v0.0.10](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-0.0.10):
* Inserted language code in sub filename

* [v0.0.9](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-0.0.9):
* Implemented (orginal, default, none, forced_only) as KODI language setting
* Fixed minor bugs in API implementation
* Added .idea folder to .gitignore

* [v0.0.8](https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles-0.0.8):
* opensubtitles should make max 2 requests for separate languages
* lint updates
Expand Down
60 changes: 54 additions & 6 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="service.subtitles.a4ksubtitles"
name="a4kSubtitles"
version="0.0.10"
version="0.0.11"
provider-name="Unknown">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
<import addon="vfs.libarchive"/>
<import addon="script.module.requests"/>
</requires>
<requires>
<import addon="xbmc.python" version="2.25.0"/>
<import addon="vfs.libarchive"/>
<import addon="script.module.requests"/>
</requires>
<extension point="xbmc.subtitle.module" library="main.py"/>
<extension point="xbmc.addon.metadata">
<summary lang="en">a4kSubtitles - Multi-Source Subtitles Addon</summary>
Expand All @@ -23,5 +23,53 @@ Supports: OpenSubtitles
<assets>
<icon>icon.png</icon>
</assets>
<news>
[v0.0.11]:
* Changelog in KODI

[v0.0.10]:
* Inserted language code in sub filename

[v0.0.9]:
* Implemented (orginal, default, none, forced_only) as KODI language setting
* Fixed minor bugs in API implementation
* Added .idea folder to .gitignore

[v0.0.8]:
* opensubtitles should make max 2 requests for separate languages
* lint updates
* add tests for download

[v0.0.7]:
* API class rename

[v0.0.6]:
* fix core requiring handle even with API usage

[v0.0.5]:
* expose API for usage without KODI
* add tests for search

[v0.0.4]:
* distribution process:
* KODI repository with updates based on github releases
* addons.xml and addons.xml.crc auto generation via git hooks
* release automation on merge to master via Github Actions

[v0.0.3]:
* general settings for configuring requests timeout and results limit
* additional ordering of the results depending on the similarity ratio of the video file name and the subtitle file name

[v0.0.2]:
* improve archive extraction support
* limit the results and add requests timeout
* fix OpenSubtitles authentication
* handle debug logging detection issues

[v0.0.1]:
* initial working version (search and download subtitles)
* OpenSubtitles support with optional authentication
* results ordering with preferred language ordered first
</news>
</extension>
</addon>
60 changes: 54 additions & 6 deletions packages/addons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<addons>
<addon id="service.subtitles.a4ksubtitles"
name="a4kSubtitles"
version="0.0.10"
version="0.0.11"
provider-name="Unknown">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
<import addon="vfs.libarchive"/>
<import addon="script.module.requests"/>
</requires>
<requires>
<import addon="xbmc.python" version="2.25.0"/>
<import addon="vfs.libarchive"/>
<import addon="script.module.requests"/>
</requires>
<extension point="xbmc.subtitle.module" library="main.py"/>
<extension point="xbmc.addon.metadata">
<summary lang="en">a4kSubtitles - Multi-Source Subtitles Addon</summary>
Expand All @@ -26,6 +26,54 @@ Supports: OpenSubtitles
<assets>
<icon>icon.png</icon>
</assets>
<news>
[v0.0.11]:
* Changelog in KODI

[v0.0.10]:
* Inserted language code in sub filename

[v0.0.9]:
* Implemented (orginal, default, none, forced_only) as KODI language setting
* Fixed minor bugs in API implementation
* Added .idea folder to .gitignore

[v0.0.8]:
* opensubtitles should make max 2 requests for separate languages
* lint updates
* add tests for download

[v0.0.7]:
* API class rename

[v0.0.6]:
* fix core requiring handle even with API usage

[v0.0.5]:
* expose API for usage without KODI
* add tests for search

[v0.0.4]:
* distribution process:
* KODI repository with updates based on github releases
* addons.xml and addons.xml.crc auto generation via git hooks
* release automation on merge to master via Github Actions

[v0.0.3]:
* general settings for configuring requests timeout and results limit
* additional ordering of the results depending on the similarity ratio of the video file name and the subtitle file name

[v0.0.2]:
* improve archive extraction support
* limit the results and add requests timeout
* fix OpenSubtitles authentication
* handle debug logging detection issues

[v0.0.1]:
* initial working version (search and download subtitles)
* OpenSubtitles support with optional authentication
* results ordering with preferred language ordered first
</news>
</extension>
</addon>
</addons>
2 changes: 1 addition & 1 deletion packages/addons.xml.crc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
76ca0d8937ec34388517309f61b6b7b2b0521701
7ff84516b598715f4820edd98ddf126bed2d6cd9
8 changes: 1 addition & 7 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#!/bin/bash

token=$1
ver=$(echo "$2" | sed "s/release: //")
user="a4k-openproject"
repo="a4kSubtitles"
sha="$(git rev-parse HEAD)"
ver=$(git show -s --format=%s)
tag_ver="${ver#?}"
tag="service.subtitles.a4ksubtitles/service.subtitles.a4ksubtitles-$tag_ver"
api="https://api.github.com/repos/$user/$repo"

if [ ${#ver} -ge 7 ]; then
echo 'skipping release'
exit
fi

generate_release_data()
{
cat <<EOF
Expand Down
20 changes: 20 additions & 0 deletions scripts/update_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-

import os
import re
from xml.etree import ElementTree

current_dir = os.path.dirname(__file__)
addon_xml_path = os.path.join(current_dir, '..', 'addon.xml')
changelog_path = os.path.join(current_dir, '..', 'CHANGELOG.md')

tree = ElementTree.parse(addon_xml_path)
root = tree.getroot()
news = root.find('./extension/news')
changelog = news.text.strip() + '\n'

tag_prefix = 'https://github.com/newt-sc/a4kSubtitles/releases/tag/service.subtitles.a4ksubtitles%2Fservice.subtitles.a4ksubtitles'
changelog = re.sub(r'\[v(.*?)\]:', lambda m: '* [v%s](%s-%s):' % (m.group(1), tag_prefix, m.group(1)), changelog)

with open(changelog_path, 'w') as f:
f.write(changelog)
59 changes: 59 additions & 0 deletions scripts/validate_commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-

import sys
import subprocess
import os
import json
import re
from xml.etree import ElementTree

github = json.loads(os.getenv('GITHUB_CONTEXT'))
is_pull_request = github['event_name'] == 'pull_request'

if is_pull_request:
os.system('git fetch --deepen=1 --no-tags --quiet')
command_args = ['git', 'log', '--format=%B', '-n', '1', github['event']['after']]
else:
command_args = ['git', 'show', '-s', '--format=%s']

git_last_commit_cmd = subprocess.Popen(command_args,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)

git_stdout, _ = git_last_commit_cmd.communicate()
commit_message = git_stdout.strip().decode('utf8')
print('Commit: `%s`' % commit_message)
os.system('echo "::set-output name=commit::%s"' % commit_message)

if is_pull_request and github['event']['pull_request']['commits'] > 1:
print('Error: Ammend your commits!')
sys.exit(1)

is_chore = commit_message.startswith('chore: ')
if is_chore:
sys.exit(os.EX_OK)

is_release = commit_message.startswith('release: v')
if not is_release:
print('Error: Only release and chore commits allowed!')
sys.exit(1)

semver_regex = r'^([0-9]+)\.([0-9]+)\.([0-9]+)$'
version = commit_message.replace('release: v', '')

if not re.match(semver_regex, version):
print('Error: Only semver `major.minor.patch` allowed without additional labels!')
sys.exit(1)

tree = ElementTree.parse(os.path.join(os.path.dirname(__file__), '..', 'addon.xml'))
root = tree.getroot()
addon_xml_version = root.get('version')

if addon_xml_version != version:
print('Error: The version must match the version set in addon.xml!')
sys.exit(1)

news = root.find('./extension/news').text.strip()
if not news.startswith('[v%s]:' % version):
print('Error: Update changelog in the news element of addon.xml!')
sys.exit(1)

0 comments on commit eff8f67

Please sign in to comment.