Skip to content

Commit

Permalink
ci: adds release script to update version in manifest on release
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Aug 29, 2024
1 parent 27a1d1c commit 5e06284
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -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
76 changes: 76 additions & 0 deletions .github/scripts/updata_hacs_manifest.py
Original file line number Diff line number Diff line change
@@ -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()
39 changes: 39 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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 [email protected]
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/[email protected]
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
2 changes: 1 addition & 1 deletion custom_components/dual_smart_thermostat/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.b07"
}

0 comments on commit 5e06284

Please sign in to comment.