-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create workflow to prepare new releases
- Loading branch information
1 parent
2e922af
commit 41fb02e
Showing
2 changed files
with
94 additions
and
0 deletions.
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,17 @@ | ||
name: Generate new release (manual) | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: "New Version (without leading v)" | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
generate-release: | ||
name: Generate new release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- run: "scripts/release.py ${{ github.event.inputs.version }})" |
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,77 @@ | ||
#!/usr/bin/env python3 | ||
# Run in root of repository | ||
# scripts/release.py <version number> | ||
|
||
import sys | ||
import json | ||
import subprocess | ||
from datetime import datetime | ||
|
||
CHANGELOG_FILE = "CHANGELOG.md" | ||
MAIN_CPP_FILE = "src/main.cpp" | ||
PACKAGE_JSON_FILE = "editors/code/package.json" | ||
|
||
assert len(sys.argv) == 2, "Usage: scripts/release.py <version number>" | ||
VERSION = sys.argv[1] | ||
|
||
CHANGELOG_DATE = datetime.now().strftime("%Y-%m-%d") | ||
|
||
# Update version in CHANGELOG.md | ||
new_changelog_lines: list[str] = [] | ||
with open(CHANGELOG_FILE, "r") as file: | ||
lines = file.readlines() | ||
|
||
for line in lines: | ||
new_changelog_lines.append(line) | ||
if line.startswith("## [Unreleased]"): | ||
new_changelog_lines.append("\n") | ||
new_changelog_lines.append(f"## [{VERSION}] - {CHANGELOG_DATE}") | ||
new_changelog_lines.append("\n") | ||
|
||
with open(CHANGELOG_FILE, "w") as file: | ||
file.writelines(new_changelog_lines) | ||
|
||
# Update version in main.cpp | ||
new_main_cpp_lines: list[str] = [] | ||
with open(MAIN_CPP_FILE, "r") as file: | ||
lines = file.readlines() | ||
|
||
for line in lines: | ||
if line.strip().startswith('argparse::ArgumentParser program("luau-lsp", '): | ||
new_line = ( | ||
line[0 : line.find(line.strip())] | ||
+ f'argparse::ArgumentParser program("luau-lsp", "{VERSION}");\n' | ||
) | ||
new_main_cpp_lines.append(new_line) | ||
else: | ||
new_main_cpp_lines.append(line) | ||
|
||
with open(MAIN_CPP_FILE, "w") as file: | ||
file.writelines(new_main_cpp_lines) | ||
|
||
# Update version in package.json | ||
package_json_data = None | ||
with open(PACKAGE_JSON_FILE, "r") as t: | ||
package_json_data = json.load(t) | ||
package_json_data["version"] = VERSION | ||
|
||
with open(PACKAGE_JSON_FILE, "w") as t: | ||
json.dump(package_json_data, t) | ||
|
||
# Run prettier | ||
subprocess.run( | ||
["npx", "prettier", "--write", CHANGELOG_FILE, PACKAGE_JSON_FILE], check=True | ||
) | ||
|
||
# Commit | ||
subprocess.run( | ||
["git", "add", CHANGELOG_FILE, MAIN_CPP_FILE, PACKAGE_JSON_FILE], check=True | ||
) | ||
subprocess.run(["git", "commit", "-m", f"v{VERSION}"], check=True) | ||
|
||
# Tag | ||
subprocess.run(["git", "tag", "-a", VERSION, "-m", VERSION], check=True) | ||
|
||
# Push | ||
subprocess.run(["git", "push"], check=True) | ||
subprocess.run(["git", "push", "--tags"], check=True) |