diff --git a/.github/workflows/build_tests.yml b/.github/workflows/build_tests.yml index b857af1..e3cdd1a 100644 --- a/.github/workflows/build_tests.yml +++ b/.github/workflows/build_tests.yml @@ -1,49 +1,11 @@ -name: Run Build Tests +name: Unit 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@v3 - - name: Setup Python - uses: actions/setup-python@v3 - 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 repo - run: | - pip install . - - uses: pypa/gh-action-pip-audit@v1.0.8 - with: - # Ignore irrelevant Mercurial vulnerability - # Ignore `requests` and `urllib3` vulnerabilities as they are not used in this package - # Ignore `setuptools` and `pip` vulnerabilities I don't think they apply here - ignore-vulns: | - PYSEC-2023-228 - GHSA-9wx4-h78v-vm56 - GHSA-34jh-p97f-mpxf - PYSEC-2022-43012 + py_build_tests: + uses: neongeckocom/.github/.github/workflows/python_build_tests.yml@master + with: + python_version: "3.8" + diff --git a/.github/workflows/license_tests.yml b/.github/workflows/license_tests.yml index e101270..5ec7120 100644 --- a/.github/workflows/license_tests.yml +++ b/.github/workflows/license_tests.yml @@ -1,39 +1,11 @@ name: Run License Tests on: push: - branches: - - master + workflow_dispatch: pull_request: branches: - - dev - workflow_dispatch: - + - master jobs: license_tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup Python - uses: actions/setup-python@v3 - 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: Check python - id: license_check_report - uses: pilosus/action-pip-license-checker@v0.5.0 - with: - fail: 'Copyleft,Other,Error' - fails-only: true - exclude-license: '^(Mozilla).*$' - - name: Print report - if: ${{ always() }} - run: echo "${{ steps.license_check_report.outputs.report }}" + uses: neongeckocom/.github/.github/workflows/license_tests.yml@master + diff --git a/.github/workflows/publish_stable.yml b/.github/workflows/publish_stable.yml index 3b864eb..c7df9cb 100644 --- a/.github/workflows/publish_stable.yml +++ b/.github/workflows/publish_stable.yml @@ -69,4 +69,4 @@ jobs: uses: ad-m/github-push-action@master with: github_token: ${{ secrets.GITHUB_TOKEN }} - branch: dev \ No newline at end of file + branch: dev diff --git a/.github/workflows/release_workflow.yml b/.github/workflows/release_workflow.yml index 1b7b803..a2adcf9 100644 --- a/.github/workflows/release_workflow.yml +++ b/.github/workflows/release_workflow.yml @@ -7,6 +7,7 @@ on: jobs: publish_alpha: + if: github.event.pull_request.merged == true uses: TigreGotico/gh-automations/.github/workflows/publish-alpha.yml@master secrets: inherit with: @@ -17,6 +18,22 @@ jobs: publish_prerelease: true changelog_max_issues: 100 + notify: + if: github.event.pull_request.merged == true + needs: publish_alpha + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Send message to Matrix bots channel + id: matrix-chat-message + uses: fadenb/matrix-chat-message@v0.0.6 + with: + homeserver: 'matrix.org' + token: ${{ secrets.MATRIX_TOKEN }} + channel: '!WjxEKjjINpyBRPFgxl:krbel.duckdns.org' + message: | + new ${{ github.event.repository.name }} PR merged! https://github.com/${{ github.repository }}/pull/${{ github.event.number }} + publish_pypi: needs: publish_alpha if: success() # Ensure this job only runs if the previous job succeeds @@ -36,20 +53,6 @@ jobs: - name: version run: echo "::set-output name=version::$(python setup.py --version)" id: version - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token - with: - tag_name: V${{ steps.version.outputs.version }} - release_name: Release ${{ steps.version.outputs.version }} - body: | - Changes in this Release - ${{ steps.changelog.outputs.changelog }} - draft: false - prerelease: true - commitish: dev - name: Build Distribution Packages run: | python setup.py sdist bdist_wheel @@ -102,4 +105,3 @@ jobs: -H "Authorization: token $GITHUB_TOKEN" \ -d "{\"title\":\"$PR_TITLE\",\"body\":\"$PR_BODY\",\"head\":\"$HEAD_BRANCH\",\"base\":\"$BASE_BRANCH\"}" \ https://api.github.com/repos/${{ github.repository }}/pulls - diff --git a/ovos_PHAL_plugin_mk1/__init__.py b/ovos_PHAL_plugin_mk1/__init__.py index 9e892ef..ded1a56 100644 --- a/ovos_PHAL_plugin_mk1/__init__.py +++ b/ovos_PHAL_plugin_mk1/__init__.py @@ -85,6 +85,9 @@ def __init__(self, bus=None, config=None): self.bus.on("mycroft.audio.service.play", self.on_music) self.bus.on("mycroft.audio.service.stop", self.on_display_reset) + self.bus.on("ovos.mk1.display_date", self.on_display_date) + self.bus.on("ovos.mk1.display_time", self.on_display_time) + self.bus.emit(Message("system.factory.reset.register", {"skill_id": "ovos-phal-plugin-mk1"})) @@ -512,14 +515,16 @@ def on_display(self, message=None): on the faceplate at once. """ code = "" - x_offset = "" - y_offset = "" + x_offset = 0 + y_offset = 0 clear_previous = "" + LOG.debug(message) + LOG.debug(message.data) if message and message.data: code = message.data.get("img_code", code) x_offset = int(message.data.get("xOffset", x_offset)) y_offset = int(message.data.get("yOffset", y_offset)) - clear_previous = message.data.get("clearPrev", clear_previous) + clear_previous = message.data.get("clear_previous", clear_previous) clear_previous = int(str(clear_previous) == "True") clear_previous = "cP=" + str(clear_previous) + "," @@ -589,3 +594,61 @@ def on_weather_display(self, message=None): icon = "x=2," + icon msg = "weather.display=" + str(temp) + "," + str(icon) self.writer.write(msg) + + # date/time + def on_display_date(self, message=None): + self._deactivate_mouth_events() + self.on_text(message) + sleep(10) + self.on_display_reset() + self._activate_mouth_events() + + def on_display_time(self, message=None): + code_dict = { + ':': 'CIICAA', + '0': 'EIMHEEMHAA', + '1': 'EIIEMHAEAA', + '2': 'EIEHEFMFAA', + '3': 'EIEFEFMHAA', + '4': 'EIMBABMHAA', + '5': 'EIMFEFEHAA', + '6': 'EIMHEFEHAA', + '7': 'EIEAEAMHAA', + '8': 'EIMHEFMHAA', + '9': 'EIMBEBMHAA', + } + + self._deactivate_mouth_events() + display_time = message.data.get("text") + # clear screen (draw two blank sections, numbers cover rest) + if len(display_time) == 4: + # for 4-character times, 9x8 blank + self.on_display(Message("", data={"img_code": "JIAAAAAAAAAAAAAAAAAA", "clear_previous": False})) + # self.enclosure.mouth_display(img_code="JIAAAAAAAAAAAAAAAAAA", + # refresh=False) + self.on_display(Message("", data={"img_code": "JIAAAAAAAAAAAAAAAAAA", "xOffset": 22, "clear_previous": False})) + # self.enclosure.mouth_display(img_code="JIAAAAAAAAAAAAAAAAAA", + # x=22, refresh=False) + else: + # for 5-character times, 7x8 blank + self.on_display(Message("", data={"img_code": "HIAAAAAAAAAAAAAA", "clear_previous": False})) + # self.enclosure.mouth_display(img_code="HIAAAAAAAAAAAAAA", + # refresh=False) + self.on_display(Message("", data={"img_code": "HIAAAAAAAAAAAAAA", "xOffset": 24, "clear_previous": False})) + # self.enclosure.mouth_display(img_code="HIAAAAAAAAAAAAAA", + # x=24, refresh=False) + + # draw the time, centered on display + xoffset = (32 - (4 * (len(display_time)) - 2)) / 2 + for c in display_time: + if c in code_dict: + self.on_display(Message("", data={"img_code": code_dict[c], "xOffset": xoffset, "clear_previous": False})) + if c == ":": + xoffset += 2 # colon is 1 pixels + a space + else: + xoffset += 4 # digits are 3 pixels + a space + + self.on_display(Message("", data={"img_code": "CIAAAA", "xOffset": 29, "clear_previous": False})) + sleep(5) + self.on_display_reset() + self._activate_mouth_events() diff --git a/ovos_PHAL_plugin_mk1/arduino.py b/ovos_PHAL_plugin_mk1/arduino.py index deeb0ea..277d294 100644 --- a/ovos_PHAL_plugin_mk1/arduino.py +++ b/ovos_PHAL_plugin_mk1/arduino.py @@ -142,15 +142,19 @@ def __init__(self, serial, bus, size=16): self.start() def flush(self): + LOG.debug(f"alive in flush {self.is_alive}") while self.alive: try: cmd = self.commands.get() + '\n' + LOG.debug(f"in arduino.flush {cmd}") self.serial.write(cmd.encode()) self.commands.task_done() except Exception as e: LOG.error("Writing error: {0}".format(e)) + LOG.debug("not alive anymore") def write(self, command): + LOG.debug(f"command in writer write {command}") self.commands.put(str(command)) def stop(self): diff --git a/scripts/remove_alpha.py b/scripts/remove_alpha.py new file mode 100644 index 0000000..ccb5e6b --- /dev/null +++ b/scripts/remove_alpha.py @@ -0,0 +1,26 @@ +""" +on merge to master -> declare stable (remove alpha) +""" +import argparse +import fileinput +from os.path import abspath + + +def update_alpha(version_file): + alpha_var_name = "VERSION_ALPHA" + + for line in fileinput.input(version_file, inplace=True): + if line.startswith(alpha_var_name): + print(f"{alpha_var_name} = 0") + else: + print(line.rstrip('\n')) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description='Update the version based on the specified part (major, minor, build, alpha)') + parser.add_argument('--version-file', help='Path to the version.py file', required=True) + + args = parser.parse_args() + + update_alpha(abspath(args.version_file)) diff --git a/scripts/update_version.py b/scripts/update_version.py new file mode 100644 index 0000000..e6897ef --- /dev/null +++ b/scripts/update_version.py @@ -0,0 +1,65 @@ +""" +on merge to dev: +- depending on labels (conventional commits) script is called with "major", "minor", "build", "alpha" +- on merge to dev, update version.py string to enforce semver +""" + +import argparse +from os.path import abspath + +def read_version(version_file): + VERSION_MAJOR = 0 + VERSION_MINOR = 0 + VERSION_BUILD = 0 + VERSION_ALPHA = 0 + + with open(version_file, 'r') as file: + content = file.read() + for l in content.split("\n"): + l = l.strip() + if l.startswith("VERSION_MAJOR"): + VERSION_MAJOR = int(l.split("=")[-1]) + elif l.startswith("VERSION_MINOR"): + VERSION_MINOR = int(l.split("=")[-1]) + elif l.startswith("VERSION_BUILD"): + VERSION_BUILD = int(l.split("=")[-1]) + elif l.startswith("VERSION_ALPHA"): + VERSION_ALPHA = int(l.split("=")[-1]) + return VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_ALPHA + + +def update_version(part, version_file): + VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_ALPHA = read_version(version_file) + + if part == 'major': + VERSION_MAJOR += 1 + VERSION_MINOR = 0 + VERSION_BUILD = 0 + VERSION_ALPHA = 1 + elif part == 'minor': + VERSION_MINOR += 1 + VERSION_BUILD = 0 + VERSION_ALPHA = 1 + elif part == 'build': + VERSION_BUILD += 1 + VERSION_ALPHA = 1 + elif part == 'alpha': + VERSION_ALPHA += 1 + + with open(version_file, 'w') as file: + file.write(f"""# START_VERSION_BLOCK +VERSION_MAJOR = {VERSION_MAJOR} +VERSION_MINOR = {VERSION_MINOR} +VERSION_BUILD = {VERSION_BUILD} +VERSION_ALPHA = {VERSION_ALPHA} +# END_VERSION_BLOCK""") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Update the version based on the specified part (major, minor, build, alpha)') + parser.add_argument('part', help='Part of the version to update (major, minor, build, alpha)') + parser.add_argument('--version-file', help='Path to the version.py file', required=True) + + args = parser.parse_args() + + update_version(args.part, abspath(args.version_file)) diff --git a/version.py b/version.py new file mode 100644 index 0000000..ea4e38a --- /dev/null +++ b/version.py @@ -0,0 +1,6 @@ +# START_VERSION_BLOCK +VERSION_MAJOR = 0 +VERSION_MINOR = 0 +VERSION_BUILD = 0 +VERSION_ALPHA = 1 +# END_VERSION_BLOCK