blob: 841758787c841b11e2821e27a8242050a2d2bb88 [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):
24 print(*args, file=sys.stderr, **kwargs)
25
Nick Anthony2d9b73c2020-06-29 21:24:55 -040026
27def getJetpadReleaseInfo(date):
28 try:
Nick Anthonye584c0b2021-04-15 09:33:00 -040029 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)
Nick Anthony2d9b73c2020-06-29 21:24:55 -040030 except subprocess.CalledProcessError:
Nick Anthony227adad2021-07-15 12:04:10 -040031 print_e("FAIL: Failed to get jetpad release info for %s. "
32 "This likely means you need to run gcert." % date)
Nick Anthony2d9b73c2020-06-29 21:24:55 -040033 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
40
41def getReleaseInfoObject(date, includeAllCommits, jetpadReleaseInfo):
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]
Nick Anthony41cd4002021-04-08 10:04:42 -040057 if path and path[0] == '/': path = path[1:]
Nick Anthony2d9b73c2020-06-29 21:24:55 -040058 requiresSameVersion = False
59 if artifactIdReleaseLine[7] == "true":
60 requiresSameVersion = True
Nick Anthonye584c0b2021-04-15 09:33:00 -040061 buildId = artifactIdReleaseLine[8]
62 branch = artifactIdReleaseLine[9]
Nick Anthony2d9b73c2020-06-29 21:24:55 -040063 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,
Nick Anthonye584c0b2021-04-15 09:33:00 -040071 "path": path,
72 "buildId": buildId,
73 "branch": branch,
Nick Anthony2d9b73c2020-06-29 21:24:55 -040074 })
75 else:
76 releaseJsonObject["modules"][groupId] = [{
77 "groupId": groupId,
78 "artifactId": artifactId,
79 "version": version,
80 "fromSHA": fromSHA,
81 "untilSHA": untilSHA,
82 "requiresSameVersion": requiresSameVersion,
Nick Anthonye584c0b2021-04-15 09:33:00 -040083 "path": path,
84 "buildId": buildId,
85 "branch": branch,
Nick Anthony2d9b73c2020-06-29 21:24:55 -040086 }]
87 return releaseJsonObject
88
89def getJetpadRelease(date, includeAllCommits):
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)
96