diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 474ceca3575e..2f1fac96a6a3 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -70,13 +70,20 @@ jobs: pushd . cd build/android && printf "y" | ./build.sh presubmit-with-archive arm64-v8a popd + - id: get_commit_msg + uses: ./.github/actions/get-commit-msg - name: Check artifact sizes run: | python3 test/sizeguard/dump_artifact_size.py out/*.aar > current_size.json + BYPASS_ARG="" + if python3 test/sizeguard/check_bypass.py ${{ steps.get_commit_msg.outputs.hash }}; then + BYPASS_ARG="--bypass" + fi python3 test/sizeguard/check_size.py current_size.json \ --target-branch origin/main \ --threshold 20480 \ - --artifacts filament-android-release.aar/jni/arm64-v8a/libfilament-jni.so + --artifacts filament-android-release.aar/jni/arm64-v8a/libfilament-jni.so \ + $BYPASS_ARG build-ios: name: build-iOS diff --git a/docs_src/build/duplicates.json b/docs_src/build/duplicates.json index 28d9e8376b9a..6e49f55cf538 100644 --- a/docs_src/build/duplicates.json +++ b/docs_src/build/duplicates.json @@ -100,6 +100,9 @@ "test/backend/README.md": { "dest": "dup/test_ci_backend.md" }, + "test/sizeguard/README.md": { + "dest": "dup/test_ci_sizeguard.md" + }, "filament/backend/test/README.md": { "dest": "dup/backend_test.md" } diff --git a/docs_src/src_mdbook/src/SUMMARY.md b/docs_src/src_mdbook/src/SUMMARY.md index 19ec5699f716..81b5a18191b4 100644 --- a/docs_src/src_mdbook/src/SUMMARY.md +++ b/docs_src/src_mdbook/src/SUMMARY.md @@ -33,6 +33,7 @@ - [backend](./dup/backend_test.md) - [CI: backend](./dup/test_ci_backend.md) - [CI: renderdiff](./dup/test_ci_renderdiff.md) + - [CI: sizeguard](./dup/test_ci_sizeguard.md) - [Libraries](./notes/libs.md) - [bluegl](./dup/bluegl.md) - [bluevk](./dup/bluevk.md) diff --git a/test/sizeguard/README.md b/test/sizeguard/README.md new file mode 100644 index 000000000000..2970f2f9ea6d --- /dev/null +++ b/test/sizeguard/README.md @@ -0,0 +1,37 @@ +# Sizeguard + +This directory contains scripts used to monitor and gate the size of Filament artifacts. + +## Scripts + +### `dump_artifact_size.py` +Computes the sizes of build artifacts (e.g., `.aar`, `.tgz`) and their internal contents. It outputs a JSON representation of these sizes. + +**Usage:** +```bash +python3 dump_artifact_size.py out/*.aar > current_size.json +``` + +### `check_size.py` +Compares a current size JSON (generated by `dump_artifact_size.py`) against historical data stored in the `filament-assets` repository. It fails if any artifact's size increase exceeds a specified threshold. + +**Key Arguments:** +- `current_json`: Path to the local JSON file. +- `--threshold`: Size increase threshold in bytes (default: 20KB). +- `--bypass`: If provided, the script will print the comparison but exit successfully even if thresholds are exceeded. + +### `check_bypass.py` +A utility script that checks the commit message for a specific tag to determine if the sizeguard check should be bypassed. + +**Usage:** +- Returns exit code `0` if the tag `SIZEGUARD_BYPASS` is found in the commit message. +- Returns exit code `1` otherwise. + +## Continuous Integration + +These scripts are integrated into the GitHub Actions workflows (e.g., `.github/workflows/presubmit.yml`). + +To bypass a failing sizeguard check in a PR, add the following tag on a new line in your commit message: +``` +SIZEGUARD_BYPASS +``` diff --git a/test/sizeguard/check_bypass.py b/test/sizeguard/check_bypass.py new file mode 100755 index 000000000000..d46fa163dee4 --- /dev/null +++ b/test/sizeguard/check_bypass.py @@ -0,0 +1,47 @@ +# Copyright (C) 2026 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#!/usr/bin/env python3 + +import subprocess +import sys + +def commit_msg_has_tag(commit_hash, tag): + try: + result = subprocess.run( + ['git', 'log', '-n1', '--pretty=%B', commit_hash], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + check=True, + text=True + ) + for line in result.stdout.split('\n'): + if tag == line.strip(): + return True + return False + except subprocess.CalledProcessError as e: + print(f"Error reading commit message: {e}", file=sys.stderr) + return False + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("Usage: check_bypass.py ", file=sys.stderr) + sys.exit(1) + + commit_hash = sys.argv[1] + + if commit_msg_has_tag(commit_hash, "SIZEGUARD_BYPASS"): + sys.exit(0) + else: + sys.exit(1) diff --git a/test/sizeguard/check_size.py b/test/sizeguard/check_size.py index a908fe608cf8..b83ef5d14180 100644 --- a/test/sizeguard/check_size.py +++ b/test/sizeguard/check_size.py @@ -103,6 +103,10 @@ def main(): "--artifacts", nargs="+", help="List of artifact paths to check (e.g. 'foo.aar' or 'foo.aar/lib/arm64/bar.so')." ) + parser.add_argument( + "--bypass", action="store_true", + help="Bypass the size threshold check and exit successfully." + ) args = parser.parse_args() @@ -179,7 +183,10 @@ def main(): print("-" * 110) - if failures: + if args.bypass: + print("SUCCESS: Size guard test has been bypassed via commit message tag.") + sys.exit(0) + elif failures: print(f"FAILURE: {len(failures)} artifacts exceeded threshold of {args.threshold} bytes.") sys.exit(1) else: