Søren Gjesse | e6087bf | 2023-01-17 10:49:29 +0100 | [diff] [blame] | 1 | #!/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 | |
| 6 | import re |
| 7 | import subprocess |
| 8 | |
| 9 | GMAVEN_PUBLISHER = '/google/bin/releases/android-devtools/gmaven/publisher/gmaven-publisher' |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 10 | GMAVEN_PUBLISH_STAGE_RELEASE_ID_PATTERN = re.compile( |
| 11 | 'Release ID = ([0-9a-f\-]+)') |
Søren Gjesse | e6087bf | 2023-01-17 10:49:29 +0100 | [diff] [blame] | 12 | |
| 13 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 14 | def 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 Gjesse | e6087bf | 2023-01-17 10:49:29 +0100 | [diff] [blame] | 18 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 19 | print("Staging: %s" % ', '.join(gfiles)) |
| 20 | print("") |
Søren Gjesse | e6087bf | 2023-01-17 10:49:29 +0100 | [diff] [blame] | 21 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 22 | cmd = [GMAVEN_PUBLISHER, 'stage', '--gfile', ','.join(gfiles)] |
| 23 | output = subprocess.check_output(cmd) |
Søren Gjesse | e6087bf | 2023-01-17 10:49:29 +0100 | [diff] [blame] | 24 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 25 | # 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 Gjesse | e6087bf | 2023-01-17 10:49:29 +0100 | [diff] [blame] | 29 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 30 | 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 Gjesse | e6087bf | 2023-01-17 10:49:29 +0100 | [diff] [blame] | 39 | print(output) |
Søren Gjesse | e6087bf | 2023-01-17 10:49:29 +0100 | [diff] [blame] | 40 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 41 | release_id = matches[0] |
| 42 | return release_id |
Søren Gjesse | e6087bf | 2023-01-17 10:49:29 +0100 | [diff] [blame] | 43 | |
| 44 | |
| 45 | def publisher_stage_redir_test_info(release_id, artifact, dst): |
| 46 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 47 | 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 Gjesse | e6087bf | 2023-01-17 10:49:29 +0100 | [diff] [blame] | 51 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 52 | 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 Gjesse | e6087bf | 2023-01-17 10:49:29 +0100 | [diff] [blame] | 57 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 58 | print("""To test the staged content with 'redir' run: |
Søren Gjesse | e6087bf | 2023-01-17 10:49:29 +0100 | [diff] [blame] | 59 | |
| 60 | %s |
| 61 | |
| 62 | Then add the following repository to settings.gradle to search the 'redir' |
| 63 | repository: |
| 64 | |
| 65 | dependencyResolutionManagement { |
| 66 | repositories { |
| 67 | maven { |
| 68 | url 'http://localhost:1480' |
| 69 | allowInsecureProtocol true |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | and add the following repository to gradle.build for for the staged version: |
| 75 | |
| 76 | dependencies { |
| 77 | implementation('%s') { |
| 78 | changing = true |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | Use this commands to get artifact from 'redir': |
| 83 | |
| 84 | rm -rf /tmp/maven_repo_local |
| 85 | %s |
| 86 | """ % (redir_command, artifact, get_command)) |
| 87 | |
| 88 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 89 | def 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 Gjesse | e6087bf | 2023-01-17 10:49:29 +0100 | [diff] [blame] | 93 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 94 | cmd = [GMAVEN_PUBLISHER, 'publish', release_id] |
| 95 | output = subprocess.check_output(cmd) |