Skip to content

Commit

Permalink
Add build size verification script
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Nov 27, 2024
1 parent 76d8b65 commit c5f4316
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
15 changes: 14 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,26 @@ jobs:
waiting_room:
name: Waiting Room
runs-on: ubuntu-latest
needs: [conda_build, pip_install, npm_build, cdn_build]
needs: [conda_build, pip_install, npm_build, cdn_build, verify_sizes]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
environment:
name: publish
steps:
- run: echo "All builds have finished, have been approved, and ready to publish"

verify_sizes:
name: Verify sizes
runs-on: ubuntu-latest
needs: [conda_build, pip_build, npm_build, cdn_build]
env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}"
- RUN_ID: ${{ github.run_id }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "1"
- run: pipx run scripts/verify_build_sizes.py $RUN_ID

pixi_lock:
name: Pixi lock
runs-on: ubuntu-latest
Expand Down
49 changes: 49 additions & 0 deletions scripts/verify_build_sizes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# /// script
# dependencies = ["requests"]
# ///
import os
import sys

import requests

PACKAGE = "panel"


EXPECTED_SIZES_MB = {
"npm": 25,
"pip": 60, # sdist + wheel
"cdn": 30,
"conda": 25,
}

HEADERS = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {os.environ['GITHUB_TOKEN']}",
"X-GitHub-Api-Version": "2022-11-28",
}


def main(run_number: int):
url = f"https://api.github.com/repos/holoviz/{PACKAGE}/actions/workflows/build.yaml/runs"
resp = requests.get(url, headers=HEADERS, timeout=20)
assert resp.ok

for run in resp.json()["workflow_runs"]:
if run["run_number"] == run_number:
break

assert run["run_number"] == run_number, "Run number not found!"

artifact_url = run["url"] + "/artifacts"
artifact_resp = requests.get(artifact_url, headers=HEADERS, timeout=20)
assert artifact_resp.ok

sizes = {v["name"]: v["size_in_bytes"] for v in artifact_resp.json()["artifacts"]}

print(sizes)
for k, v in EXPECTED_SIZES_MB.items():
assert sizes[k] < v * 1024**2, f"{k} artifact ({sizes[k] / 1024**2:0.2f} MB) larger than {v} MB."


if __name__ == "__main__":
main(int(sys.argv[1]))

0 comments on commit c5f4316

Please sign in to comment.