tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

print_cipd_version.py (1835B)


      1 #!/usr/bin/env python3
      2 # Copyright 2023 The Chromium Authors
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 
      6 import argparse
      7 import pathlib
      8 import re
      9 import subprocess
     10 
     11 _DIR_SOURCE_ROOT = str(pathlib.Path(__file__).absolute().parents[2])
     12 
     13 
     14 def main():
     15    parser = argparse.ArgumentParser()
     16    # Hide args set by wrappers so that using --help with the wrappers does not
     17    # show them.
     18    parser.add_argument('--subdir', required=True, help=argparse.SUPPRESS)
     19    parser.add_argument('--cipd-package',
     20                        required=True,
     21                        help=argparse.SUPPRESS)
     22    parser.add_argument('--git-log-url', help=argparse.SUPPRESS)
     23    parser.add_argument('--cipd-instance',
     24                        help='Uses value from DEPS by default')
     25    args = parser.parse_args()
     26 
     27    if not args.cipd_instance:
     28        cmd = [
     29            'gclient', 'getdep', '-r', f'src/{args.subdir}:{args.cipd_package}'
     30        ]
     31        args.cipd_instance = subprocess.check_output(cmd,
     32                                                     cwd=_DIR_SOURCE_ROOT,
     33                                                     text=True)
     34 
     35    cmd = [
     36        'cipd', 'describe', args.cipd_package, '-version', args.cipd_instance
     37    ]
     38    print(' '.join(cmd))
     39    output = subprocess.check_output(cmd, text=True)
     40    print(output, end='')
     41    if args.git_log_url:
     42        git_hashes = re.findall(r'version:.*?@(\w+)', output)
     43        if not git_hashes:
     44            print('Could not find git hash from output.')
     45        else:
     46            # Multiple version tags exist when multiple versions have the same sha1.
     47            last_version = git_hashes[-1]
     48            print()
     49            print('Recent commits:', args.git_log_url.format(last_version))
     50 
     51 
     52 if __name__ == '__main__':
     53    main()