Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions scripts/ci/publish-pages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
40 changes: 40 additions & 0 deletions tools/tests/test_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down