Andrew Shulaev | dbfcb7c | 2022-07-11 14:14:37 +0100 | [diff] [blame] | 1 | #!/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 | |
| 16 | import argparse |
Primiano Tucci | 7f264d1 | 2024-09-25 11:02:05 +0100 | [diff] [blame] | 17 | import base64 |
| 18 | import json |
| 19 | import os |
| 20 | import io |
| 21 | import re |
| 22 | import zipfile |
Andrew Shulaev | dbfcb7c | 2022-07-11 14:14:37 +0100 | [diff] [blame] | 23 | import urllib.request |
| 24 | from os import path |
| 25 | |
Primiano Tucci | 7f264d1 | 2024-09-25 11:02:05 +0100 | [diff] [blame] | 26 | ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 27 | |
Andrew Shulaev | dbfcb7c | 2022-07-11 14:14:37 +0100 | [diff] [blame] | 28 | |
| 29 | def get_artifact_url(run, name): |
| 30 | return f'https://storage.googleapis.com/perfetto-ci-artifacts/{run}/ui-test-artifacts/{name}' |
| 31 | |
| 32 | |
| 33 | def main(): |
Primiano Tucci | 7f264d1 | 2024-09-25 11:02:05 +0100 | [diff] [blame] | 34 | os.chdir(ROOT_DIR) |
Andrew Shulaev | dbfcb7c | 2022-07-11 14:14:37 +0100 | [diff] [blame] | 35 | parser = argparse.ArgumentParser() |
Primiano Tucci | 7f264d1 | 2024-09-25 11:02:05 +0100 | [diff] [blame] | 36 | 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 Shulaev | dbfcb7c | 2022-07-11 14:14:37 +0100 | [diff] [blame] | 41 | args = parser.parse_args() |
Primiano Tucci | 7f264d1 | 2024-09-25 11:02:05 +0100 | [diff] [blame] | 42 | url = get_artifact_url(args.run, 'index.html') |
| 43 | with urllib.request.urlopen(url) as resp: |
Andrew Shulaev | dbfcb7c | 2022-07-11 14:14:37 +0100 | [diff] [blame] | 44 | handle_report(resp.read().decode('utf-8'), args.run) |
| 45 | |
| 46 | |
Primiano Tucci | 7f264d1 | 2024-09-25 11:02:05 +0100 | [diff] [blame] | 47 | def sanitize(name): |
| 48 | return re.sub('[ _]', '-', name) |
| 49 | |
| 50 | |
Andrew Shulaev | dbfcb7c | 2022-07-11 14:14:37 +0100 | [diff] [blame] | 51 | def handle_report(report: str, run: str): |
Primiano Tucci | 7f264d1 | 2024-09-25 11:02:05 +0100 | [diff] [blame] | 52 | 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 Shulaev | dbfcb7c | 2022-07-11 14:14:37 +0100 | [diff] [blame] | 70 | |
Primiano Tucci | 7f264d1 | 2024-09-25 11:02:05 +0100 | [diff] [blame] | 71 | 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 Shulaev | dbfcb7c | 2022-07-11 14:14:37 +0100 | [diff] [blame] | 75 | |
Hector Dearman | 2b5bbef | 2022-11-03 14:32:46 +0000 | [diff] [blame] | 76 | print('Done. Now run:') |
Primiano Tucci | 7f264d1 | 2024-09-25 11:02:05 +0100 | [diff] [blame] | 77 | print('./tools/test_data upload (or status)') |
Andrew Shulaev | dbfcb7c | 2022-07-11 14:14:37 +0100 | [diff] [blame] | 78 | |
| 79 | |
| 80 | if __name__ == "__main__": |
| 81 | main() |