Skip to content

Commit

Permalink
🔧 Add release management script
Browse files Browse the repository at this point in the history
Add Python script for automated release process

Implement version updates, changelog management, and GitHub
release creation. Script updates package.json, CHANGELOG.md,
and hacs.json files, commits changes, creates a new tag, and
pushes to GitHub.

Update package.json to set initial version to 0.8.0.
  • Loading branch information
hyperb1iss committed Aug 13, 2024
1 parent 3202c02 commit 72de96d
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/hyper-light-card-bundle.js
asset_name: hyper-light-card-bundle.js
asset_path: ./dist/hyper-light-card.js
asset_name: hyper-light-card.js
asset_content_type: application/javascript
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hyper-light-card",
"version": "1.0.0",
"version": "0.8.0",
"description": "A custom Lovelace card for Home Assistant to control SignalRGB",
"main": "dist/hyper-light-card.js",
"module": "dist/hyper-light-card.js",
Expand All @@ -15,7 +15,7 @@
"test:watch": "jest --watch",
"copy:hass": "node scripts/copy-to-hass.js",
"dev": "npm run build:dev && npm run copy:hass",
"build:hacs": "rollup -c --environment BUILD:production && cp dist/hyper-light-card.js dist/hyper-light-card-bundle.js"
"build:hacs": "rollup -c --environment BUILD:production"
},
"keywords": [
"home-assistant",
Expand Down
85 changes: 85 additions & 0 deletions scripts/release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python3

import os
import re
import subprocess
import sys
from datetime import datetime

import json
import semver
from github import Github

# Configuration
REPO_NAME = "hyperb1iss/hyper-light-card"
MAIN_FILE = "src/hyper-light-card.ts"
CHANGELOG_FILE = "CHANGELOG.md"
HACS_MANIFEST = "hacs.json"


def get_current_version():
with open("package.json", "r") as file:
package_json = json.load(file)
return package_json.get("version")


def update_version(new_version):
with open("package.json", "r+") as file:
package_json = json.load(file)
package_json["version"] = new_version
file.seek(0)
json.dump(package_json, file, indent=2)
file.truncate()


def commit_and_push(version):
subprocess.run(["git", "add", MAIN_FILE, CHANGELOG_FILE, HACS_MANIFEST])
subprocess.run(["git", "commit", "-m", f":bookmark: Bump version to {version}"])
subprocess.run(["git", "push"])
subprocess.run(["git", "tag", f"v{version}"])
subprocess.run(["git", "push", "--tags"])


def create_github_release(version, changelog_entry):
g = Github(os.environ.get("GITHUB_TOKEN"))
repo = g.get_repo(REPO_NAME)
repo.create_git_release(
f"v{version}",
f"Release {version}",
changelog_entry,
draft=False,
prerelease=False,
)


def main():
current_version = get_current_version()
if not current_version:
print("Error: Couldn't find current version.")
sys.exit(1)

print(f"Current version: {current_version}")
new_version = input("Enter new version: ")

try:
semver.parse(new_version)
except ValueError:
print("Error: Invalid semantic version.")
sys.exit(1)

update_version(new_version)

print(
"Changes made. Please review and press Enter to commit and push, or Ctrl+C to abort."
)
input()

commit_and_push(new_version)

create_github_release(new_version, changelog_entry)

print(f"Version {new_version} has been released!")


if __name__ == "__main__":
main()

0 comments on commit 72de96d

Please sign in to comment.