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):
24print(*args, file=sys.stderr, **kwargs)
25
Nick Anthony2d9b73c2020-06-29 21:24:55 -040026
27def getJetpadReleaseInfo(date):
28try:
Nick Anthonye584c0b2021-04-15 09:33:00 -040029rawJetpadReleaseOutput = 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 -040030except subprocess.CalledProcessError:
Nick Anthony227adad2021-07-15 12:04:10 -040031print_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 -040033return 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
40
41def getReleaseInfoObject(date, includeAllCommits, jetpadReleaseInfo):
42releaseDateTime = 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]
Nick Anthony41cd4002021-04-08 10:04:42 -040057if path and path[0] == '/': path = path[1:]
Nick Anthony2d9b73c2020-06-29 21:24:55 -040058requiresSameVersion = False
59if artifactIdReleaseLine[7] == "true":
60requiresSameVersion = True
Nick Anthonye584c0b2021-04-15 09:33:00 -040061buildId = artifactIdReleaseLine[8]
62branch = artifactIdReleaseLine[9]
Nick Anthony2d9b73c2020-06-29 21:24:55 -040063if 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,
Nick Anthonye584c0b2021-04-15 09:33:00 -040071"path": path,
72"buildId": buildId,
73"branch": branch,
Nick Anthony2d9b73c2020-06-29 21:24:55 -040074})
75else:
76releaseJsonObject["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}]
87return releaseJsonObject
88
89def getJetpadRelease(date, includeAllCommits):
90print("Getting the release info from Jetpad...")
91jetpadReleaseInfo = getJetpadReleaseInfo(date)
92if not jetpadReleaseInfo:
93exit(1)
94print("Successful")
95return getReleaseInfoObject(date, includeAllCommits, jetpadReleaseInfo)
96