|
12 | 12 | type: boolean |
13 | 13 |
|
14 | 14 | jobs: |
| 15 | + development-bundle: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + contents: write |
| 19 | + |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v5 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Set up Python for the standard-library bundle tools |
| 26 | + uses: actions/setup-python@v6 |
| 27 | + with: |
| 28 | + python-version: '3.11' |
| 29 | + |
| 30 | + - name: Build the exact source development bundle |
| 31 | + env: |
| 32 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 33 | + run: | |
| 34 | + python - <<'PY' |
| 35 | + import os |
| 36 | + import subprocess |
| 37 | + import sys |
| 38 | + from pathlib import Path |
| 39 | +
|
| 40 | + output = Path(os.environ["RUNNER_TEMP"]) / "tnfr-development-bundle" |
| 41 | + output.mkdir() |
| 42 | + command = [ |
| 43 | + sys.executable, "scripts/build_development_bundle.py", |
| 44 | + "--revision", "HEAD", "--output-dir", str(output), |
| 45 | + ] |
| 46 | + tag = os.environ.get("RELEASE_TAG") |
| 47 | + if tag: |
| 48 | + command.extend(["--expected-tag", tag]) |
| 49 | + result = subprocess.run(command, check=True, capture_output=True, text=True) |
| 50 | + (output / "build-receipt.json").write_text(result.stdout, encoding="utf-8") |
| 51 | + print(result.stdout) |
| 52 | + PY |
| 53 | +
|
| 54 | + - name: Verify the extracted development bundle |
| 55 | + run: | |
| 56 | + python - <<'PY' |
| 57 | + import os |
| 58 | + import subprocess |
| 59 | + import sys |
| 60 | + import tempfile |
| 61 | + import zipfile |
| 62 | + from pathlib import Path |
| 63 | +
|
| 64 | + output = Path(os.environ["RUNNER_TEMP"]) / "tnfr-development-bundle" |
| 65 | + archives = list(output.glob("TNFR-*-light-development.zip")) |
| 66 | + if len(archives) != 1: |
| 67 | + raise SystemExit("Expected exactly one development bundle") |
| 68 | + archive = archives[0] |
| 69 | + with tempfile.TemporaryDirectory(prefix="tnfr-extracted-") as directory: |
| 70 | + with zipfile.ZipFile(archive) as bundle: |
| 71 | + bundle.extractall(directory) |
| 72 | + root = Path(directory) / archive.stem |
| 73 | + subprocess.run([ |
| 74 | + sys.executable, "scripts/development_bundle_evidence.py", "verify", |
| 75 | + ], cwd=root, check=True) |
| 76 | + PY |
| 77 | +
|
| 78 | + - name: Retain the development bundle and build receipt |
| 79 | + uses: actions/upload-artifact@v4 |
| 80 | + with: |
| 81 | + name: tnfr-development-bundle |
| 82 | + path: ${{ runner.temp }}/tnfr-development-bundle/* |
| 83 | + if-no-files-found: error |
| 84 | + retention-days: 14 |
| 85 | + |
| 86 | + - name: Attach the development bundle to the published release |
| 87 | + if: github.event_name == 'release' |
| 88 | + env: |
| 89 | + GH_TOKEN: ${{ github.token }} |
| 90 | + GH_REPO: ${{ github.repository }} |
| 91 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 92 | + run: | |
| 93 | + python - <<'PY' |
| 94 | + import hashlib |
| 95 | + import json |
| 96 | + import os |
| 97 | + import subprocess |
| 98 | + import tempfile |
| 99 | + from pathlib import Path |
| 100 | + from urllib.parse import quote |
| 101 | +
|
| 102 | + tag = os.environ["RELEASE_TAG"] |
| 103 | + repository = os.environ["GH_REPO"] |
| 104 | + output = Path(os.environ["RUNNER_TEMP"]) / "tnfr-development-bundle" |
| 105 | + archives = list(output.glob("TNFR-*-light-development.zip")) |
| 106 | + if len(archives) != 1: |
| 107 | + raise SystemExit("Expected exactly one development bundle") |
| 108 | + archive = archives[0] |
| 109 | + payloads = [archive, archive.with_name(archive.name + ".sha256")] |
| 110 | + result = subprocess.run([ |
| 111 | + "gh", "api", f"repos/{repository}/releases/tags/{quote(tag, safe='')}", |
| 112 | + ], check=True, capture_output=True, text=True) |
| 113 | + release = json.loads(result.stdout) |
| 114 | + existing = {asset["name"]: asset for asset in release["assets"]} |
| 115 | + missing = [] |
| 116 | + for path in payloads: |
| 117 | + expected = hashlib.sha256(path.read_bytes()).hexdigest() |
| 118 | + asset = existing.get(path.name) |
| 119 | + if asset is None: |
| 120 | + missing.append(str(path)) |
| 121 | + continue |
| 122 | + actual = asset.get("digest") |
| 123 | + if actual is None: |
| 124 | + with tempfile.TemporaryDirectory(prefix="tnfr-release-asset-") as directory: |
| 125 | + subprocess.run([ |
| 126 | + "gh", "release", "download", tag, "--repo", repository, |
| 127 | + "--pattern", path.name, "--dir", directory, |
| 128 | + ], check=True) |
| 129 | + downloaded = Path(directory) / path.name |
| 130 | + actual = "sha256:" + hashlib.sha256(downloaded.read_bytes()).hexdigest() |
| 131 | + if asset["size"] != path.stat().st_size or actual != "sha256:" + expected: |
| 132 | + raise SystemExit(f"Existing release asset differs: {path.name}") |
| 133 | + print(f"Verified existing release asset: {path.name}") |
| 134 | + if missing: |
| 135 | + subprocess.run([ |
| 136 | + "gh", "release", "upload", tag, *missing, "--repo", repository, |
| 137 | + ], check=True) |
| 138 | + PY |
| 139 | +
|
15 | 140 | pypi-publish: |
16 | 141 | runs-on: ubuntu-latest |
17 | 142 | permissions: |
|
0 commit comments