From 58948192a0bbee521bab7312299a311bdadce079 Mon Sep 17 00:00:00 2001 From: builderjer Date: Sun, 8 Sep 2024 07:23:14 -0600 Subject: [PATCH 01/10] automations --- .github/workflows/build_tests.yml | 24 ++-- .github/workflows/conventional-label.yml | 10 ++ .github/workflows/dev2master.yml | 20 ++++ .github/workflows/license_tests.yml | 26 +++-- .github/workflows/publish_alpha.yml | 137 +++++++++++++++++++++++ .github/workflows/publish_pypi.yml | 45 -------- .github/workflows/publish_stable.yml | 77 +++++++++++++ ovos_PHAL_plugin_mk1/mk1_serial.py | 53 +++++++++ scripts/remove_alpha.py | 27 +++++ scripts/update_version.py | 66 +++++++++++ test/license_tests.py | 53 --------- version.py | 6 + 12 files changed, 425 insertions(+), 119 deletions(-) create mode 100644 .github/workflows/conventional-label.yml create mode 100644 .github/workflows/dev2master.yml create mode 100644 .github/workflows/publish_alpha.yml delete mode 100644 .github/workflows/publish_pypi.yml create mode 100644 .github/workflows/publish_stable.yml create mode 100644 ovos_PHAL_plugin_mk1/mk1_serial.py create mode 100644 scripts/remove_alpha.py create mode 100644 scripts/update_version.py delete mode 100644 test/license_tests.py create mode 100644 version.py diff --git a/.github/workflows/build_tests.yml b/.github/workflows/build_tests.yml index f204bb7..59139a7 100644 --- a/.github/workflows/build_tests.yml +++ b/.github/workflows/build_tests.yml @@ -1,36 +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 - with: - ref: ${{ github.head_ref }} - name: Setup Python uses: actions/setup-python@v1 with: - python-version: 3.8 + 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 libfann-dev portaudio19-dev libpulse-dev + 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 tflite_runtime workaround tflit bug - run: | - pip3 install numpy - pip3 install --extra-index-url https://google-coral.github.io/py-repo/ tflite_runtime - - name: Install core repo + - name: Install skill run: | - pip install .[audio-backend,mark1,stt,tts,skills_minimal,skills,gui,bus,all] + pip install . + - uses: pypa/gh-action-pip-audit@v1.0.0 diff --git a/.github/workflows/conventional-label.yml b/.github/workflows/conventional-label.yml new file mode 100644 index 0000000..9894c1b --- /dev/null +++ b/.github/workflows/conventional-label.yml @@ -0,0 +1,10 @@ +# auto add labels to PRs +on: + pull_request_target: + types: [ opened, edited ] +name: conventional-release-labels +jobs: + label: + runs-on: ubuntu-latest + steps: + - uses: bcoe/conventional-release-labels@v1 diff --git a/.github/workflows/dev2master.yml b/.github/workflows/dev2master.yml new file mode 100644 index 0000000..1987cd8 --- /dev/null +++ b/.github/workflows/dev2master.yml @@ -0,0 +1,20 @@ +# This workflow will generate a distribution and upload it to PyPI + +name: Push dev -> master +on: + workflow_dispatch: + +jobs: + build_and_publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + ref: dev + - name: Push dev -> master + uses: ad-m/github-push-action@master + + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: master diff --git a/.github/workflows/license_tests.yml b/.github/workflows/license_tests.yml index 561e773..708539a 100644 --- a/.github/workflows/license_tests.yml +++ b/.github/workflows/license_tests.yml @@ -1,6 +1,11 @@ name: Run License Tests on: push: + branches: + - master + pull_request: + branches: + - dev workflow_dispatch: jobs: @@ -8,8 +13,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} - name: Setup Python uses: actions/setup-python@v1 with: @@ -24,12 +27,13 @@ jobs: - name: Install core repo run: | pip install . - - name: Install licheck - run: | - pip install git+https://github.com/NeonJarbas/lichecker - - name: Install test dependencies - run: | - pip install pytest pytest-timeout pytest-cov - - name: Test Licenses - run: | - pytest test/license_tests.py \ No newline at end of file + - 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 }}" diff --git a/.github/workflows/publish_alpha.yml b/.github/workflows/publish_alpha.yml new file mode 100644 index 0000000..ba90e50 --- /dev/null +++ b/.github/workflows/publish_alpha.yml @@ -0,0 +1,137 @@ +# This workflow will generate an ALPHA release distribution and upload it to PyPI +name: Publish Alpha Build +on: + pull_request: + types: [closed] + branches: + - dev + paths-ignore: + - 'version.py' + - 'test/**' + - 'examples/**' + - '.github/**' + - '.gitignore' + - 'LICENSE' + - 'CHANGELOG.md' + - 'MANIFEST.in' + - 'README.md' + - 'scripts/**' + +jobs: + build_and_publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: dev + fetch-depth: 0 # Avoid errors when pushing refs to the destination repository + + - 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: Debug GitHub Labels + run: | + echo "Labels in Pull Request:" + echo "${{ toJson(github.event.pull_request.labels) }}" + + # Convert the labels array into text using jq + LABELS=$(echo '${{ toJson(github.event.pull_request.labels) }}' | jq -r '.[].name') + + # Handle the case where there are no labels + if [ -z "$LABELS" ]; then + echo "No labels found on the pull request." + else + echo "Labels: $LABELS" + fi + + - name: Determine version bump + id: version_bump + run: | + # Convert the labels array into text using jq + LABELS=$(echo '${{ toJson(github.event.pull_request.labels) }}' | jq -r '.[].name') + + # Handle the case where there are no labels + if [ -z "$LABELS" ]; then + echo "No labels found on the pull request." + LABELS="" + fi + + echo "Labels: $LABELS" + + MAJOR=0 + MINOR=0 + BUILD=0 + + # Loop over the labels and determine the version bump + for label in $LABELS; do + echo "Processing label: $label" + if [ "$label" == "breaking" ]; then + MAJOR=1 + elif [ "$label" == "feature" ]; then + MINOR=1 + elif [ "$label" == "fix" ]; then + BUILD=1 + fi + done + + # Set the output based on the labels found + if [ $MAJOR -eq 1 ]; then + echo "::set-output name=part::major" + elif [ $MINOR -eq 1 ]; then + echo "::set-output name=part::minor" + elif [ $BUILD -eq 1 ]; then + echo "::set-output name=part::build" + else + echo "::set-output name=part::alpha" + fi + + - name: Update version in version.py + run: | + python scripts/update_version.py ${{ steps.version_bump.outputs.part }} --version-file $GITHUB_WORKSPACE/version.py + + - name: "Generate release changelog" + uses: heinrichreimer/github-changelog-generator-action@v2.3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + maxIssues: 50 + id: changelog + + - name: Commit to dev + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Increment Version + branch: dev + + - 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 + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{secrets.PYPI_TOKEN}} diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml deleted file mode 100644 index 747142c..0000000 --- a/.github/workflows/publish_pypi.yml +++ /dev/null @@ -1,45 +0,0 @@ -# This workflow will generate a distribution and upload it to PyPI - -name: Publish to pypi -on: - workflow_dispatch: - -jobs: - build_and_publish: - 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 Build Tools - run: | - python -m pip install build wheel - - 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 bdist_wheel - - name: Publish to Test PyPI - uses: pypa/gh-action-pypi-publish@master - with: - password: ${{secrets.PYPI_TOKEN}} diff --git a/.github/workflows/publish_stable.yml b/.github/workflows/publish_stable.yml new file mode 100644 index 0000000..1194935 --- /dev/null +++ b/.github/workflows/publish_stable.yml @@ -0,0 +1,77 @@ +# This workflow will generate a STABLE distribution and upload it to PyPI + +name: Publish Stable Release +on: + push: + branches: + - master + paths-ignore: + - 'test/**' + - 'examples/**' + - '.github/**' + - '.gitignore' + - 'CHANGELOG.md' + - 'MANIFEST.in' + - 'scripts/**' + workflow_dispatch: + +jobs: + build_and_publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: master + 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 Build Tools + run: | + python -m pip install build wheel + - name: Remove Alpha tag + run: | + python scripts/remove_alpha.py --version-file $GITHUB_WORKSPACE/version.py + - name: "Generate release changelog" + uses: heinrichreimer/github-changelog-generator-action@v2.3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + maxIssues: 50 + id: changelog + - name: Commit to master + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Increment Version + branch: master + - name: Rebase dev on master + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git checkout dev + git rebase origin/master + git push origin dev --force-with-lease + - 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: false + commitish: master + - name: Build Distribution Packages + run: | + python setup.py sdist bdist_wheel + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{secrets.PYPI_TOKEN}} diff --git a/ovos_PHAL_plugin_mk1/mk1_serial.py b/ovos_PHAL_plugin_mk1/mk1_serial.py new file mode 100644 index 0000000..c46f1ea --- /dev/null +++ b/ovos_PHAL_plugin_mk1/mk1_serial.py @@ -0,0 +1,53 @@ +import serial + +from ovos_utils.log import LOG +# from ovos_config import Configuration + +class MK1Serial(): + def __init__(self, config=None): + config = config or {"port": "/dev/ttyAMA0", + "rate": 9600, + "timeout": 5.0}) + self.port = config.get("port") + self.rate = config.get("rate") + self.timeout = config.get("timeout") + + try: + self.ser = serial.serial_for_url(url=self.port, baudrate=self.rate, timeout=self.timeout, do_not_open=True) + LOG.info(f"Serial connection created with port: {self.port}, baudrate: {self.rate}, timeout: {self.timeout}") + except Exception as e: + LOG.exception(f"could not connect to serial: {self.port}") + + @property + def is_open(self): + if self.ser: + return self.ser.is_open() + return False + + def open_ser(self): + if not self.is_open(): + try: + self.ser.open() + except Exception as e: + LOG.error(f"could not open serial port {self.port}: {e}") + else: + LOG.debug(f"serial port {self.port} is already open") + + def close_ser(self): + if self.is_open(): + try: + self.ser.flush() + self.ser.close() + except Exception as e: + LOG.error(f"could not close serial port {self.port}: {e}") + else: + LOG.debug(f"serial port {self.port} is already closed") + + def reset_ser(self): + if self.is_open(): + try: + self.close_ser() + self.open_ser() + LOG.debug(f"serial connection {self.port} has been reset") + except Exception as e: + LOG.error(f"could not reset serial port {self.port}: {e}") diff --git a/scripts/remove_alpha.py b/scripts/remove_alpha.py new file mode 100644 index 0000000..fa4d09b --- /dev/null +++ b/scripts/remove_alpha.py @@ -0,0 +1,27 @@ +""" +on merge to master -> declare stable (remove alpha) +""" +import argparse +import fileinput +import sys +from os.path import abspath, join, dirname + + +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..188eaa1 --- /dev/null +++ b/scripts/update_version.py @@ -0,0 +1,66 @@ +""" +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 sys +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/test/license_tests.py b/test/license_tests.py deleted file mode 100644 index 8cf0e08..0000000 --- a/test/license_tests.py +++ /dev/null @@ -1,53 +0,0 @@ -import unittest -from pprint import pprint - -from lichecker import LicenseChecker - -# these packages dont define license in setup.py -# manually verified and injected -license_overrides = { - "kthread": "MIT", - 'yt-dlp': "Unlicense", - 'pyxdg': 'GPL-2.0', - 'ptyprocess': 'ISC license', - 'psutil': 'BSD3' -} -# explicitly allow these packages that would fail otherwise -whitelist = [] - -# validation flags -allow_nonfree = False -allow_viral = False -allow_unknown = False -allow_unlicense = True -allow_ambiguous = False - -pkg_name = "ovos-phal-mk1" - - -class TestLicensing(unittest.TestCase): - @classmethod - def setUpClass(self): - licheck = LicenseChecker(pkg_name, - license_overrides=license_overrides, - whitelisted_packages=whitelist, - allow_ambiguous=allow_ambiguous, - allow_unlicense=allow_unlicense, - allow_unknown=allow_unknown, - allow_viral=allow_viral, - allow_nonfree=allow_nonfree) - print("Package", pkg_name) - print("Version", licheck.version) - print("License", licheck.license) - print("Transient Requirements (dependencies of dependencies)") - pprint(licheck.transient_dependencies) - self.licheck = licheck - - def test_license_compliance(self): - print("Package Versions") - pprint(self.licheck.versions) - - print("Dependency Licenses") - pprint(self.licheck.licenses) - - self.licheck.validate() 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 From 58ff301028c49da41f3fc892452445ad5bf09d09 Mon Sep 17 00:00:00 2001 From: builderjer Date: Sun, 8 Sep 2024 09:16:00 -0600 Subject: [PATCH 02/10] fix build test? --- .github/workflows/build_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_tests.yml b/.github/workflows/build_tests.yml index 59139a7..8440e62 100644 --- a/.github/workflows/build_tests.yml +++ b/.github/workflows/build_tests.yml @@ -37,4 +37,4 @@ jobs: - name: Install skill run: | pip install . - - uses: pypa/gh-action-pip-audit@v1.0.0 + - uses: pypa/gh-action-pip-audit@v1.0.8 From b08178da9e652e5137dbbf15c0481ca1d38a4c6d Mon Sep 17 00:00:00 2001 From: builderjer Date: Sun, 8 Sep 2024 09:22:23 -0600 Subject: [PATCH 03/10] fix build test...again --- .github/workflows/build_tests.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/build_tests.yml b/.github/workflows/build_tests.yml index 8440e62..c289fe8 100644 --- a/.github/workflows/build_tests.yml +++ b/.github/workflows/build_tests.yml @@ -38,3 +38,12 @@ jobs: 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 From 07080f50e42ab997e2077ed1a7da504081635058 Mon Sep 17 00:00:00 2001 From: builderjer Date: Sun, 8 Sep 2024 09:27:43 -0600 Subject: [PATCH 04/10] remove unused file --- ovos_PHAL_plugin_mk1/mk1_serial.py | 53 ------------------------------ 1 file changed, 53 deletions(-) delete mode 100644 ovos_PHAL_plugin_mk1/mk1_serial.py diff --git a/ovos_PHAL_plugin_mk1/mk1_serial.py b/ovos_PHAL_plugin_mk1/mk1_serial.py deleted file mode 100644 index c46f1ea..0000000 --- a/ovos_PHAL_plugin_mk1/mk1_serial.py +++ /dev/null @@ -1,53 +0,0 @@ -import serial - -from ovos_utils.log import LOG -# from ovos_config import Configuration - -class MK1Serial(): - def __init__(self, config=None): - config = config or {"port": "/dev/ttyAMA0", - "rate": 9600, - "timeout": 5.0}) - self.port = config.get("port") - self.rate = config.get("rate") - self.timeout = config.get("timeout") - - try: - self.ser = serial.serial_for_url(url=self.port, baudrate=self.rate, timeout=self.timeout, do_not_open=True) - LOG.info(f"Serial connection created with port: {self.port}, baudrate: {self.rate}, timeout: {self.timeout}") - except Exception as e: - LOG.exception(f"could not connect to serial: {self.port}") - - @property - def is_open(self): - if self.ser: - return self.ser.is_open() - return False - - def open_ser(self): - if not self.is_open(): - try: - self.ser.open() - except Exception as e: - LOG.error(f"could not open serial port {self.port}: {e}") - else: - LOG.debug(f"serial port {self.port} is already open") - - def close_ser(self): - if self.is_open(): - try: - self.ser.flush() - self.ser.close() - except Exception as e: - LOG.error(f"could not close serial port {self.port}: {e}") - else: - LOG.debug(f"serial port {self.port} is already closed") - - def reset_ser(self): - if self.is_open(): - try: - self.close_ser() - self.open_ser() - LOG.debug(f"serial connection {self.port} has been reset") - except Exception as e: - LOG.error(f"could not reset serial port {self.port}: {e}") From 0d029f2fa92694ce6c8b0deceb2661443729be1a Mon Sep 17 00:00:00 2001 From: builderjer Date: Sun, 8 Sep 2024 09:38:47 -0600 Subject: [PATCH 05/10] updated action versions --- .github/workflows/build_tests.yml | 4 ++-- .github/workflows/dev2master.yml | 2 +- .github/workflows/license_tests.yml | 4 ++-- .github/workflows/publish_alpha.yml | 4 ++-- .github/workflows/publish_stable.yml | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build_tests.yml b/.github/workflows/build_tests.yml index c289fe8..049c97d 100644 --- a/.github/workflows/build_tests.yml +++ b/.github/workflows/build_tests.yml @@ -16,9 +16,9 @@ jobs: python-version: [ 3.7, 3.8, 3.9, "3.10" ] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Python - uses: actions/setup-python@v1 + uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} - name: Install Build Tools diff --git a/.github/workflows/dev2master.yml b/.github/workflows/dev2master.yml index 1987cd8..1528f2c 100644 --- a/.github/workflows/dev2master.yml +++ b/.github/workflows/dev2master.yml @@ -8,7 +8,7 @@ jobs: build_and_publish: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. ref: dev diff --git a/.github/workflows/license_tests.yml b/.github/workflows/license_tests.yml index 708539a..e101270 100644 --- a/.github/workflows/license_tests.yml +++ b/.github/workflows/license_tests.yml @@ -12,9 +12,9 @@ jobs: license_tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup Python - uses: actions/setup-python@v1 + uses: actions/setup-python@v3 with: python-version: 3.8 - name: Install Build Tools diff --git a/.github/workflows/publish_alpha.yml b/.github/workflows/publish_alpha.yml index ba90e50..419db31 100644 --- a/.github/workflows/publish_alpha.yml +++ b/.github/workflows/publish_alpha.yml @@ -21,13 +21,13 @@ jobs: build_and_publish: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: ref: dev fetch-depth: 0 # Avoid errors when pushing refs to the destination repository - name: Setup Python - uses: actions/setup-python@v1 + uses: actions/setup-python@v3 with: python-version: 3.8 diff --git a/.github/workflows/publish_stable.yml b/.github/workflows/publish_stable.yml index 1194935..e7be905 100644 --- a/.github/workflows/publish_stable.yml +++ b/.github/workflows/publish_stable.yml @@ -19,12 +19,12 @@ jobs: build_and_publish: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: ref: master fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. - name: Setup Python - uses: actions/setup-python@v1 + uses: actions/setup-python@v3 with: python-version: 3.8 - name: Install Build Tools From 2c0f9cae337a4c0afe86967d130738463eb22d8a Mon Sep 17 00:00:00 2001 From: builderjer Date: Mon, 9 Sep 2024 05:28:22 -0600 Subject: [PATCH 06/10] codebot recomendations --- .github/workflows/publish_alpha.yml | 2 +- .github/workflows/publish_stable.yml | 2 +- scripts/remove_alpha.py | 3 +-- scripts/update_version.py | 1 - 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish_alpha.yml b/.github/workflows/publish_alpha.yml index 419db31..b4ee352 100644 --- a/.github/workflows/publish_alpha.yml +++ b/.github/workflows/publish_alpha.yml @@ -93,7 +93,7 @@ jobs: - name: Update version in version.py run: | - python scripts/update_version.py ${{ steps.version_bump.outputs.part }} --version-file $GITHUB_WORKSPACE/version.py + python scripts/update_version.py ${{ steps.version_bump.outputs.part }} --version-file "$GITHUB_WORKSPACE/version.py" - name: "Generate release changelog" uses: heinrichreimer/github-changelog-generator-action@v2.3 diff --git a/.github/workflows/publish_stable.yml b/.github/workflows/publish_stable.yml index e7be905..83cb7b5 100644 --- a/.github/workflows/publish_stable.yml +++ b/.github/workflows/publish_stable.yml @@ -32,7 +32,7 @@ jobs: python -m pip install build wheel - name: Remove Alpha tag run: | - python scripts/remove_alpha.py --version-file $GITHUB_WORKSPACE/version.py + python scripts/remove_alpha.py --version-file "$GITHUB_WORKSPACE/version.py" - name: "Generate release changelog" uses: heinrichreimer/github-changelog-generator-action@v2.3 with: diff --git a/scripts/remove_alpha.py b/scripts/remove_alpha.py index fa4d09b..ccb5e6b 100644 --- a/scripts/remove_alpha.py +++ b/scripts/remove_alpha.py @@ -3,8 +3,7 @@ """ import argparse import fileinput -import sys -from os.path import abspath, join, dirname +from os.path import abspath def update_alpha(version_file): diff --git a/scripts/update_version.py b/scripts/update_version.py index 188eaa1..e6897ef 100644 --- a/scripts/update_version.py +++ b/scripts/update_version.py @@ -4,7 +4,6 @@ - on merge to dev, update version.py string to enforce semver """ -import sys import argparse from os.path import abspath From a621878f48250b427a1683551c0bdccc552e0218 Mon Sep 17 00:00:00 2001 From: miro Date: Mon, 9 Sep 2024 23:26:04 +0100 Subject: [PATCH 07/10] automation:shared_actions --- .github/workflows/publish_alpha.yml | 137 ------------------ .github/workflows/publish_stable.yml | 87 +++-------- .github/workflows/release_workflow.yml | 63 ++++++++ version.py => ovos_PHAL_plugin_mk1/version.py | 2 +- 4 files changed, 84 insertions(+), 205 deletions(-) delete mode 100644 .github/workflows/publish_alpha.yml create mode 100644 .github/workflows/release_workflow.yml rename version.py => ovos_PHAL_plugin_mk1/version.py (84%) diff --git a/.github/workflows/publish_alpha.yml b/.github/workflows/publish_alpha.yml deleted file mode 100644 index b4ee352..0000000 --- a/.github/workflows/publish_alpha.yml +++ /dev/null @@ -1,137 +0,0 @@ -# This workflow will generate an ALPHA release distribution and upload it to PyPI -name: Publish Alpha Build -on: - pull_request: - types: [closed] - branches: - - dev - paths-ignore: - - 'version.py' - - 'test/**' - - 'examples/**' - - '.github/**' - - '.gitignore' - - 'LICENSE' - - 'CHANGELOG.md' - - 'MANIFEST.in' - - 'README.md' - - 'scripts/**' - -jobs: - build_and_publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - ref: dev - fetch-depth: 0 # Avoid errors when pushing refs to the destination repository - - - 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: Debug GitHub Labels - run: | - echo "Labels in Pull Request:" - echo "${{ toJson(github.event.pull_request.labels) }}" - - # Convert the labels array into text using jq - LABELS=$(echo '${{ toJson(github.event.pull_request.labels) }}' | jq -r '.[].name') - - # Handle the case where there are no labels - if [ -z "$LABELS" ]; then - echo "No labels found on the pull request." - else - echo "Labels: $LABELS" - fi - - - name: Determine version bump - id: version_bump - run: | - # Convert the labels array into text using jq - LABELS=$(echo '${{ toJson(github.event.pull_request.labels) }}' | jq -r '.[].name') - - # Handle the case where there are no labels - if [ -z "$LABELS" ]; then - echo "No labels found on the pull request." - LABELS="" - fi - - echo "Labels: $LABELS" - - MAJOR=0 - MINOR=0 - BUILD=0 - - # Loop over the labels and determine the version bump - for label in $LABELS; do - echo "Processing label: $label" - if [ "$label" == "breaking" ]; then - MAJOR=1 - elif [ "$label" == "feature" ]; then - MINOR=1 - elif [ "$label" == "fix" ]; then - BUILD=1 - fi - done - - # Set the output based on the labels found - if [ $MAJOR -eq 1 ]; then - echo "::set-output name=part::major" - elif [ $MINOR -eq 1 ]; then - echo "::set-output name=part::minor" - elif [ $BUILD -eq 1 ]; then - echo "::set-output name=part::build" - else - echo "::set-output name=part::alpha" - fi - - - name: Update version in version.py - run: | - python scripts/update_version.py ${{ steps.version_bump.outputs.part }} --version-file "$GITHUB_WORKSPACE/version.py" - - - name: "Generate release changelog" - uses: heinrichreimer/github-changelog-generator-action@v2.3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - maxIssues: 50 - id: changelog - - - name: Commit to dev - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Increment Version - branch: dev - - - 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 - - - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - password: ${{secrets.PYPI_TOKEN}} diff --git a/.github/workflows/publish_stable.yml b/.github/workflows/publish_stable.yml index 83cb7b5..6623a1a 100644 --- a/.github/workflows/publish_stable.yml +++ b/.github/workflows/publish_stable.yml @@ -1,77 +1,30 @@ -# This workflow will generate a STABLE distribution and upload it to PyPI - -name: Publish Stable Release +name: Stable Release on: push: - branches: - - master - paths-ignore: - - 'test/**' - - 'examples/**' - - '.github/**' - - '.gitignore' - - 'CHANGELOG.md' - - 'MANIFEST.in' - - 'scripts/**' + branches: [master] workflow_dispatch: jobs: - build_and_publish: + publish_stable: + uses: TigreGotico/gh-automations/.github/workflows/publish-stable.yml@master + with: + branch: 'master' + version_file: 'ovos_PHAL_plugin_mk1/version.py' + setup_py: 'setup.py' + publish_release: true + publish_pypi: true + + sync_dev: + needs: publish_stable + if: success() # Ensure this job only runs if the previous job succeeds runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v2 with: - ref: master fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. - - 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: Remove Alpha tag - run: | - python scripts/remove_alpha.py --version-file "$GITHUB_WORKSPACE/version.py" - - name: "Generate release changelog" - uses: heinrichreimer/github-changelog-generator-action@v2.3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - maxIssues: 50 - id: changelog - - name: Commit to master - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Increment Version - branch: master - - name: Rebase dev on master - run: | - git config user.name "GitHub Actions" - git config user.email "actions@github.com" - git checkout dev - git rebase origin/master - git push origin dev --force-with-lease - - 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: false - commitish: master - - name: Build Distribution Packages - run: | - python setup.py sdist bdist_wheel - - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 + ref: master + - name: Push master -> dev + uses: ad-m/github-push-action@master with: - password: ${{secrets.PYPI_TOKEN}} + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: dev \ No newline at end of file diff --git a/.github/workflows/release_workflow.yml b/.github/workflows/release_workflow.yml new file mode 100644 index 0000000..4877f55 --- /dev/null +++ b/.github/workflows/release_workflow.yml @@ -0,0 +1,63 @@ +name: Release Alpha and Propose Stable + +on: + pull_request: + types: [closed] + branches: [dev] + +jobs: + publish_alpha: + uses: TigreGotico/gh-automations/.github/workflows/publish-alpha.yml@master + with: + branch: 'dev' + version_file: 'ovos_PHAL_plugin_mk1/version.py' + setup_py: 'setup.py' + update_changelog: true + publish_prerelease: true + publish_pypi: true + changelog_max_issues: 100 + + propose_release: + needs: publish_alpha + if: success() # Ensure this job only runs if the previous job succeeds + runs-on: ubuntu-latest + steps: + - name: Checkout dev branch + uses: actions/checkout@v3 + with: + ref: dev + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: '3.10' + + - name: Get version from setup.py + id: get_version + run: | + VERSION=$(python setup.py --version) + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Create and push new branch + run: | + git checkout -b release-${{ env.VERSION }} + git push origin release-${{ env.VERSION }} + + - name: Open Pull Request from dev to master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Variables + BRANCH_NAME="release-${{ env.VERSION }}" + BASE_BRANCH="master" + HEAD_BRANCH="release-${{ env.VERSION }}" + PR_TITLE="Release ${{ env.VERSION }}" + PR_BODY="Human review requested!" + + # Create a PR using GitHub API + curl -X POST \ + -H "Accept: application/vnd.github+json" \ + -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/version.py b/ovos_PHAL_plugin_mk1/version.py similarity index 84% rename from version.py rename to ovos_PHAL_plugin_mk1/version.py index ea4e38a..be3eeb2 100644 --- a/version.py +++ b/ovos_PHAL_plugin_mk1/version.py @@ -1,6 +1,6 @@ # START_VERSION_BLOCK VERSION_MAJOR = 0 -VERSION_MINOR = 0 +VERSION_MINOR = 1 VERSION_BUILD = 0 VERSION_ALPHA = 1 # END_VERSION_BLOCK From 743088f08a34327c7ac36f328dc42f2603055311 Mon Sep 17 00:00:00 2001 From: miro Date: Mon, 9 Sep 2024 23:27:41 +0100 Subject: [PATCH 08/10] unused files --- .github/workflows/build_tests.yml | 2 +- .github/workflows/dev2master.yml | 20 ---------- scripts/remove_alpha.py | 26 ------------- scripts/update_version.py | 65 ------------------------------- 4 files changed, 1 insertion(+), 112 deletions(-) delete mode 100644 .github/workflows/dev2master.yml delete mode 100644 scripts/remove_alpha.py delete mode 100644 scripts/update_version.py diff --git a/.github/workflows/build_tests.yml b/.github/workflows/build_tests.yml index 049c97d..b857af1 100644 --- a/.github/workflows/build_tests.yml +++ b/.github/workflows/build_tests.yml @@ -34,7 +34,7 @@ jobs: - name: Build Distribution Packages run: | python setup.py bdist_wheel - - name: Install skill + - name: Install repo run: | pip install . - uses: pypa/gh-action-pip-audit@v1.0.8 diff --git a/.github/workflows/dev2master.yml b/.github/workflows/dev2master.yml deleted file mode 100644 index 1528f2c..0000000 --- a/.github/workflows/dev2master.yml +++ /dev/null @@ -1,20 +0,0 @@ -# This workflow will generate a distribution and upload it to PyPI - -name: Push dev -> master -on: - workflow_dispatch: - -jobs: - build_and_publish: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. - ref: dev - - name: Push dev -> master - uses: ad-m/github-push-action@master - - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: master diff --git a/scripts/remove_alpha.py b/scripts/remove_alpha.py deleted file mode 100644 index ccb5e6b..0000000 --- a/scripts/remove_alpha.py +++ /dev/null @@ -1,26 +0,0 @@ -""" -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 deleted file mode 100644 index e6897ef..0000000 --- a/scripts/update_version.py +++ /dev/null @@ -1,65 +0,0 @@ -""" -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)) From b7af3e2d2ed1f151a969a6a704ed44eaf3a8a5b8 Mon Sep 17 00:00:00 2001 From: miro Date: Mon, 9 Sep 2024 23:29:35 +0100 Subject: [PATCH 09/10] version from file --- setup.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f2f001f..1e74b05 100755 --- a/setup.py +++ b/setup.py @@ -1,10 +1,37 @@ #!/usr/bin/env python3 +from os.path import join, dirname + from setuptools import setup + +def get_version(): + """ Find the version of this skill""" + version_file = join(dirname(__file__), 'ovos_PHAL_plugin_mk1/version.py') + major, minor, build, alpha = (None, None, None, None) + with open(version_file) as f: + for line in f: + if 'VERSION_MAJOR' in line: + major = line.split('=')[1].strip() + elif 'VERSION_MINOR' in line: + minor = line.split('=')[1].strip() + elif 'VERSION_BUILD' in line: + build = line.split('=')[1].strip() + elif 'VERSION_ALPHA' in line: + alpha = line.split('=')[1].strip() + + if ((major and minor and build and alpha) or + '# END_VERSION_BLOCK' in line): + break + version = f"{major}.{minor}.{build}" + if int(alpha): + version += f"a{alpha}" + return version + + PLUGIN_ENTRY_POINT = 'ovos-phal-mk1=ovos_PHAL_plugin_mk1:MycroftMark1' setup( name='ovos-PHAL-plugin-mk1', - version='0.0.1a5', + version=get_version(), description='A PHAL plugin for mycroft', url='https://github.com/OpenVoiceOS/ovos-PHAL-plugin-mk1', author='JarbasAi', From e51f528ed721189386fd8c266eca5cdcf10b6e91 Mon Sep 17 00:00:00 2001 From: miro Date: Mon, 9 Sep 2024 23:35:20 +0100 Subject: [PATCH 10/10] use requirements.txt --- requirements.txt | 4 ++++ setup.py | 21 ++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3144922 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +ovos-plugin-manager>=0.0.24 +ovos-mark1-utils>=0.0.0a2 +ovos-utils>=0.0.38 +pyserial~=3.0 \ No newline at end of file diff --git a/setup.py b/setup.py index 1e74b05..479eba7 100755 --- a/setup.py +++ b/setup.py @@ -1,12 +1,26 @@ #!/usr/bin/env python3 +import os from os.path import join, dirname from setuptools import setup +BASEDIR = os.path.abspath(os.path.dirname(__file__)) + + +def required(requirements_file): + """ Read requirements file and remove comments and empty lines. """ + with open(os.path.join(BASEDIR, requirements_file), 'r') as f: + requirements = f.read().splitlines() + if 'MYCROFT_LOOSE_REQUIREMENTS' in os.environ: + print('USING LOOSE REQUIREMENTS!') + requirements = [r.replace('==', '>=').replace('~=', '>=') for r in requirements] + return [pkg for pkg in requirements + if pkg.strip() and not pkg.startswith("#")] + def get_version(): """ Find the version of this skill""" - version_file = join(dirname(__file__), 'ovos_PHAL_plugin_mk1/version.py') + version_file = join(BASEDIR, 'ovos_PHAL_plugin_mk1/version.py') major, minor, build, alpha = (None, None, None, None) with open(version_file) as f: for line in f: @@ -38,10 +52,7 @@ def get_version(): author_email='jarbasai@mailfence.com', license='Apache-2.0', packages=['ovos_PHAL_plugin_mk1'], - install_requires=["ovos-plugin-manager>=0.0.24", - "ovos-mark1-utils>=0.0.0a2", - "ovos-utils>=0.0.38", - "pyserial~=3.0"], + install_requires=required("requirements.txt"), zip_safe=True, classifiers=[ 'Development Status :: 3 - Alpha',