50 lines
2.9 KiB
Python
50 lines
2.9 KiB
Python
from datetime import datetime, timezone
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import re
|
|
|
|
root = Path(__file__).resolve().parent
|
|
manifest = json.loads((root / 'manifest.json').read_text(encoding='utf-8'))
|
|
build = json.loads((root / 'build-result.json').read_text(encoding='utf-8-sig'))
|
|
for key in ('typecheck_exit', 'build_exit', 'public_config_exit', 'token_verify_exit'):
|
|
assert build[key] == 0, (key, build[key])
|
|
for key in ('frozen_files_unchanged', 'public_source_files_unchanged', 'previous_outputs_unchanged', 'environment_files_absent'):
|
|
assert build[key] is True, key
|
|
assert build['error'] is None
|
|
test_log = (root / 'frontend-test.log').read_text(encoding='utf-8-sig')
|
|
tests = int(re.search(r'tests (\d+)', test_log).group(1))
|
|
passed = int(re.search(r'pass (\d+)', test_log).group(1))
|
|
failed = int(re.search(r'fail (\d+)', test_log).group(1))
|
|
assert tests == passed and failed == 0
|
|
|
|
def sha(path):
|
|
return hashlib.sha256(Path(path).read_bytes()).hexdigest()
|
|
|
|
output = Path(build['output'])
|
|
files = [{'relative_path': path.relative_to(output).as_posix(), 'size': path.stat().st_size, 'sha256': sha(path)}
|
|
for path in sorted(output.rglob('*')) if path.is_file()]
|
|
output_manifest = root / 'build-output-manifest.json'
|
|
output_manifest.write_text(json.dumps({'output': str(output), 'file_count': len(files), 'files': files},
|
|
ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
|
for item in manifest['files']:
|
|
item['source_sha256_now'] = sha(item['source_path'])
|
|
item['source_unchanged'] = item['source_sha256_now'] == item['before_sha256']
|
|
assert item['source_unchanged'], item['source_path']
|
|
assert sha(item['payload_path']) == item['after_sha256'], item['payload_path']
|
|
assert sha(item['snapshot_path']) == item['after_sha256'], item['snapshot_path']
|
|
manifest.update({
|
|
'status': 'ready', 'source_files_unchanged': True, 'dependencies_installed': False, 'deployed': False,
|
|
'verification': {'frontend': {'passed': passed, 'failed': failed, 'log': str(root / 'frontend-test.log')},
|
|
'build_result': str(root / 'build-result.json'), 'typecheck_exit': 0, 'build_exit': 0,
|
|
'public_config_exit': 0, 'token_verify_exit': 0},
|
|
'build_output': str(output), 'output_file_count': len(files),
|
|
'output_manifest': str(output_manifest), 'output_manifest_sha256': sha(output_manifest),
|
|
'completed_at': datetime.now(timezone.utc).isoformat(),
|
|
})
|
|
(root / 'manifest.json').write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
|
summary = {key: manifest[key] for key in ('status', 'verification', 'build_output', 'output_file_count', 'output_manifest_sha256')}
|
|
summary['payload_manifest_sha256'] = sha(root / 'manifest.json')
|
|
(root / 'result.json').write_text(json.dumps(summary, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
|
print(json.dumps(summary, ensure_ascii=False))
|