-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: adds release script to update version in manifest on release
- Loading branch information
=
committed
Aug 29, 2024
1 parent
27a1d1c
commit 83c6130
Showing
4 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters