Files
Investidor-V2/outputs/investmoz-audit-current-20261012/run-B7-navigation-build.py
T
nala ba1c0340ea
tests / ci (push) Canceled after 0s
oportunidades 8
2026-10-14 08:25:30 +02:00

44 lines
3.1 KiB
Python

from pathlib import Path
from datetime import datetime,timezone
from zipfile import ZipFile,ZIP_DEFLATED
import hashlib,json,subprocess,os,shutil,sys
OUT=Path(__file__).resolve().parent;ROOT=OUT.parents[1]
q=ROOT/'storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742'
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
b2=True
before=q/'public/build';prepared=q/('public/build-B7-business-navigation-prepared'if b2 else'public/build-B-C139-prepared')
assert prepared.resolve().parent==(q/'public').resolve()and not prepared.exists()
backup=q/('storage/app/private/option-B7-navigation-build-before-20261013.zip'if b2 else'storage/app/private/option-B-build-before-20261013.zip');assert not backup.exists()
old_manifest=sha(before/'manifest.json');active_manifest=sha(ROOT/'public/build/manifest.json')
with ZipFile(backup,'w',ZIP_DEFLATED)as archive:
for p in before.rglob('*'):
if p.is_file():archive.write(p,str(p.relative_to(before)))
env=os.environ.copy();env['STABILITY_QA_MODE']='consumers';env['INVESTMOZ_QA_BUILD']='0'
env['PATH']='C:/laragon/bin/php/php-8.5.11-Win32-vs17-x64;C:/Program Files/nodejs;'+env.get('PATH','')
proof={'at':datetime.now(timezone.utc).isoformat(),'scope':'B','QA_source':str(q),'active_changes':0,
'old_QA_manifest':old_manifest,'private_backup_sha256':sha(backup),'visual_observed':False,'commands':[]}
try:
for name,args in [('types',['types:check']),('build',['build','--','--outDir',str(prepared.relative_to(q))])]:
result=subprocess.run(['C:/Program Files/nodejs/npm.cmd','run',*args],cwd=q,env=env,
capture_output=True,text=True,encoding='utf-8',errors='replace')
(OUT/f"{'option-B7-navigation'if b2 else'option-B'}-{name}-QA.log").write_text(result.stdout+result.stderr,encoding='utf-8')
proof['commands'].append({'script':name,'exit':result.returncode})
assert result.returncode==0
assert(prepared/'manifest.json').exists()and sha(before/'manifest.json')==old_manifest
for p in prepared.rglob('*'):
if not p.is_file()or p.name=='manifest.json':continue
destination=before/p.relative_to(prepared);destination.parent.mkdir(parents=True,exist_ok=True)
if destination.exists():assert sha(destination)==sha(p),'Immutable chunk differs'
else:shutil.copyfile(p,destination)
temporary=before/'manifest.option-B.pending';shutil.copyfile(prepared/'manifest.json',temporary)
assert sha(before/'manifest.json')==old_manifest
os.replace(temporary,before/'manifest.json')
assert sha(ROOT/'public/build/manifest.json')==active_manifest
proof.update(result='passed',new_QA_manifest=sha(before/'manifest.json'),production_build=True,
prepared_assets=sum(p.is_file()for p in prepared.rglob('*')),
old_assets_preserved=True,atomic_QA_manifest_switch=True,active_manifest_unchanged=True)
except Exception as error:proof.update(result='stopped',error_type=type(error).__name__)
(OUT/('option-B7-navigation-build-QA.json'if b2 else'option-B-build-QA.json')).write_text(json.dumps(proof,indent=2)+'\n',encoding='utf-8')
print(json.dumps(proof));raise SystemExit(0 if proof['result']=='passed'else 1)