From 0c9a3e45ae880b671aa39c4a87f3b122f6980f47 Mon Sep 17 00:00:00 2001 From: peterino2 Date: Sun, 12 Oct 2025 15:24:57 -0700 Subject: [PATCH] big rework on automation.py and staging game builds now --- .github/workflows/build.yml | 10 ++-- .gitignore | 3 ++ lib/tracy/build.zig | 2 +- tools/scripts/automation.py | 101 +++++++++++++++++++++++++++++------- 4 files changed, 89 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 966c709..97d7421 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,7 @@ name: Build Projects on: push: - branches: [ main, integration, dev/**] + branches: [ main, integration] pull_request: branches: [ main, integration ] @@ -14,14 +14,10 @@ jobs: target: - zig: x86_64-linux-gnu os: self-hosted-linux - zipCommand: tar -cvfz - zipName: package.tar.xz - python: $PYTHON_NAME + python: python3 - zig: x86_64-windows os: self-hosted-windows - zipCommand: zip - zipName: package.zip - python: %PYTHON_NAME% + python: python steps: - name: Checkout repository diff --git a/.gitignore b/.gitignore index 699b498..ac45b6e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ .zig-cache/ zig-out/ +staging/ +zig-out-debug/ +zig-out-release/ *Saved/* .modulecache/ diff --git a/lib/tracy/build.zig b/lib/tracy/build.zig index 8ef8368..41ae3a7 100644 --- a/lib/tracy/build.zig +++ b/lib/tracy/build.zig @@ -11,7 +11,7 @@ pub fn build(b: *std.Build) void { //const tracy_enabled = b.option(bool, "tracy", "Enables tracy integration") orelse false; - const tracy_enabled: bool = true; //if (b.graph.env_map.hash_map.get("WITH_TRACY") != null) true else false; + const tracy_enabled: bool = false; //if (b.graph.env_map.hash_map.get("WITH_TRACY") != null) true else false; // if (b.graph.env_map.hash_map.get("WITH_TRACY")) |with_tracy| { // tracy_enabled = with_tracy; // } diff --git a/tools/scripts/automation.py b/tools/scripts/automation.py index 64c792d..538095d 100644 --- a/tools/scripts/automation.py +++ b/tools/scripts/automation.py @@ -1,5 +1,7 @@ import os import argparse +import shutil +import sys import subprocess orig_dir = os.path.abspath(os.path.dirname(__file__)) @@ -14,45 +16,100 @@ def getCommitHash(): dryRun = False -def run(cmd): +def run(cmd, cwd=None): global dryRun print(" ".join(cmd)) + c = os.getcwd() + + if cwd is not None: + c = cwd + if not dryRun: - print(subprocess.check_output(cmd, shell=True).decode()) + print(subprocess.check_output(" ".join(cmd), shell=True, cwd=c).decode(), file=sys.stderr) 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']) + run(['zig', 'env']) + run(['zig', 'build', f'-Dtarget={target}', '--prefix', 'zig-out-debug', 'install']) + run(['zig', 'build', f'-Dtarget={target}', '-Dstatic_build', '-Doptimize=ReleaseSafe', '--prefix', 'zig-out-release', 'install']) + if deploy is not None: + host = '$BACKLOG_INFRA_DEPLOY_HOST' + path = '$BACKLOG_INFRA_DEPLOY_PATH' + + if os.name == 'nt': + host = '%BACKLOG_INFRA_DEPLOY_HOST%' + path = '%BACKLOG_INFRA_DEPLOY_PATH%' + + sampleGameDeploy = f'{path}/sampleGame/{branch}/{deploy}' + binariesDeploy = f'{path}/binaries/{branch}/{deploy}' + def makePackage(target, branch, deploy, tag): - host = '$BACKLOG_INFRA_DEPLOY_HOST' - path = '$BACKLOG_INFRA_DEPLOY_PATH' + + + run(['ssh', host, f'mkdir -p {binariesDeploy}']) + run(['ssh', host, f'mkdir -p {sampleGameDeploy}']) 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' + packageFile = f'binaries-{deploy}-{tag}-{target}.zip' run(['zip', '-r', '-7', packageFile, f'zig-out-{tag}']) - run(['scp', packageFile, f'{host}:{path}/{branch}/{deploy}/{packageFile}']) + run(['scp', packageFile, f'{host}:{binariesDeploy}/{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}']) + packageFile = f'binaries-{deploy}-{tag}-{target}.tar.xz' + run(['tar', '-cvzf', os.path.abspath(packageFile), '-C', f'zig-out-{tag}']) + run(['scp', packageFile, f'{host}:{binariesDeploy}/{packageFile}']) + + os.makedirs(f'staging/sampleGame/{tag}', exist_ok=True) + + excludeList = [ + 'headless.exe', + 'headless.pdb', + 'newProject.exe', + 'newProject.pdb', + 'toolbox.exe', + 'toolbox.pdb' + ] + + for f in os.listdir(f'zig-out-{tag}/bin'): + shutil.copy(os.path.join(f'zig-out-{tag}/bin', f), f"staging/sampleGame/{tag}/") + + if os.path.exists(f'zig-out-{tag}/modules'): + os.makedirs('staging/sampleGame/zig-out/modules', exist_ok=True) + for f in os.listdir(f'zig-out-{tag}/modules'): + print("module: ", f, os.path.join(f'zig-out-{tag}/modules', f)) + shutil.copy(os.path.join(f'zig-out-{tag}/modules', f), f"staging/sampleGame/zig-out/modules/" + f) + + makePackage(target, branch, deploy, 'debug') makePackage(target, branch, deploy, 'release') + # stage content + if os.path.exists('staging/sampleGame/content'): + shutil.rmtree('staging/sampleGame/content', ignore_errors=False, onerror=None) + + shutil.copytree('content', 'staging/sampleGame/content') + + if os.name == 'nt': + packageFile = f'sampleGame-{deploy}-{target}.zip' + run(['zip', '-r', '-7', os.path.abspath(packageFile), f'.'], cwd=os.path.join(os.getcwd(), 'staging/sampleGame')) + run(['scp', packageFile, f'{host}:{sampleGameDeploy}/{packageFile}']) + else: + packageFile = f'sampleGame-{deploy}-{target}.tar.xz' + run(['tar', '-cvzf', os.path.abspath(packageFile), '-C', f'staging/sampleGame']) + run(['scp', packageFile, f'{host}:{sampleGameDeploy}/{packageFile}']) + + + run(['zig', 'build', f'-Dtarget={target}', 'run-headless']) + run(['zig', 'build', f'-Dtarget={target}', '-Dstatic_build','run-headless']) + run(['zig', 'build', f'-Dtarget={target}', '-Dslow_logging','run-headless']) + 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('--deploy', nargs="?", help='tag for the deployment') parser.add_argument('--branch', default="manual", help='branch name') parser.add_argument('--dry', action="store_true", help='dont run anything') @@ -63,5 +120,11 @@ if __name__ == "__main__": if args.dry: dryRun = True - buildAndPackage(args.branch, args.target, args.deploy) + + def cleanBranchName(branch): + + return branch.replace('/', '_') + + b = cleanBranchName(args.branch) + buildAndPackage(b, args.target, args.deploy)