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