From 69dda2e8e3ec36d0be2c2f56cbcb394e7caef961 Mon Sep 17 00:00:00 2001 From: VasilyZa <450270247@qq.com> Date: Fri, 4 Dec 2026 16:56:57 +0800 Subject: [PATCH] fix(ci): parse Pages size before checking the limit --- scripts/ci/publish-pages.sh | 8 +++++--- tools/tests/test_ci.py | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/scripts/ci/publish-pages.sh b/scripts/ci/publish-pages.sh index f5ebf3f1..f120f8a9 100644 --- a/scripts/ci/publish-pages.sh +++ b/scripts/ci/publish-pages.sh @@ -46,9 +46,11 @@ case $operation in make O="$output" pages bash scripts/ci/restore-rpr.sh retain "$output" [[ $(<"$output/pages/rpr/source-commit") == "$GITHUB_SHA" ]] - [[ $(stat -c %s -- "$iso") -lt 2147483648 ]] || { echo 'Installer exceeds the GitHub Release asset limit' >&2; exit 1; } - size=$(du --apparent-size --bytes -s -- "$output/pages") - [[ ${size%%[[:space:]]*} -le 1000000000 ]] || { echo 'Production site exceeds the GitHub Pages 1 GB limit' >&2; exit 1; } + iso_bytes=$(stat -c %s -- "$iso") + test "$iso_bytes" -lt 2147483648 || { echo 'Installer exceeds the GitHub Release asset limit' >&2; exit 1; } + pages_usage=$(du --apparent-size --bytes -s -- "$output/pages") + IFS=$'\t' read -r pages_bytes _ <<< "$pages_usage" + test "$pages_bytes" -le 1000000000 || { echo 'Production site exceeds the GitHub Pages 1 GB limit' >&2; exit 1; } ;; upload) tag=$(<"$tag_file") diff --git a/tools/tests/test_ci.py b/tools/tests/test_ci.py index 53f24386..c3535cfd 100644 --- a/tools/tests/test_ci.py +++ b/tools/tests/test_ci.py @@ -184,6 +184,46 @@ def run(command, root, *, check=True): self.assertIn("different commit", error.stderr) +class PublishPagesTests(unittest.TestCase): + def test_assemble_checks_site_and_installer_sizes(self): + checkout = Path(ci.__file__).resolve().parents[1] + with tempfile.TemporaryDirectory() as directory: + work = Path(directory) + output = work / "release output" + fingerprint = "A" * 40 + files = {"rpr-testing/current-" + fingerprint: "b" * 64 + "\n", + "pages/rpr/source-commit": SHA + "\n", + "images/reliefos-installer.iso": "installer"} + for name, contents in files.items(): + path = output / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(contents) + # Exercise the publisher's checks on prebuilt files without rebuilding them. + make = work / "make" + make.write_text("#!/bin/sh\nexit 0\n") + make.chmod(0o755) + env = dict(os.environ, PATH=f"{work}:{os.environ['PATH']}", GITHUB_SHA=SHA, + RPR_SIGNING_FINGERPRINT=fingerprint, GITHUB_REPOSITORY="ReliefOSProject/ReliefOS") + + def assemble(): + return subprocess.run(["bash", "scripts/ci/publish-pages.sh", "assemble", output], + cwd=checkout, env=env, capture_output=True, text=True) + + result = assemble() + self.assertEqual(result.returncode, 0, result.stderr) + + for path, size, message in ( + (output / "pages/large.bin", 1_000_000_001, "Production site exceeds"), + (output / "images/reliefos-installer.iso", 2_147_483_648, "Installer exceeds"), + ): + with self.subTest(path=path.name): + with path.open("wb") as stream: + stream.truncate(size) + result = assemble() + self.assertEqual(result.returncode, 1, result.stderr) + self.assertIn(message, result.stderr) + + class GateTests(unittest.TestCase): def needs(self, build=True, docs=True): result = {name: {"result": "success"} for name in ci.STAGES}