forked from ruffle-rs/ruffle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11b03e2
commit 0eecf74
Showing
3 changed files
with
297 additions
and
73 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,131 @@ | ||
#!/usr/bin/env python3 | ||
import os | ||
import subprocess | ||
import sys | ||
from datetime import datetime | ||
|
||
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
REPO_DIR = os.path.realpath(os.path.join(SCRIPT_DIR, '../../')) | ||
|
||
|
||
# ===== Utilities ========================================== | ||
|
||
def get_current_time_version(): | ||
now = datetime.now() | ||
return f"{now.year}.{now.month}.{now.day}" | ||
|
||
|
||
def github_output(variable, value): | ||
line = f"{variable}={value}" | ||
print(line) | ||
if 'GITHUB_OUTPUT' in os.environ: | ||
with open(os.environ['GITHUB_OUTPUT'], 'a') as f: | ||
f.write(line + '\n') | ||
|
||
|
||
def log(msg): | ||
print(msg, file=sys.stderr) | ||
|
||
|
||
# ===== Commands to execute ================================ | ||
|
||
def run_command(args, cwd=REPO_DIR): | ||
return subprocess.run( | ||
args, | ||
cwd=cwd, | ||
check=True, | ||
stdout=subprocess.PIPE, | ||
).stdout.decode('utf-8') | ||
|
||
|
||
def cargo_get_version(): | ||
return run_command(['cargo', 'get', 'workspace.package.version']).strip() | ||
|
||
|
||
def cargo_set_version(args): | ||
run_command(['cargo', 'set-version', '--exclude', 'swf', *args]) | ||
|
||
|
||
# ===== Commands =========================================== | ||
|
||
def bump(mode): | ||
""" | ||
Bump the current version of Ruffle according to the mode, which may be one of: nightly, major, minor, patch. | ||
""" | ||
|
||
current_version = cargo_get_version() | ||
log(f'Current version: {current_version}, bumping with mode {mode}') | ||
|
||
if mode == 'nightly': | ||
cargo_set_version(['--bump', 'minor']) | ||
next_planned_version = cargo_get_version() | ||
run_command(['git', 'reset', '--hard', 'HEAD']) | ||
cargo_set_version([f'{next_planned_version}-nightly.{get_current_time_version()}']) | ||
else: | ||
cargo_set_version(['--bump', mode]) | ||
|
||
version = cargo_get_version() | ||
|
||
npm_dir = f'{REPO_DIR}/web' | ||
run_command(['npm', 'install', 'workspace-version'], cwd=npm_dir) | ||
run_command(['npm', 'version', '--no-git-tag-version', version], cwd=npm_dir) | ||
run_command(['./node_modules/workspace-version/dist/index.js'], cwd=npm_dir) | ||
|
||
github_output('current-version', current_version) | ||
github_output('version', version) | ||
|
||
|
||
def commit(): | ||
commit_message = f'Release {cargo_get_version()}' | ||
run_command(['git', 'config', 'user.name', 'RuffleBuild']) | ||
run_command(['git', 'config', 'user.email', 'ruffle@ruffle.rs']) | ||
|
||
run_command(['git', 'add', '--update']) | ||
run_command(['git', 'commit', '-m', commit_message]) | ||
|
||
|
||
def release(channel): | ||
""" | ||
Create a release of Ruffle on GitHub. | ||
""" | ||
|
||
if channel == 'nightly': | ||
now = datetime.now() | ||
current_time_dashes = now.strftime("%Y-%m-%d") | ||
current_time_underscores = now.strftime("%Y_%m_%d") | ||
|
||
tag_name = f"nightly-{current_time_dashes}" | ||
release_name = f"Nightly {current_time_dashes}" | ||
package_prefix = f"ruffle-nightly-{current_time_underscores}" | ||
release_options = ['--generate-notes', '--prerelease'] | ||
else: | ||
version = cargo_get_version() | ||
tag_name = f"v{version}" | ||
release_name = f"Release {version}" | ||
package_prefix = f"ruffle-{version}" | ||
release_options = [] | ||
|
||
release_commit = run_command(['git', 'rev-parse', 'HEAD']).strip() | ||
run_command([ | ||
'gh', 'release', 'create', tag_name, | ||
'--title', release_name, | ||
'--target', release_commit, | ||
*release_options]) | ||
|
||
github_output('tag_name', tag_name) | ||
github_output('package_prefix', package_prefix) | ||
|
||
|
||
def main(): | ||
cmd = sys.argv[1] | ||
log(f'Running command {cmd}') | ||
if cmd == 'bump': | ||
bump(sys.argv[2]) | ||
elif cmd == 'commit': | ||
commit() | ||
elif cmd == 'release': | ||
release(sys.argv[2]) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.