import os import shutil import json import subprocess from pathlib import Path # Resolve project root dynamically relative to this script's directory (tools/) ROOT = Path(__file__).resolve().parent.parent DEPLOY_DIR = ROOT / "Temp" / "gas_deploy" GAS_FILES = [ "gas_data_feed.gs", "gas_data_collect.gs", "gas_lib.gs", "gas_harness_rows.gs", "gas_report.gs", "gas_event_calendar.gs", "gas_apex_alpha_watch.gs", "gas_apex_runtime_core.gs" ] def main(): print(f"Preparing deployment directory: {DEPLOY_DIR}") if DEPLOY_DIR.exists(): shutil.rmtree(DEPLOY_DIR) DEPLOY_DIR.mkdir(parents=True, exist_ok=True) # 1. Copy appsscript.json manifest manifest_src = ROOT / "src" / "gas_adapter_parts" / "appsscript.json" if manifest_src.exists(): shutil.copy(manifest_src, DEPLOY_DIR / "appsscript.json") print(f"Copied appsscript.json from {manifest_src}") else: # Create default manifest manifest = { "timeZone": "Asia/Seoul", "dependencies": {}, "exceptionLogging": "STACKDRIVER", "runtimeVersion": "V8" } with open(DEPLOY_DIR / "appsscript.json", "w", encoding="utf-8") as f: json.dump(manifest, f, ensure_ascii=False, indent=2) print("Created default appsscript.json") # 2. Copy GAS files from ROOT to DEPLOY_DIR copied_count = 0 for gf in GAS_FILES: src = ROOT / gf if src.exists(): shutil.copy(src, DEPLOY_DIR / gf) print(f"Copied {gf}") copied_count += 1 else: print(f"WARNING: Source file not found: {gf}") # 3. Create/Overwrite .clasp.json with DEPLOY_DIR as rootDir clasp_cfg = { "scriptId": "1xfeBAeeknmnBtSvrIqWXO_2hc3ByeriLUOSuOOB4YxLLHhN3zdnL7tVh", "rootDir": str(DEPLOY_DIR.relative_to(ROOT)) } with open(ROOT / ".clasp.json", "w", encoding="utf-8") as f: json.dump(clasp_cfg, f, ensure_ascii=False, indent=2) print(f"Updated .clasp.json with rootDir={clasp_cfg['rootDir']}") # 4. Run clasp push with shell=True for Windows compatibility print("Running npx @google/clasp push -f ...") env = dict(os.environ) res = subprocess.run( ["npx", "@google/clasp", "push", "-f"], cwd=str(ROOT), env=env, shell=True, capture_output=True, text=True, encoding="utf-8", errors="replace" ) print(f"Return code: {res.returncode}") print("STDOUT:") print(res.stdout) print("STDERR:") print(res.stderr) if res.returncode == 0: print("GAS deploy completed successfully!") else: print("GAS deploy failed!") exit(1) if __name__ == "__main__": main()