Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kjarosh committed Aug 8, 2024
1 parent 9723cb0 commit 654fc76
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions .github/scripts/release.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#!/usr/bin/env python3
import contextlib
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 ==========================================

Expand All @@ -19,23 +23,34 @@ def get_current_day_id():


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(f"{variable}={value}")
f.write(line + '\n')


def log(msg):
print(msg, file=sys.stderr)


# ===== Commands to execute ================================

def run_command(args):
return subprocess.run(args, check=True, stdout=subprocess.PIPE).stdout.decode('utf-8')
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'])
return run_command(['cargo', 'get', 'workspace.package.version']).strip()


def cargo_set_version(args):
run_command(['cargo', 'set-version', '--exclude swf', *args])
run_command(['cargo', 'set-version', '--exclude', 'swf', *args])


# ===== Commands ===========================================
Expand All @@ -46,26 +61,29 @@ def bump(mode):
"""

current_version = cargo_get_version()
log(f'Current version: {current_version}, bumping with mode {mode}')

if mode == 'nightly':
version_4part = f"current_version.{get_current_day_id()}"
version_4part = f'{current_version}.{get_current_day_id()}'
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()}"])
cargo_set_version([f'{next_planned_version}-nightly.{get_current_time_version()}'])
else:
cargo_set_version(['--bump', mode])
version_4part = cargo_get_version()

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)
github_output('version_4part', version_4part)

run_command(['npm', 'install', '--global', 'workspace-version'])
run_command(['npm', 'version', version])
run_command(['workspace-version'])


def commit():
commit_message = f'Release {cargo_get_version()}'
Expand Down Expand Up @@ -109,16 +127,14 @@ def release(channel):


def main():
if len(sys.argv) == 0:
exit(1)

cmd = sys.argv[0]
cmd = sys.argv[1]
log(f'Running command {cmd}')
if cmd == 'bump':
bump(sys.argv[1])
bump(sys.argv[2])
elif cmd == 'commit':
commit()
elif cmd == 'release':
release(sys.argv[1])
release(sys.argv[2])


if __name__ == "__main__":
Expand Down

0 comments on commit 654fc76

Please sign in to comment.