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