blob: cec146c94721da0b0ec0fde8ca4fb80cab0bdb7c [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
20
21def getJetpadReleaseInfo(date):
22try:
Nick Anthonye584c0b2021-04-15 09:33:00 -040023rawJetpadReleaseOutput = 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 -040024except subprocess.CalledProcessError:
25print_e('FAIL: Failed to get jetpad release info for %s' % date)
26return None
27rawJetpadReleaseOutputLines = rawJetpadReleaseOutput.splitlines()
28if len(rawJetpadReleaseOutputLines) <= 2:
29print_e("Error: Date %s returned zero results from Jetpad. Please check your date" % args.date)
30return None
31jetpadReleaseOutput = iter(rawJetpadReleaseOutputLines)
32return jetpadReleaseOutput
33
34def getReleaseInfoObject(date, includeAllCommits, jetpadReleaseInfo):
35releaseDateTime = datetime.datetime.fromtimestamp(float(date)/1000.0)
36releaseJsonObject = {}
37releaseJsonObject["releaseDate"] = "%02d-%02d-%s" % (releaseDateTime.month, releaseDateTime.day, releaseDateTime.year)
38releaseJsonObject["includeAllCommits"] = includeAllCommits
39releaseJsonObject["modules"] = {}
40for line in jetpadReleaseInfo:
41if "androidx" not in line.decode(): continue
42# Remove all white space and split line based on '|'
43artifactIdReleaseLine = line.decode().replace(" ", "").split('|')
44groupId = artifactIdReleaseLine[1]
45artifactId = artifactIdReleaseLine[2]
46version = artifactIdReleaseLine[3]
47fromSHA = artifactIdReleaseLine[4]
48untilSHA = artifactIdReleaseLine[5]
49path = artifactIdReleaseLine[6]
Nick Anthony41cd4002021-04-08 10:04:42 -040050if path and path[0] == '/': path = path[1:]
Nick Anthony2d9b73c2020-06-29 21:24:55 -040051requiresSameVersion = False
52if artifactIdReleaseLine[7] == "true":
53requiresSameVersion = True
Nick Anthonye584c0b2021-04-15 09:33:00 -040054buildId = artifactIdReleaseLine[8]
55branch = artifactIdReleaseLine[9]
Nick Anthony2d9b73c2020-06-29 21:24:55 -040056if groupId in releaseJsonObject["modules"]:
57releaseJsonObject["modules"][groupId].append({
58"groupId": groupId,
59"artifactId": artifactId,
60"version": version,
61"fromSHA": fromSHA,
62"untilSHA": untilSHA,
63"requiresSameVersion": requiresSameVersion,
Nick Anthonye584c0b2021-04-15 09:33:00 -040064"path": path,
65"buildId": buildId,
66"branch": branch,
Nick Anthony2d9b73c2020-06-29 21:24:55 -040067})
68else:
69releaseJsonObject["modules"][groupId] = [{
70"groupId": groupId,
71"artifactId": artifactId,
72"version": version,
73"fromSHA": fromSHA,
74"untilSHA": untilSHA,
75"requiresSameVersion": requiresSameVersion,
Nick Anthonye584c0b2021-04-15 09:33:00 -040076"path": path,
77"buildId": buildId,
78"branch": branch,
Nick Anthony2d9b73c2020-06-29 21:24:55 -040079}]
80return releaseJsonObject
81
82def getJetpadRelease(date, includeAllCommits):
83print("Getting the release info from Jetpad...")
84jetpadReleaseInfo = getJetpadReleaseInfo(date)
85if not jetpadReleaseInfo:
86exit(1)
87print("Successful")
88return getReleaseInfoObject(date, includeAllCommits, jetpadReleaseInfo)
89