39 lines
3.4 KiB
Python
39 lines
3.4 KiB
Python
from pathlib import Path
|
|
import hashlib, json, shutil, subprocess, os
|
|
R=Path(__file__).resolve().parent.parent;P=R/'storage/app/private/investmoz-v2/portal-audit'
|
|
plan=json.loads((P/'onboarding-governance-plan.json').read_text());S=Path(plan['source'])
|
|
assert S.parent==P and S.name.startswith('onboarding-qa-') and plan['target']['port']==55441
|
|
file='resources/js/pages/profiles/administration.tsx'; dest=S/file; text=dest.read_text()
|
|
for value,label in [('role','Papel'),('organization','Âmbito organizacional')]:
|
|
before=''' <select
|
|
className={control}
|
|
value={'''+value+'''}'''
|
|
after=''' <select
|
|
aria-label="'''+label+'''"
|
|
className={control}
|
|
value={'''+value+'''}'''
|
|
assert text.count(before)==1;text=text.replace(before,after)
|
|
dest.write_text(text,encoding='utf-8')
|
|
plan['files'].append({'path':file,'before_sha256':hashlib.sha256((R/file).read_bytes()).hexdigest(),'after_sha256':hashlib.sha256(dest.read_bytes()).hexdigest()})
|
|
plan['files']=sorted(plan['files'],key=lambda row:row['path']);plan['previous_backend_delta']=plan['delta_sha256']
|
|
plan['delta_sha256']=hashlib.sha256(json.dumps(plan['files'],sort_keys=True).encode()).hexdigest()
|
|
plan['frontend_changes']=True;plan['production_build_required']=True
|
|
for file in ['package.json','package-lock.json','tsconfig.json','vite.config.ts','components.json']:
|
|
if (R/file).exists():shutil.copyfile(R/file,S/file)
|
|
task_stage=str(S/'node_modules').replace("'","''");task_modules=str(R/'node_modules').replace("'","''")
|
|
subprocess.run(['powershell.exe','-NoProfile','-Command',f"New-Item -ItemType Junction -Path '{task_stage}' -Target '{task_modules}' | Out-Null"],capture_output=True,check=True)
|
|
artisan=S/'artisan';text=artisan.read_text();assert text.count("require __DIR__.'/vendor/autoload.php';")==1
|
|
artisan.write_text(text.replace("require __DIR__.'/vendor/autoload.php';","require __DIR__.'/qa-autoload.php';"),encoding='utf-8')
|
|
env=dict(os.environ);env['PATH']='C:/laragon/bin/php/php-8.5.11-Win32-vs17-x64;C:/Users/macbook/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin;'+env.get('PATH','')
|
|
command=['C:/Users/macbook/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node.exe',str(R/'node_modules/vite-plus/bin/vp'),'build']
|
|
with (P/'onboarding-governance-production-build.log').open('w',encoding='utf-8') as log:
|
|
result=subprocess.run(command,cwd=S,env=env,stdout=log,stderr=subprocess.STDOUT,timeout=300)
|
|
plan['production_build_passed']=result.returncode==0
|
|
if result.returncode==0:
|
|
manifest=S/'public/build/manifest.json';plan['production_manifest_sha256']=hashlib.sha256(manifest.read_bytes()).hexdigest()
|
|
plan['assets']=[{'path':str(file.relative_to(S)).replace('\\','/'),'sha256':hashlib.sha256(file.read_bytes()).hexdigest()} for file in sorted((S/'public/build').rglob('*')) if file.is_file()]
|
|
assert all(not row['before_sha256'] or hashlib.sha256((R/row['path']).read_bytes()).hexdigest()==row['before_sha256'] for row in plan['files'])
|
|
(P/'onboarding-governance-plan.json').write_text(json.dumps(plan,indent=2),encoding='utf-8')
|
|
print(json.dumps({'result':'production_build_passed' if result.returncode==0 else 'production_build_stopped','delta':plan['delta_sha256'][:12],'files':len(plan['files']),'active_changes':0,'log':'onboarding-governance-production-build.log'}))
|
|
raise SystemExit(result.returncode)
|