| #!/usr/bin/env python3 | |
| # | |
| # Copyright (C) 2020 The Android Open Source Project | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| # | |
| import subprocess | |
| import datetime | |
| import sys | |
| def print_e(*args, **kwargs): | |
| print(*args, file=sys.stderr, **kwargs) | |
| def getJetpadReleaseInfo(date): | |
| try: | |
| 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) | |
| except subprocess.CalledProcessError: | |
| print_e("FAIL: Failed to get jetpad release info for %s. " | |
| "This likely means you need to run gcert." % date) | |
| return None | |
| rawJetpadReleaseOutputLines = rawJetpadReleaseOutput.splitlines() | |
| if len(rawJetpadReleaseOutputLines) <= 2: | |
| print_e("Error: Date %s returned zero results from Jetpad. Please check your date" % date) | |
| return None | |
| jetpadReleaseOutput = iter(rawJetpadReleaseOutputLines) | |
| return jetpadReleaseOutput | |
| def getReleaseInfoObject(date, includeAllCommits, jetpadReleaseInfo): | |
| releaseDateTime = datetime.datetime.fromtimestamp(float(date)/1000.0) | |
| releaseJsonObject = {} | |
| releaseJsonObject["releaseDate"] = "%02d-%02d-%s" % (releaseDateTime.month, releaseDateTime.day, releaseDateTime.year) | |
| releaseJsonObject["includeAllCommits"] = includeAllCommits | |
| releaseJsonObject["modules"] = {} | |
| for line in jetpadReleaseInfo: | |
| if "androidx" not in line.decode(): continue | |
| # Remove all white space and split line based on '|' | |
| artifactIdReleaseLine = line.decode().replace(" ", "").split('|') | |
| groupId = artifactIdReleaseLine[1] | |
| artifactId = artifactIdReleaseLine[2] | |
| version = artifactIdReleaseLine[3] | |
| fromSHA = artifactIdReleaseLine[4] | |
| untilSHA = artifactIdReleaseLine[5] | |
| path = artifactIdReleaseLine[6] | |
| if path and path[0] == '/': path = path[1:] | |
| requiresSameVersion = False | |
| if artifactIdReleaseLine[7] == "true": | |
| requiresSameVersion = True | |
| buildId = artifactIdReleaseLine[8] | |
| branch = artifactIdReleaseLine[9] | |
| if groupId in releaseJsonObject["modules"]: | |
| releaseJsonObject["modules"][groupId].append({ | |
| "groupId": groupId, | |
| "artifactId": artifactId, | |
| "version": version, | |
| "fromSHA": fromSHA, | |
| "untilSHA": untilSHA, | |
| "requiresSameVersion": requiresSameVersion, | |
| "path": path, | |
| "buildId": buildId, | |
| "branch": branch, | |
| }) | |
| else: | |
| releaseJsonObject["modules"][groupId] = [{ | |
| "groupId": groupId, | |
| "artifactId": artifactId, | |
| "version": version, | |
| "fromSHA": fromSHA, | |
| "untilSHA": untilSHA, | |
| "requiresSameVersion": requiresSameVersion, | |
| "path": path, | |
| "buildId": buildId, | |
| "branch": branch, | |
| }] | |
| return releaseJsonObject | |
| def getJetpadRelease(date, includeAllCommits): | |
| print("Getting the release info from Jetpad...") | |
| jetpadReleaseInfo = getJetpadReleaseInfo(date) | |
| if not jetpadReleaseInfo: | |
| exit(1) | |
| print("Successful") | |
| return getReleaseInfoObject(date, includeAllCommits, jetpadReleaseInfo) | |