-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workflow for publishing new releases (#325)
- Loading branch information
Showing
4 changed files
with
132 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,34 @@ | ||
name: Publish new release | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
publish: | ||
name: Update manifest and publish | ||
strategy: | ||
matrix: | ||
python-version: [3.8] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repository | ||
uses: actions/checkout@v2.3.4 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2.2.2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install Poetry | ||
uses: abatilo/actions-poetry@v2.1.2 | ||
with: | ||
poetry-version: 1.1.5 | ||
|
||
- name: Install dependencies | ||
run: poetry install | ||
|
||
- name: Run script | ||
run: | | ||
poetry run python script/publish_release.py | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,58 @@ | ||
#!/usr/bin/env python3 | ||
"""Update manifest.json and create new Github Release.""" | ||
from __future__ import annotations | ||
|
||
import json | ||
import os | ||
import sys | ||
|
||
from github import Github | ||
from github.ContentFile import ContentFile | ||
from github.GitRelease import GitRelease | ||
from github.Repository import Repository | ||
|
||
|
||
def main() -> int: | ||
"""Main function""" | ||
github_token = os.environ.get("GITHUB_TOKEN") | ||
print("Fetching draft release...") | ||
github = Github(github_token) | ||
repo = github.get_repo("leikoilja/ha-google-home") | ||
release = repo.get_releases()[0] | ||
if not release.draft: | ||
print("The latest release is not a draft!") | ||
return 1 | ||
version = release.title.lstrip("v") | ||
update_version(repo, version) | ||
publish_release(release) | ||
return 0 | ||
|
||
|
||
def update_version(repo: Repository, version: str) -> None: | ||
"""Update manifest.json with the new version""" | ||
print("Updating manifest.json...") | ||
manifest = repo.get_contents("custom_components/google_home/manifest.json") | ||
assert isinstance(manifest, ContentFile) | ||
manifest_json = json.loads(manifest.decoded_content) | ||
manifest_json["version"] = version | ||
updated_manifest = json.dumps(manifest_json, indent=2) + "\n" | ||
repo.update_file( | ||
path=manifest.path, | ||
message=f"Release v{version}", | ||
content=updated_manifest, | ||
sha=manifest.sha, | ||
) | ||
|
||
|
||
def publish_release(release: GitRelease) -> None: | ||
"""Publish draft release""" | ||
print("Publishing new release...") | ||
release.update_release( | ||
name=release.title, | ||
message=release.body, | ||
draft=False, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |