commit compras1 3011
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-30 09:33:36 +02:00
parent 96b30368bc
commit 47649bd46c
163 changed files with 9419 additions and 145 deletions
+61
View File
@@ -0,0 +1,61 @@
"""Install the authorised access correction in the same selected Compras installation."""
from pathlib import Path
import hashlib
import json
import os
import shutil
import subprocess
import zipfile
root = Path('/var/www/compras-deploy/current').resolve()
assert root == Path('/var/www/compras-deploy/releases/presentation-20261129')
old = json.loads((root/'compras-release.json').read_text())
assert old['release_id'] == 'compras-a2711a98b34fceb3'
subprocess.run(['/usr/bin/php', str(root/'scripts/verify-compras-release.php'), str(root), '--installed'], check=True)
archive = Path('/root/compras-release-access.zip')
assert hashlib.sha256(archive.read_bytes()).hexdigest() == '1d1ca615ea9fe2bf4a3247f073f7be0f8ef12e305244df7e281999713c0c49e9'
z = zipfile.ZipFile(archive)
new = json.loads(z.read('compras-release.json'))
assert new['release_id'] == 'compras-e5c8c140738b6e1e'
assert old['components'] == new['components']
assert set(old['source_files']) == set(new['source_files'])
changed = [n for n in new['source_files'] if new['source_files'][n] != old['source_files'][n]]
assert set(changed) == {'routes/web.php', 'resources/js/pages/auth/login.tsx', 'resources/js/pages/home.tsx', 'resources/js/components/sgc-workspace-shell.tsx'}
backup = Path('/var/backups/compras-presentation-20261129/access-fix')
backup.mkdir(mode=0o700, exist_ok=False)
paths = changed + ['public/build/manifest.json', 'public/build/fonts-manifest.json', 'compras-release.json']
for name in paths:
dest = backup/name
dest.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(root/name, dest)
def write(name, data):
assert not Path(name).is_absolute() and '..' not in Path(name).parts
dest = root/name
assert not dest.is_symlink()
dest.parent.mkdir(parents=True, exist_ok=True)
temp = dest.with_name(dest.name+'.access-next')
temp.write_bytes(data)
temp.chmod(0o644)
os.replace(temp, dest)
try:
for name in changed:
write(name, z.read(name))
for name in new['frontend']['files']:
target = 'public/build/'+name
if (root/target).exists():
assert (root/target).read_bytes() == z.read(target), 'Immutable asset collision'
else:
write(target, z.read(target))
for name in ['public/build/fonts-manifest.json', 'public/build/manifest.json', 'compras-release.json']:
write(name, z.read(name))
subprocess.run(['/usr/bin/php', str(root/'scripts/verify-compras-release.php'), str(root), '--installed'], check=True)
except BaseException:
for name in paths:
write(name, (backup/name).read_bytes())
raise
proof = {'state': 'installed', 'release_id': new['release_id'], 'previous_release_id': old['release_id'],
'changed_files': changed, 'backup': str(backup), 'data_settings_permissions_changed': False,
'guest_root': '/login', 'authenticated_root': '/dashboard', 'public_presentation': '/apresentacao',
'public_screens_preserved_with_visible_login': True}
(backup/'result.json').write_text(json.dumps(proof, indent=2)+'\n')
print(json.dumps(proof))