xref: /aosp_15_r20/external/skia/infra/bots/assets/gsutil/create.py (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Worker#!/usr/bin/env python3
2*c8dee2aaSAndroid Build Coastguard Worker#
3*c8dee2aaSAndroid Build Coastguard Worker# Copyright 2022 Google LLC
4*c8dee2aaSAndroid Build Coastguard Worker#
5*c8dee2aaSAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be
6*c8dee2aaSAndroid Build Coastguard Worker# found in the LICENSE file.
7*c8dee2aaSAndroid Build Coastguard Worker
8*c8dee2aaSAndroid Build Coastguard Worker
9*c8dee2aaSAndroid Build Coastguard Worker"""Create the asset."""
10*c8dee2aaSAndroid Build Coastguard Worker
11*c8dee2aaSAndroid Build Coastguard Worker
12*c8dee2aaSAndroid Build Coastguard Workerimport argparse
13*c8dee2aaSAndroid Build Coastguard Workerimport os
14*c8dee2aaSAndroid Build Coastguard Workerimport shutil
15*c8dee2aaSAndroid Build Coastguard Workerimport subprocess
16*c8dee2aaSAndroid Build Coastguard Workerimport sys
17*c8dee2aaSAndroid Build Coastguard Worker
18*c8dee2aaSAndroid Build Coastguard WorkerFILE_DIR = os.path.dirname(os.path.abspath(__file__))
19*c8dee2aaSAndroid Build Coastguard WorkerINFRA_BOTS_DIR = os.path.realpath(os.path.join(FILE_DIR, os.pardir, os.pardir))
20*c8dee2aaSAndroid Build Coastguard Workersys.path.insert(0, INFRA_BOTS_DIR)
21*c8dee2aaSAndroid Build Coastguard Workerimport utils
22*c8dee2aaSAndroid Build Coastguard Worker
23*c8dee2aaSAndroid Build Coastguard Worker# https://cloud.google.com/storage/docs/gsutil_install#windows
24*c8dee2aaSAndroid Build Coastguard WorkerURL = "https://storage.googleapis.com/pub/gsutil.zip"
25*c8dee2aaSAndroid Build Coastguard WorkerVERSION = "5.25"
26*c8dee2aaSAndroid Build Coastguard Worker
27*c8dee2aaSAndroid Build Coastguard Workerdef create_asset(target_dir):
28*c8dee2aaSAndroid Build Coastguard Worker  """Create the asset."""
29*c8dee2aaSAndroid Build Coastguard Worker  with utils.tmp_dir():
30*c8dee2aaSAndroid Build Coastguard Worker    subprocess.run(["curl", URL, "--output", "gsutil.zip"], check=True)
31*c8dee2aaSAndroid Build Coastguard Worker    subprocess.run(["unzip", "gsutil.zip"], check=True)
32*c8dee2aaSAndroid Build Coastguard Worker    with open("./gsutil/VERSION", "r") as f:
33*c8dee2aaSAndroid Build Coastguard Worker      version = f.read().strip()
34*c8dee2aaSAndroid Build Coastguard Worker      if version != VERSION:
35*c8dee2aaSAndroid Build Coastguard Worker        raise RuntimeError("Action version %s does not match expected version %s"
36*c8dee2aaSAndroid Build Coastguard Worker                           % (version, VERSION))
37*c8dee2aaSAndroid Build Coastguard Worker    shutil.move('./gsutil', target_dir)
38*c8dee2aaSAndroid Build Coastguard Worker
39*c8dee2aaSAndroid Build Coastguard Worker
40*c8dee2aaSAndroid Build Coastguard Workerdef main():
41*c8dee2aaSAndroid Build Coastguard Worker  parser = argparse.ArgumentParser()
42*c8dee2aaSAndroid Build Coastguard Worker  parser.add_argument('--target_dir', '-t', required=True)
43*c8dee2aaSAndroid Build Coastguard Worker  args = parser.parse_args()
44*c8dee2aaSAndroid Build Coastguard Worker  create_asset(args.target_dir)
45*c8dee2aaSAndroid Build Coastguard Worker
46*c8dee2aaSAndroid Build Coastguard Worker
47*c8dee2aaSAndroid Build Coastguard Workerif __name__ == '__main__':
48*c8dee2aaSAndroid Build Coastguard Worker  main()
49*c8dee2aaSAndroid Build Coastguard Worker
50