blob: 1e15f07606872404c36f4f14f3a5427c15a153f4 [file] [log] [blame]
Nick Anthony2d9b73c2020-06-29 21:24:55 -04001#!/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
18import subprocess
19import datetime
Nick Anthony227adad2021-07-15 12:04:10 -040020import sys
21
22
23def print_e(*args, **kwargs):
24print(*args, file=sys.stderr, **kwargs)
25
Nick Anthony2d9b73c2020-06-29 21:24:55 -040026
27def getJetpadReleaseInfo(date):
Nick Anthony140b5f12021-07-15 12:08:50 -040028try:
29rawJetpadReleaseOutput = 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)
30except subprocess.CalledProcessError:
31print_e("FAIL: Failed to get jetpad release info for %s. "
32"This likely means you need to run gcert." % date)
33return None
34rawJetpadReleaseOutputLines = rawJetpadReleaseOutput.splitlines()
35if len(rawJetpadReleaseOutputLines) <= 2:
36print_e("Error: Date %s returned zero results from Jetpad. Please check your date" % args.date)
37return None
38jetpadReleaseOutput = iter(rawJetpadReleaseOutputLines)
39return jetpadReleaseOutput
Nick Anthony2d9b73c2020-06-29 21:24:55 -040040
41def getReleaseInfoObject(date, includeAllCommits, jetpadReleaseInfo):
Nick Anthony140b5f12021-07-15 12:08:50 -040042releaseDateTime = datetime.datetime.fromtimestamp(float(date)/1000.0)
43releaseJsonObject = {}
44releaseJsonObject["releaseDate"] = "%02d-%02d-%s" % (releaseDateTime.month, releaseDateTime.day, releaseDateTime.year)
45releaseJsonObject["includeAllCommits"] = includeAllCommits
46releaseJsonObject["modules"] = {}
47for line in jetpadReleaseInfo:
48if "androidx" not in line.decode(): continue
49# Remove all white space and split line based on '|'
50artifactIdReleaseLine = line.decode().replace(" ", "").split('|')
51groupId = artifactIdReleaseLine[1]
52artifactId = artifactIdReleaseLine[2]
53version = artifactIdReleaseLine[3]
54fromSHA = artifactIdReleaseLine[4]
55untilSHA = artifactIdReleaseLine[5]
56path = artifactIdReleaseLine[6]
57if path and path[0] == '/': path = path[1:]
58requiresSameVersion = False
59if artifactIdReleaseLine[7] == "true":
60requiresSameVersion = True
61buildId = artifactIdReleaseLine[8]
62branch = artifactIdReleaseLine[9]
63if groupId in releaseJsonObject["modules"]:
64releaseJsonObject["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})
75else:
76releaseJsonObject["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}]
87return releaseJsonObject
Nick Anthony2d9b73c2020-06-29 21:24:55 -040088
89def getJetpadRelease(date, includeAllCommits):
Nick Anthony140b5f12021-07-15 12:08:50 -040090print("Getting the release info from Jetpad...")
91jetpadReleaseInfo = getJetpadReleaseInfo(date)
92if not jetpadReleaseInfo:
93exit(1)
94print("Successful")
95return getReleaseInfoObject(date, includeAllCommits, jetpadReleaseInfo)
Nick Anthony2d9b73c2020-06-29 21:24:55 -040096