From 72de96d7e0ab982edc3a3dce3947527dc71718c4 Mon Sep 17 00:00:00 2001 From: Stefanie Jane Date: Mon, 12 Aug 2024 18:53:41 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Add=20release=20management=20scr?= =?UTF-8?q?ipt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .github/workflows/release.xml | 4 +- package-lock.json | 6 +-- package.json | 4 +- scripts/release.py | 85 +++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 7 deletions(-) create mode 100755 scripts/release.py diff --git a/.github/workflows/release.xml b/.github/workflows/release.xml index 0b198f0..6e086ee 100644 --- a/.github/workflows/release.xml +++ b/.github/workflows/release.xml @@ -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 diff --git a/package-lock.json b/package-lock.json index 84df78c..44d9f8f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,13 @@ { "name": "hyper-light-card", - "version": "1.0.0", + "version": "0.8.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "hyper-light-card", - "version": "1.0.0", - "license": "MIT", + "version": "0.8.0", + "license": "Apache 2.0", "devDependencies": { "@babel/core": "^7.24.9", "@babel/plugin-transform-typescript": "^7.25.0", diff --git a/package.json b/package.json index ee28410..a629172 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/scripts/release.py b/scripts/release.py new file mode 100755 index 0000000..cc9c6d3 --- /dev/null +++ b/scripts/release.py @@ -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()