blob: ce52e48b9176da73727fda0e65fa89fe35a1968b [file] [log] [blame]
Søren Gjessee6087bf2023-01-17 10:49:29 +01001#!/usr/bin/env python3
2# Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
6import re
7import subprocess
8
9GMAVEN_PUBLISHER = '/google/bin/releases/android-devtools/gmaven/publisher/gmaven-publisher'
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020010GMAVEN_PUBLISH_STAGE_RELEASE_ID_PATTERN = re.compile(
11 'Release ID = ([0-9a-f\-]+)')
Søren Gjessee6087bf2023-01-17 10:49:29 +010012
13
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020014def publisher_stage(gfiles, dry_run=False):
15 if dry_run:
16 print('Dry-run, would have staged %s' % gfiles)
17 return 'dry-run-release-id'
Søren Gjessee6087bf2023-01-17 10:49:29 +010018
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020019 print("Staging: %s" % ', '.join(gfiles))
20 print("")
Søren Gjessee6087bf2023-01-17 10:49:29 +010021
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020022 cmd = [GMAVEN_PUBLISHER, 'stage', '--gfile', ','.join(gfiles)]
23 output = subprocess.check_output(cmd)
Søren Gjessee6087bf2023-01-17 10:49:29 +010024
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020025 # Expect output to contain:
26 # [INFO] 06/19/2020 09:35:12 CEST: >>>>>>>>>> Staged
27 # [INFO] 06/19/2020 09:35:12 CEST: Release ID = 9171d015-18f6-4a90-9984-1c362589dc1b
28 # [INFO] 06/19/2020 09:35:12 CEST: Stage Path = /bigstore/studio_staging/maven2/sgjesse/9171d015-18f6-4a90-9984-1c362589dc1b
Søren Gjessee6087bf2023-01-17 10:49:29 +010029
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020030 matches = GMAVEN_PUBLISH_STAGE_RELEASE_ID_PATTERN.findall(
31 output.decode("utf-8"))
32 if matches == None or len(matches) > 1:
33 print("Could not determine the release ID from the gmaven_publisher " +
34 "output. Expected a line with 'Release ID = <release id>'.")
35 print("Output was:")
36 print(output)
37 sys.exit(1)
38
Søren Gjessee6087bf2023-01-17 10:49:29 +010039 print(output)
Søren Gjessee6087bf2023-01-17 10:49:29 +010040
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020041 release_id = matches[0]
42 return release_id
Søren Gjessee6087bf2023-01-17 10:49:29 +010043
44
45def publisher_stage_redir_test_info(release_id, artifact, dst):
46
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020047 redir_command = ("/google/data/ro/teams/android-devtools-infra/tools/redir "
48 + "--alsologtostderr " +
49 "--gcs_bucket_path=/bigstore/gmaven-staging/${USER}/%s " +
50 "--port=1480") % release_id
Søren Gjessee6087bf2023-01-17 10:49:29 +010051
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020052 get_command = (
53 "mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get " +
54 "-Dmaven.repo.local=/tmp/maven_repo_local " +
55 "-DremoteRepositories=http://localhost:1480 " + "-Dartifact=%s " +
56 "-Ddest=%s") % (artifact, dst)
Søren Gjessee6087bf2023-01-17 10:49:29 +010057
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020058 print("""To test the staged content with 'redir' run:
Søren Gjessee6087bf2023-01-17 10:49:29 +010059
60%s
61
62Then add the following repository to settings.gradle to search the 'redir'
63repository:
64
65dependencyResolutionManagement {
66 repositories {
67 maven {
68 url 'http://localhost:1480'
69 allowInsecureProtocol true
70 }
71 }
72}
73
74and add the following repository to gradle.build for for the staged version:
75
76dependencies {
77 implementation('%s') {
78 changing = true
79 }
80}
81
82Use this commands to get artifact from 'redir':
83
84rm -rf /tmp/maven_repo_local
85%s
86""" % (redir_command, artifact, get_command))
87
88
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020089def publisher_publish(release_id, dry_run=False):
90 if dry_run:
91 print('Dry-run, would have published %s' % release_id)
92 return
Søren Gjessee6087bf2023-01-17 10:49:29 +010093
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020094 cmd = [GMAVEN_PUBLISHER, 'publish', release_id]
95 output = subprocess.check_output(cmd)