Skip to content

Commit 1cd4861

Browse files
authored
github: add scripts to store size of android release artifact (#9705)
- Add a script to test/sizeguard to compute sizes of artifacts within a compressed file. - Add a step to postsubmit-main.yml that will run the above script on every commit to main. This will enable us to add a presubmit step to guard against dramatic size increases in the Android build.
1 parent 89c3b3f commit 1cd4861

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

.github/workflows/postsubmit-main.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
- main
77

88
jobs:
9+
# Update the renderdiff goldens in filament-assets. This will add or merge the new goldens from
10+
# a branch on filament-assets.
911
update-renderdiff-goldens:
1012
name: update-renderdiff-goldens
1113
runs-on: 'ubuntu-24.04-4core'
@@ -35,6 +37,7 @@ jobs:
3537
--merge-to-main --filament-tag=${COMMIT_HASH} --golden-repo-token=${GH_TOKEN}
3638
fi
3739
40+
# Update the /docs (offiicla github-hosted Filament site) if necessary
3841
update-docs:
3942
name: update-docs
4043
runs-on: 'ubuntu-24.04-4core'
@@ -57,3 +60,40 @@ jobs:
5760
git config --global user.name "Filament Bot"
5861
git config --global credential.helper cache
5962
bash docs_src/build/postsubmit.sh ${COMMIT_HASH} ${GH_TOKEN}
63+
64+
# Produce a json that describes the android artifact sizes, and will push that json to a folder in
65+
# filament-assets
66+
update-sizeguard:
67+
name: update-sizeguard
68+
runs-on: 'ubuntu-24.04-16core'
69+
steps:
70+
- uses: actions/checkout@v4.1.6
71+
with:
72+
fetch-depth: 0
73+
- uses: ./.github/actions/linux-prereq
74+
- uses: actions/setup-java@v3
75+
with:
76+
distribution: 'temurin'
77+
java-version: '17'
78+
- id: get_commit_msg
79+
uses: ./.github/actions/get-commit-msg
80+
- name: Build and generate size report
81+
run: |
82+
cd build/android && printf "y" | ./build.sh release all
83+
cd ../..
84+
COMMIT_HASH="${{ steps.get_commit_msg.outputs.hash }}"
85+
python3 test/sizeguard/dump_artifact_size.py out/*.tgz out/*.aar > "${COMMIT_HASH}.json"
86+
- name: Push to filament-assets
87+
env:
88+
GH_TOKEN: ${{ secrets.FILAMENTBOT_TOKEN }}
89+
run: |
90+
COMMIT_HASH="${{ steps.get_commit_msg.outputs.hash }}"
91+
git config --global user.email "filament.bot@gmail.com"
92+
git config --global user.name "Filament Bot"
93+
git clone https://x-access-token:${GH_TOKEN}@github.com/google/filament-assets.git filament-assets
94+
mkdir -p filament-assets/sizeguard
95+
mv "${COMMIT_HASH}.json" filament-assets/sizeguard/
96+
cd filament-assets
97+
git add sizeguard/"${COMMIT_HASH}.json"
98+
git commit -m "Update sizeguard for filament@${COMMIT_HASH}" || echo "No changes to commit"
99+
git push https://x-access-token:${GH_TOKEN}@github.com/google/filament-assets.git main
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Copyright (C) 2026 The Android Open Source Project
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#!/usr/bin/env python3
16+
17+
import os
18+
import sys
19+
import zipfile
20+
import tarfile
21+
import json
22+
import argparse
23+
24+
# Hardcoded list of library extensions to track
25+
LIB_EXTENSIONS = ('.a', '.jar', '.so')
26+
27+
def get_archive_content(path):
28+
"""
29+
Extracts metadata for library files within a compressed archive.
30+
Returns a list of dicts with 'name' and 'size' (uncompressed).
31+
"""
32+
content = []
33+
34+
# .aar and .zip are both handled by zipfile
35+
if path.endswith(('.zip', '.aar')):
36+
with zipfile.ZipFile(path, 'r') as z:
37+
for info in z.infolist():
38+
# info.is_dir() is available in Python 3.6+
39+
if not info.is_dir() and info.filename.endswith(LIB_EXTENSIONS):
40+
content.append({
41+
"name": info.filename,
42+
"size": info.file_size
43+
})
44+
45+
# .tgz or .tar.gz handled by tarfile
46+
elif path.endswith(('.tgz', '.tar.gz')):
47+
with tarfile.open(path, 'r:gz') as t:
48+
for member in t.getmembers():
49+
if member.isfile() and member.name.endswith(LIB_EXTENSIONS):
50+
content.append({
51+
"name": member.name,
52+
"size": member.size
53+
})
54+
else:
55+
raise ValueError(f"Unsupported archive format: {path}")
56+
57+
return content
58+
59+
def main():
60+
parser = argparse.ArgumentParser(description="Dump sizes of library files inside archives as JSON.")
61+
parser.add_argument('archives', nargs='+', help='List of compressed archives (.aar, .tgz, .zip)')
62+
args = parser.parse_args()
63+
64+
results = []
65+
66+
for archive_path in args.archives:
67+
if not os.path.exists(archive_path):
68+
print(f"Error: File not found: {archive_path}", file=sys.stderr)
69+
sys.exit(1)
70+
71+
try:
72+
archive_full_size = os.path.getsize(archive_path)
73+
inner_content = get_archive_content(archive_path)
74+
75+
# Sort the content list alphabetically by name
76+
inner_content.sort(key=lambda x: x['name'])
77+
78+
results.append({
79+
"name": os.path.basename(archive_path),
80+
"size": archive_full_size,
81+
"content": inner_content
82+
})
83+
except Exception as e:
84+
print(f"Error processing {archive_path}: {e}", file=sys.stderr)
85+
sys.exit(1)
86+
87+
# Sort the top-level results by archive name
88+
results.sort(key=lambda x: x['name'])
89+
90+
# Output JSON to stdout
91+
print(json.dumps(results, indent=2))
92+
93+
if __name__ == "__main__":
94+
main()

0 commit comments

Comments
 (0)