Skip to content

Commit 214e17f

Browse files
domr@qq.comdomr@qq.com
authored andcommitted
Verify actual published PHP downloads on real WSL2 after every release
1 parent 4812a4e commit 214e17f

2 files changed

Lines changed: 110 additions & 0 deletions

File tree

‎.github/jit/run_published.py‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python3
2+
"""Validate the exact public CLI/micro downloads, including on real WSL2."""
3+
import hashlib
4+
import io
5+
import json
6+
from pathlib import Path
7+
import subprocess
8+
import sys
9+
import tarfile
10+
import tempfile
11+
import time
12+
from urllib.request import Request, urlopen
13+
14+
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts'))
15+
from php_binary import current_jit_profile
16+
from php_releases import MANIFEST, validate_manifest
17+
18+
base = 'https://download.workerman.net/php/'
19+
stamp = time.time_ns()
20+
results = Path('validation/public-jit')
21+
results.mkdir(parents=True, exist_ok=True)
22+
23+
24+
def fetch(name, limit=80 * 1024 * 1024):
25+
request = Request(base + name + '?jit-verify=' + str(stamp), headers={'Cache-Control': 'no-cache'})
26+
with urlopen(request, timeout=180) as response:
27+
data = response.read(limit + 1)
28+
if len(data) > limit:
29+
raise RuntimeError('Oversized public download: ' + name)
30+
return data
31+
32+
33+
with tempfile.TemporaryDirectory(prefix='published-php-jit-') as temporary:
34+
root = Path(temporary)
35+
for release in validate_manifest(json.loads(MANIFEST.read_text())):
36+
branch, version = release['branch'], release['version']
37+
name = f'php-{branch}-linux-x86_64'
38+
info = json.loads(fetch(name + '.json', 128 * 1024))
39+
assert info['php_version'] == version and current_jit_profile(info), name + ': stale JIT profile'
40+
archive = name + '.tar.gz'
41+
expected = fetch(archive + '.sha256', 1024).decode().split()
42+
data = fetch(archive)
43+
assert expected == [hashlib.sha256(data).hexdigest(), archive], name + ': archive checksum mismatch'
44+
with tarfile.open(fileobj=io.BytesIO(data)) as bundle:
45+
assert bundle.getnames() == ['php']
46+
member = bundle.getmember('php')
47+
assert member.isfile() and member.size < 80 * 1024 * 1024
48+
binary = bundle.extractfile(member).read()
49+
assert hashlib.sha256(binary).hexdigest() == info['sha256'] and len(binary) == info['binary_bytes']
50+
cli = root / ('php' + branch)
51+
cli.write_bytes(binary)
52+
cli.chmod(0o755)
53+
cli_report = results / (branch + '-cli.json')
54+
subprocess.run(['python3', str(Path(__file__).with_name('run_checks.py')), '--php', str(cli),
55+
'--expect-jit', 'yes', '--output', str(cli_report)], check=True)
56+
assert json.loads(cli_report.read_text())['tracing']['php'] == version
57+
if branch == '8.5':
58+
subprocess.run(['python3', str(Path(__file__).with_name('run_checks.py')), '--php', str(cli),
59+
'--fixture', str(Path(__file__).with_name('repro-php85-jit.php')),
60+
'--jit-modes', 'tracing', '--expect-jit', 'yes',
61+
'--output', str(results / (branch + '-original-repro.json'))], check=True)
62+
micro_data = fetch('php' + branch + '.micro.sfx')
63+
assert hashlib.sha256(micro_data).hexdigest() == info['micro']['sha256']
64+
assert len(micro_data) == info['micro']['binary_bytes']
65+
micro = root / ('php' + branch + '.micro.sfx')
66+
micro.write_bytes(micro_data)
67+
micro_report = results / (branch + '-micro.json')
68+
subprocess.run(['python3', str(Path(__file__).with_name('run_micro_checks.py')), '--micro', str(micro),
69+
'--output', str(micro_report)], check=True)
70+
assert json.loads(micro_report.read_text())['disable']['php'] == version
71+
print('PUBLIC DOWNLOAD PASS:', name, version, flush=True)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Test public static PHP JIT on WSL2
2+
3+
on:
4+
workflow_run:
5+
workflows: [Build Self-Hosted PHP Binary (Unix)]
6+
types: [completed]
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
wsl:
14+
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success'
15+
runs-on: windows-2025
16+
timeout-minutes: 25
17+
steps:
18+
- shell: pwsh
19+
run: git config --global core.autocrlf false
20+
- uses: actions/checkout@v6
21+
- uses: Vampire/setup-wsl@d1da7f2c0322a5ee4f24975344f67fc0f5baf364
22+
with:
23+
distribution: Ubuntu-24.04
24+
wsl-version: '2'
25+
additional-packages: python3 ca-certificates
26+
- name: Test the actual public CLI and micro downloads
27+
shell: wsl-bash {0}
28+
run: |
29+
set -euo pipefail
30+
uname -a
31+
grep -qi microsoft /proc/version
32+
grep -qi wsl2 /proc/sys/kernel/osrelease
33+
python3 .github/jit/run_published.py
34+
- uses: actions/upload-artifact@v4
35+
if: always()
36+
with:
37+
name: public-php-jit-WSL2
38+
path: validation/public-jit/
39+
retention-days: 30

0 commit comments

Comments
 (0)