sizeguard: add tag to bypass test (#9743)
This commit is contained in:
9
.github/workflows/presubmit.yml
vendored
9
.github/workflows/presubmit.yml
vendored
@@ -150,13 +150,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
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
@@ -44,6 +44,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)
|
||||
|
||||
37
test/sizeguard/README.md
Normal file
37
test/sizeguard/README.md
Normal file
@@ -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
|
||||
```
|
||||
47
test/sizeguard/check_bypass.py
Executable file
47
test/sizeguard/check_bypass.py
Executable file
@@ -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 <commit_hash>", 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)
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user