blob: cc0ec4b9417ee015e7b241372b48d7713ae9083d [file] [log] [blame]
Andrew Shulaevdbfcb7c2022-07-11 14:14:37 +01001#!/usr/bin/env python3
2# Copyright (C) 2022 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import argparse
Primiano Tucci7f264d12024-09-25 11:02:05 +010017import base64
18import json
19import os
20import io
21import re
22import zipfile
Andrew Shulaevdbfcb7c2022-07-11 14:14:37 +010023import urllib.request
24from os import path
25
Primiano Tucci7f264d12024-09-25 11:02:05 +010026ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
27
Andrew Shulaevdbfcb7c2022-07-11 14:14:37 +010028
29def get_artifact_url(run, name):
30 return f'https://storage.googleapis.com/perfetto-ci-artifacts/{run}/ui-test-artifacts/{name}'
31
32
33def main():
Primiano Tucci7f264d12024-09-25 11:02:05 +010034 os.chdir(ROOT_DIR)
Andrew Shulaevdbfcb7c2022-07-11 14:14:37 +010035 parser = argparse.ArgumentParser()
Primiano Tucci7f264d12024-09-25 11:02:05 +010036 parser.add_argument(
37 'run',
38 metavar='RUN',
39 help='CI run identifier, e.g. ' +
40 '\'20240923144821--cls-3258215-15--ui-clang-x86_64-release\'')
Andrew Shulaevdbfcb7c2022-07-11 14:14:37 +010041 args = parser.parse_args()
Primiano Tucci7f264d12024-09-25 11:02:05 +010042 url = get_artifact_url(args.run, 'index.html')
43 with urllib.request.urlopen(url) as resp:
Andrew Shulaevdbfcb7c2022-07-11 14:14:37 +010044 handle_report(resp.read().decode('utf-8'), args.run)
45
46
Primiano Tucci7f264d12024-09-25 11:02:05 +010047def sanitize(name):
48 return re.sub('[ _]', '-', name)
49
50
Andrew Shulaevdbfcb7c2022-07-11 14:14:37 +010051def handle_report(report: str, run: str):
Primiano Tucci7f264d12024-09-25 11:02:05 +010052 m = re.findall(
53 r'playwrightReportBase64 = "data:application/zip;base64,([^"]+)"', report)
54 bin = base64.b64decode(m[0])
55 z = zipfile.ZipFile(io.BytesIO(bin))
56 report = json.loads(z.open('report.json').read().decode())
57 pngs = {}
58 for f in report['files']:
59 test_file = f['fileName'].removeprefix('test/')
60 for t in f['tests']:
61 title = sanitize(t['title'])
62 for r in t['results']:
63 for a in r['attachments']:
64 png_name = sanitize(a['name'])
65 if not png_name.endswith('-actual.png'):
66 continue
67 path = 'test/data/ui-screenshots/%s/%s/%s' % (
68 test_file, title, png_name.replace('-actual', ''))
69 pngs[path] = a['path']
Andrew Shulaevdbfcb7c2022-07-11 14:14:37 +010070
Primiano Tucci7f264d12024-09-25 11:02:05 +010071 for local_path, remote_path in pngs.items():
72 url = get_artifact_url(run, remote_path)
73 print(f'Downloading {local_path} from {url}')
74 urllib.request.urlretrieve(url, local_path)
Andrew Shulaevdbfcb7c2022-07-11 14:14:37 +010075
Hector Dearman2b5bbef2022-11-03 14:32:46 +000076 print('Done. Now run:')
Primiano Tucci7f264d12024-09-25 11:02:05 +010077 print('./tools/test_data upload (or status)')
Andrew Shulaevdbfcb7c2022-07-11 14:14:37 +010078
79
80if __name__ == "__main__":
81 main()