From 83c613065800d76dcfd6dcd4ca6acc6c10889f64 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 29 Aug 2024 09:10:40 +0000 Subject: [PATCH] ci: adds release script to update version in manifest on release --- .github/FUNDING.yml | 2 + .github/scripts/updata_hacs_manifest.py | 76 +++++++++++++++++++ .github/workflows/release.yaml | 39 ++++++++++ .../dual_smart_thermostat/manifest.json | 2 +- 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 .github/FUNDING.yml create mode 100644 .github/scripts/updata_hacs_manifest.py create mode 100644 .github/workflows/release.yaml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..db61a49 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=S6NC9BYVDDJMA&source=url +custom: https://www.buymeacoffee.com/swingerman \ No newline at end of file diff --git a/.github/scripts/updata_hacs_manifest.py b/.github/scripts/updata_hacs_manifest.py new file mode 100644 index 0000000..6bf839b --- /dev/null +++ b/.github/scripts/updata_hacs_manifest.py @@ -0,0 +1,76 @@ +"""Update the manifest file.""" + +import json +import os +import sys + + +def update_manifest(): + """Update the manifest file.""" + version = "0.0.0" + manifest_path = False + dorequirements = False + + for index, value in enumerate(sys.argv): + if value in ["--version", "-V"]: + version = str(sys.argv[index + 1]).replace("v", "") + if value in ["--path", "-P"]: + manifest_path = str(sys.argv[index + 1])[1:-1] + if value in ["--requirements", "-R"]: + dorequirements = True + + if not manifest_path: + sys.exit("Missing path to manifest file") + + with open( + f"{os.getcwd()}/{manifest_path}/manifest.json", + encoding="UTF-8", + ) as manifestfile: + manifest = json.load(manifestfile) + + manifest["version"] = version + + if dorequirements: + requirements = [] + with open( + f"{os.getcwd()}/requirements.txt", + encoding="UTF-8", + ) as file: + for line in file: + requirements.append(line.rstrip()) + + new_requirements = [] + for requirement in requirements: + req = requirement.split("==")[0].lower() + new_requirements = [ + requirement + for x in manifest["requirements"] + if x.lower().startswith(req) + ] + new_requirements += [ + x for x in manifest["requirements"] if not x.lower().startswith(req) + ] + manifest["requirements"] = new_requirements + + with open( + f"{os.getcwd()}/{manifest_path}/manifest.json", + "w", + encoding="UTF-8", + ) as manifestfile: + manifestfile.write( + json.dumps( + { + "domain": manifest["domain"], + "name": manifest["name"], + **{ + k: v + for k, v in sorted(manifest.items()) + if k not in ("domain", "name") + }, + }, + indent=4, + ) + ) + + +update_manifest() diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..4366930 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,39 @@ +name: Release + +on: + workflow_dispatch: + release: + types: [published] + +env: + COMPONENT_DIR: dual_smart_thermostat + +jobs: + release_zip_file: + name: Prepare release asset + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + - name: Update manifest.json version to ${{ github.event.release.tag_name }} + run: | + python3 ${{ github.workspace }}/.github/scripts/update_hacs_manifest.py --version ${{ github.event.release.tag_name }} --path /custom_components/dual_smart_thermostat/ + - name: Commit manifest update + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git add ./custom_components/dual_smart_thermostat/manifest.json + git commit -m "Updated manifest.json" + git push origin HEAD:master + - name: Create zip + run: | + cd custom_components/dual_smart_thermostat + zip dual_smart_thermostat.zip -r ./ + - name: Upload zip to release + uses: svenstaro/upload-release-action@2.9.0 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ./custom_components/dual_smart_thermostat/dual_smart_thermostat.zip + asset_name: dual_smart_thermostat.zip + tag: ${{ github.ref }} + overwrite: true \ No newline at end of file diff --git a/custom_components/dual_smart_thermostat/manifest.json b/custom_components/dual_smart_thermostat/manifest.json index e48ef54..c8b04fa 100644 --- a/custom_components/dual_smart_thermostat/manifest.json +++ b/custom_components/dual_smart_thermostat/manifest.json @@ -13,5 +13,5 @@ "iot_class": "local_polling", "issue_tracker": "https://github.com/swingerman/ha-dual-smart-thermostat/issues", "requirements": [], - "version": "v0.9.8.beta-7" + "version": "v0.9.8" } \ No newline at end of file