blob: eedeb336f62cfb507b01d77c143f5ba53c8aa0e8 [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:
23 rawJetpadReleaseOutput = subprocess.check_output('span sql /span/global/androidx-jetpad:prod_instance \"SELECT GroupId, ArtifactId, ReleaseVersion, PreviousReleaseSHA, ReleaseSHA, Path, RequireSameVersionGroupBuild FROM LibraryReleases WHERE ReleaseDate = %s\"' % date, shell=True)
24 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]
50 if path[0] == '/': path = path[1:]
51 requiresSameVersion = False
52 if artifactIdReleaseLine[7] == "true":
53 requiresSameVersion = True
54 if groupId in releaseJsonObject["modules"]:
55 releaseJsonObject["modules"][groupId].append({
56 "groupId": groupId,
57 "artifactId": artifactId,
58 "version": version,
59 "fromSHA": fromSHA,
60 "untilSHA": untilSHA,
61 "requiresSameVersion": requiresSameVersion,
62 "path": path
63 })
64 else:
65 releaseJsonObject["modules"][groupId] = [{
66 "groupId": groupId,
67 "artifactId": artifactId,
68 "version": version,
69 "fromSHA": fromSHA,
70 "untilSHA": untilSHA,
71 "requiresSameVersion": requiresSameVersion,
72 "path": path
73 }]
74 return releaseJsonObject
75
76def getJetpadRelease(date, includeAllCommits):
77 print("Getting the release info from Jetpad...")
78 jetpadReleaseInfo = getJetpadReleaseInfo(date)
79 if not jetpadReleaseInfo:
80 exit(1)
81 print("Successful")
82 return getReleaseInfoObject(date, includeAllCommits, jetpadReleaseInfo)
83