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
40 changes: 40 additions & 0 deletions .github/workflows/postsubmit-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- main

jobs:
# Update the renderdiff goldens in filament-assets. This will add or merge the new goldens from
# a branch on filament-assets.
update-renderdiff-goldens:
name: update-renderdiff-goldens
runs-on: 'ubuntu-24.04-4core'
Expand Down Expand Up @@ -35,6 +37,7 @@
--merge-to-main --filament-tag=${COMMIT_HASH} --golden-repo-token=${GH_TOKEN}
fi

# Update the /docs (offiicla github-hosted Filament site) if necessary
update-docs:
name: update-docs
runs-on: 'ubuntu-24.04-4core'
Expand All @@ -57,3 +60,40 @@
git config --global user.name "Filament Bot"
git config --global credential.helper cache
bash docs_src/build/postsubmit.sh ${COMMIT_HASH} ${GH_TOKEN}

# Produce a json that describes the android artifact sizes, and will push that json to a folder in
# filament-assets
update-sizeguard:
name: update-sizeguard
runs-on: 'ubuntu-24.04-16core'
steps:
- uses: actions/checkout@v4.1.6
with:
fetch-depth: 0
- uses: ./.github/actions/linux-prereq
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- id: get_commit_msg
uses: ./.github/actions/get-commit-msg
- name: Build and generate size report
run: |
cd build/android && printf "y" | ./build.sh release all
cd ../..
COMMIT_HASH="${{ steps.get_commit_msg.outputs.hash }}"
python3 test/sizeguard/dump_artifact_size.py out/*.tgz out/*.aar > "${COMMIT_HASH}.json"
- name: Push to filament-assets
env:
GH_TOKEN: ${{ secrets.FILAMENTBOT_TOKEN }}
run: |
COMMIT_HASH="${{ steps.get_commit_msg.outputs.hash }}"
git config --global user.email "filament.bot@gmail.com"
git config --global user.name "Filament Bot"
git clone https://x-access-token:${GH_TOKEN}@github.com/google/filament-assets.git filament-assets
mkdir -p filament-assets/sizeguard
mv "${COMMIT_HASH}.json" filament-assets/sizeguard/
cd filament-assets
git add sizeguard/"${COMMIT_HASH}.json"
git commit -m "Update sizeguard for filament@${COMMIT_HASH}" || echo "No changes to commit"
git push https://x-access-token:${GH_TOKEN}@github.com/google/filament-assets.git main
Comment on lines +67 to +99

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
94 changes: 94 additions & 0 deletions test/sizeguard/dump_artifact_size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# 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 os
import sys
import zipfile
import tarfile
import json
import argparse

# Hardcoded list of library extensions to track
LIB_EXTENSIONS = ('.a', '.jar', '.so')

def get_archive_content(path):
"""
Extracts metadata for library files within a compressed archive.
Returns a list of dicts with 'name' and 'size' (uncompressed).
"""
content = []

# .aar and .zip are both handled by zipfile
if path.endswith(('.zip', '.aar')):
with zipfile.ZipFile(path, 'r') as z:
for info in z.infolist():
# info.is_dir() is available in Python 3.6+
if not info.is_dir() and info.filename.endswith(LIB_EXTENSIONS):
content.append({
"name": info.filename,
"size": info.file_size
})

# .tgz or .tar.gz handled by tarfile
elif path.endswith(('.tgz', '.tar.gz')):
with tarfile.open(path, 'r:gz') as t:
for member in t.getmembers():
if member.isfile() and member.name.endswith(LIB_EXTENSIONS):
content.append({
"name": member.name,
"size": member.size
})
else:
raise ValueError(f"Unsupported archive format: {path}")

return content

def main():
parser = argparse.ArgumentParser(description="Dump sizes of library files inside archives as JSON.")
parser.add_argument('archives', nargs='+', help='List of compressed archives (.aar, .tgz, .zip)')
args = parser.parse_args()

results = []

for archive_path in args.archives:
if not os.path.exists(archive_path):
print(f"Error: File not found: {archive_path}", file=sys.stderr)
sys.exit(1)

try:
archive_full_size = os.path.getsize(archive_path)
inner_content = get_archive_content(archive_path)

# Sort the content list alphabetically by name
inner_content.sort(key=lambda x: x['name'])

results.append({
"name": os.path.basename(archive_path),
"size": archive_full_size,
"content": inner_content
})
except Exception as e:
print(f"Error processing {archive_path}: {e}", file=sys.stderr)
sys.exit(1)

# Sort the top-level results by archive name
results.sort(key=lambda x: x['name'])

# Output JSON to stdout
print(json.dumps(results, indent=2))

if __name__ == "__main__":
main()
Loading