Debian Codegraph @

infra/bots/assets/gsutil/create.py

raw
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
12 import argparse
13 import os
14 import shutil
15 import subprocess
16 import sys
17
18 FILE_DIR = os.path.dirname(os.path.abspath(__file__))
19 INFRA_BOTS_DIR = os.path.realpath(os.path.join(FILE_DIR, os.pardir, os.pardir))
20 sys.path.insert(0, INFRA_BOTS_DIR)
21 import utils
22
23 # https://cloud.google.com/storage/docs/gsutil_install#windows
24 URL = "https://storage.googleapis.com/pub/gsutil.zip"
25 VERSION = "5.25"
26
27 def 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
40 def 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
47 if __name__ == '__main__':
48 main()
49