Nick Anthony | 2d9b73c | 2020-06-29 21:24:55 -0400 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | # |
| 3 | # Copyright (C) 2020 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | |
| 18 | import subprocess |
| 19 | import datetime |
Nick Anthony | 227adad | 2021-07-15 12:04:10 -0400 | [diff] [blame] | 20 | import sys |
| 21 | |
| 22 | |
| 23 | def print_e(*args, **kwargs): |
| 24 | print(*args, file=sys.stderr, **kwargs) |
| 25 | |
Nick Anthony | 2d9b73c | 2020-06-29 21:24:55 -0400 | [diff] [blame] | 26 | |
| 27 | def getJetpadReleaseInfo(date): |
Nick Anthony | 140b5f1 | 2021-07-15 12:08:50 -0400 | [diff] [blame] | 28 | try: |
| 29 | rawJetpadReleaseOutput = subprocess.check_output('span sql /span/global/androidx-jetpad:prod_instance \"SELECT GroupId, ArtifactId, ReleaseVersion, PreviousReleaseSHA, ReleaseSHA, Path, RequireSameVersionGroupBuild, ReleaseBuildId, ReleaseBranch FROM LibraryReleases WHERE ReleaseDate = %s\"' % date, shell=True) |
| 30 | except subprocess.CalledProcessError: |
| 31 | print_e("FAIL: Failed to get jetpad release info for %s. " |
| 32 | "This likely means you need to run gcert." % date) |
| 33 | return None |
| 34 | rawJetpadReleaseOutputLines = rawJetpadReleaseOutput.splitlines() |
| 35 | if len(rawJetpadReleaseOutputLines) <= 2: |
| 36 | print_e("Error: Date %s returned zero results from Jetpad. Please check your date" % args.date) |
| 37 | return None |
| 38 | jetpadReleaseOutput = iter(rawJetpadReleaseOutputLines) |
| 39 | return jetpadReleaseOutput |
Nick Anthony | 2d9b73c | 2020-06-29 21:24:55 -0400 | [diff] [blame] | 40 | |
| 41 | def getReleaseInfoObject(date, includeAllCommits, jetpadReleaseInfo): |
Nick Anthony | 140b5f1 | 2021-07-15 12:08:50 -0400 | [diff] [blame] | 42 | releaseDateTime = datetime.datetime.fromtimestamp(float(date)/1000.0) |
| 43 | releaseJsonObject = {} |
| 44 | releaseJsonObject["releaseDate"] = "%02d-%02d-%s" % (releaseDateTime.month, releaseDateTime.day, releaseDateTime.year) |
| 45 | releaseJsonObject["includeAllCommits"] = includeAllCommits |
| 46 | releaseJsonObject["modules"] = {} |
| 47 | for line in jetpadReleaseInfo: |
| 48 | if "androidx" not in line.decode(): continue |
| 49 | # Remove all white space and split line based on '|' |
| 50 | artifactIdReleaseLine = line.decode().replace(" ", "").split('|') |
| 51 | groupId = artifactIdReleaseLine[1] |
| 52 | artifactId = artifactIdReleaseLine[2] |
| 53 | version = artifactIdReleaseLine[3] |
| 54 | fromSHA = artifactIdReleaseLine[4] |
| 55 | untilSHA = artifactIdReleaseLine[5] |
| 56 | path = artifactIdReleaseLine[6] |
| 57 | if path and path[0] == '/': path = path[1:] |
| 58 | requiresSameVersion = False |
| 59 | if artifactIdReleaseLine[7] == "true": |
| 60 | requiresSameVersion = True |
| 61 | buildId = artifactIdReleaseLine[8] |
| 62 | branch = artifactIdReleaseLine[9] |
| 63 | if groupId in releaseJsonObject["modules"]: |
| 64 | releaseJsonObject["modules"][groupId].append({ |
| 65 | "groupId": groupId, |
| 66 | "artifactId": artifactId, |
| 67 | "version": version, |
| 68 | "fromSHA": fromSHA, |
| 69 | "untilSHA": untilSHA, |
| 70 | "requiresSameVersion": requiresSameVersion, |
| 71 | "path": path, |
| 72 | "buildId": buildId, |
| 73 | "branch": branch, |
| 74 | }) |
| 75 | else: |
| 76 | releaseJsonObject["modules"][groupId] = [{ |
| 77 | "groupId": groupId, |
| 78 | "artifactId": artifactId, |
| 79 | "version": version, |
| 80 | "fromSHA": fromSHA, |
| 81 | "untilSHA": untilSHA, |
| 82 | "requiresSameVersion": requiresSameVersion, |
| 83 | "path": path, |
| 84 | "buildId": buildId, |
| 85 | "branch": branch, |
| 86 | }] |
| 87 | return releaseJsonObject |
Nick Anthony | 2d9b73c | 2020-06-29 21:24:55 -0400 | [diff] [blame] | 88 | |
| 89 | def getJetpadRelease(date, includeAllCommits): |
Nick Anthony | 140b5f1 | 2021-07-15 12:08:50 -0400 | [diff] [blame] | 90 | print("Getting the release info from Jetpad...") |
| 91 | jetpadReleaseInfo = getJetpadReleaseInfo(date) |
| 92 | if not jetpadReleaseInfo: |
| 93 | exit(1) |
| 94 | print("Successful") |
| 95 | return getReleaseInfoObject(date, includeAllCommits, jetpadReleaseInfo) |
Nick Anthony | 2d9b73c | 2020-06-29 21:24:55 -0400 | [diff] [blame] | 96 | |