68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
import os
|
|
import argparse
|
|
import subprocess
|
|
|
|
orig_dir = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
def getCommitHash():
|
|
commit_hash = subprocess.check_output(
|
|
['git', 'rev-parse', '--short', 'HEAD'],
|
|
text=True
|
|
).strip()
|
|
print(commit_hash)
|
|
|
|
|
|
dryRun = False
|
|
|
|
def run(cmd):
|
|
global dryRun
|
|
print(" ".join(cmd))
|
|
if not dryRun:
|
|
print(subprocess.check_output(cmd, shell=True).decode())
|
|
|
|
def buildAndPackage(branch, target, deploy):
|
|
run(['zig', 'build', 'install', f'-Dtarget={target}', '--prefix', 'zig-out-debug'])
|
|
run(['zig', 'build', 'install', f'-Dtarget={target}', '-Dstatic_build', '-Doptimize=ReleaseSafe', '--prefix', 'zig-out-release'])
|
|
|
|
if deploy is not None:
|
|
def makePackage(target, branch, deploy, tag):
|
|
host = '$BACKLOG_INFRA_DEPLOY_HOST'
|
|
path = '$BACKLOG_INFRA_DEPLOY_PATH'
|
|
|
|
if os.name == 'nt':
|
|
host = '%BACKLOG_INFRA_DEPLOY_HOST%'
|
|
path = '%BACKLOG_INFRA_DEPLOY_PATH%'
|
|
|
|
run(['ssh', host, f'mkdir -p {path}/{branch}/{deploy}'])
|
|
|
|
if os.name == 'nt':
|
|
packageFile = f'{deploy}-{tag}-{target}.zip'
|
|
run(['zip', '-r', '-7', packageFile, f'zig-out-{tag}'])
|
|
run(['scp', packageFile, f'{host}:{path}/{branch}/{deploy}/{packageFile}'])
|
|
else:
|
|
packageFile = f'{deploy}-{tag}.tar.xz'
|
|
run(['tar', '-cvzf', packageFile, f'zig-out-{tag}'])
|
|
run(['scp', packageFile, f'{host}:{path}/{branch}/{deploy}/{packageFile}'])
|
|
|
|
makePackage(target, branch, deploy, 'debug')
|
|
makePackage(target, branch, deploy, 'release')
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description='run automation tasks for the repo')
|
|
|
|
# Positional argument (required)
|
|
parser.add_argument('--deploy', nargs="?", help='Path to the input file')
|
|
parser.add_argument('--branch', default="manual", help='branch name')
|
|
parser.add_argument('--dry', action="store_true", help='dont run anything')
|
|
|
|
parser.add_argument('target', help='required')
|
|
|
|
|
|
args = parser.parse_args()
|
|
if args.dry:
|
|
dryRun = True
|
|
|
|
buildAndPackage(args.branch, args.target, args.deploy)
|
|
|