mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
Merge note (batch b5; pull_request_target spec-trace workflow has a startup_failure, so its checks run locally): - One Test run (47198949595) succeeded (go test (linux), process-level tests (real binaries)) on the integration tree 22da3420 = main 5bf18d62 + #1011 #1012 in this order; these squash merges reproduce that tree, verified after the last one. - spec-trace-check.sh and public-text-check.sh, run with main's scripts against this head and body: both exit 0. - Code review ACCEPT on 501f43f7: on a release tag the publish workflow takes the three Linux binaries unchanged out of the just-pushed image by digest, refuses dirty, unknown, lab-tagged or mismatched revisions, uploads the tarball and SHA256SUMS, sets the pre-release flag from the tag form on new and existing releases, and cleans up both owned resources while keeping the first failure. - Workflow review: publish workflow and its helper script reviewed at this exact head.
93 lines
5.4 KiB
Python
93 lines
5.4 KiB
Python
"""Exercise release packaging without Docker, GitHub writes or product builds."""
|
|
from pathlib import Path
|
|
import json, os, subprocess, tarfile, tempfile, unittest
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
REV = "a" * 40
|
|
DIGEST = "example.invalid/block@sha256:" + "b" * 64
|
|
|
|
class ReleaseAssets(unittest.TestCase):
|
|
def run_case(self, bad=None, mode="revision", existing=True, tag="v1.1.1",
|
|
docker_rm_rc=0, rm_rc=0, publish_rc=0):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root=Path(tmp); tools=root/"tools"; tools.mkdir(); image=root/"image"; image.mkdir()
|
|
expected={}
|
|
for name in ("blockmaster", "blockvolume", "sw-block"):
|
|
revision=REV; modified="false"; suffix=""; status=0
|
|
if bad == name:
|
|
if mode == "revision": revision="c"*40
|
|
elif mode == "dirty": modified="true"
|
|
elif mode == "unknown": revision="unknown"
|
|
elif mode == "lab": suffix=" LAB BUILD(example)"
|
|
elif mode == "provenance-failure": status=17
|
|
else: self.fail("invalid fixture mode")
|
|
data=(f"#!/bin/sh\necho '{name} revision={revision} modified={modified}{suffix}'\nexit {status}\n").encode()
|
|
(image/name).write_bytes(data); (image/name).chmod(0o755); expected[name]=data
|
|
log=root/"calls.jsonl"; state=root/"release.json"; state.write_text(json.dumps({"prerelease":"-" not in tag}))
|
|
common="""#!/usr/bin/env python3
|
|
import json,os,pathlib,shutil,sys
|
|
args=sys.argv[1:]
|
|
with open(os.environ['CALLS'],'a') as f: f.write(json.dumps([pathlib.Path(sys.argv[0]).name,*args])+chr(10))
|
|
"""
|
|
(tools/"docker").write_text(common+"""
|
|
if args[0]=='create': print('owned-container')
|
|
elif args[0]=='cp': shutil.copy2(pathlib.Path(os.environ['IMAGE'])/args[1].rsplit('/',1)[1],args[2])
|
|
elif args[0]=='rm': sys.exit(int(os.environ['DOCKER_RM_RC']))
|
|
""")
|
|
(tools/"rm").write_text(common+"""
|
|
if os.environ['RM_RC']!='0': sys.exit(int(os.environ['RM_RC']))
|
|
shutil.rmtree(args[-1])
|
|
""")
|
|
(tools/"gh").write_text(common+"""
|
|
if args[:2]==['release','view']: sys.exit(0 if os.environ['EXISTING']=='1' else 1)
|
|
if args[1] in ('edit','create'):
|
|
flag=next((a for a in args if a.startswith('--prerelease')), '--prerelease=false')
|
|
pathlib.Path(os.environ['STATE']).write_text(json.dumps({'prerelease':flag in ('--prerelease','--prerelease=true')}))
|
|
if args[1] in ('upload','create'): sys.exit(int(os.environ['PUBLISH_RC']))
|
|
""")
|
|
for tool in tools.iterdir(): tool.chmod(0o755)
|
|
out=root/"assets"
|
|
env=dict(os.environ,PATH=str(tools)+os.pathsep+os.environ['PATH'],CALLS=str(log),IMAGE=str(image),
|
|
EXISTING=str(int(existing)),STATE=str(state),GITHUB_REPOSITORY='example/block',
|
|
DOCKER_RM_RC=str(docker_rm_rc),RM_RC=str(rm_rc),PUBLISH_RC=str(publish_rc))
|
|
result=subprocess.run(['bash',str(HERE/'release-binary-assets.sh'),DIGEST,REV,tag,str(out)],
|
|
env=env,capture_output=True,text=True,timeout=15)
|
|
calls=[json.loads(line) for line in log.read_text().splitlines()] if log.exists() else []
|
|
primary=(17 if mode=='provenance-failure' else 1) if bad else publish_rc
|
|
self.assertEqual(result.returncode,primary or docker_rm_rc or rm_rc,result.stderr)
|
|
if bad:
|
|
self.assertFalse(any(c[0]=='gh' for c in calls),calls)
|
|
self.assertFalse((out/'SHA256SUMS').exists())
|
|
elif not publish_rc:
|
|
archive=out/f'sw-block-{tag}-linux-amd64.tar.gz'
|
|
with tarfile.open(archive) as tar:
|
|
self.assertEqual(set(tar.getnames()),set(expected))
|
|
for name,data in expected.items(): self.assertEqual(tar.extractfile(name).read(),data)
|
|
subprocess.run(['sha256sum','--check','SHA256SUMS'],cwd=out,check=True,capture_output=True)
|
|
command='upload' if existing else 'create'
|
|
self.assertTrue(any(c[:3]==['gh','release',command] for c in calls),calls)
|
|
self.assertEqual(json.loads(state.read_text())['prerelease'],'-' in tag)
|
|
self.assertEqual(calls[0],['docker','pull',DIGEST])
|
|
self.assertIn(['docker','create',DIGEST],calls)
|
|
self.assertEqual(calls[-2],['docker','rm','owned-container'])
|
|
self.assertEqual(calls[-1][:4],['rm','-rf','--',calls[-1][-1]])
|
|
if not rm_rc: self.assertFalse(Path(calls[-1][-1]).exists())
|
|
|
|
def test_release_kind_on_create_and_existing(self):
|
|
for existing in (False,True):
|
|
for tag in ('v1.1.1','v1.1.1-rc1'):
|
|
with self.subTest(existing=existing,tag=tag): self.run_case(existing=existing,tag=tag)
|
|
|
|
def test_every_binary_refuses_invalid_provenance(self):
|
|
for name in ('blockmaster','blockvolume','sw-block'):
|
|
for mode in ('revision','dirty','unknown','lab','provenance-failure'):
|
|
with self.subTest(binary=name,mode=mode): self.run_case(bad=name,mode=mode)
|
|
|
|
def test_cleanup_preserves_primary_error_and_tries_both(self):
|
|
self.run_case(publish_rc=37,docker_rm_rc=41,rm_rc=43)
|
|
self.run_case(bad='blockmaster',mode='provenance-failure',docker_rm_rc=41,rm_rc=43)
|
|
self.run_case(docker_rm_rc=41)
|
|
self.run_case(rm_rc=43)
|
|
|
|
if __name__=='__main__': unittest.main()
|