-
Notifications
You must be signed in to change notification settings - Fork 6
/
gbBuildCheck.py
124 lines (110 loc) · 3.97 KB
/
gbBuildCheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import os
import sys
import time
import requests
import json
cQuery = str(sys.argv[2])
level = str(sys.argv[3])
buildType = str(sys.argv[4])
key = str(sys.argv[1])
print(os.environ['GITHUB_WORKSPACE'])
def run_query(query, key):
try:
headers = {"Authorization": "Bearer %s" % key}
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
return request.json()
except Exception as e:
return(e)
def findDate(queryResponse):
for i in range(0, len(queryResponse["data"]["repository"]["object"]["blame"]["ranges"])):
curDate = queryResponse["data"]["repository"]["object"]["blame"]["ranges"][i]["commit"]["committedDate"]
if(i == 0):
recentDate = curDate
else:
if(recentDate < curDate):
recentDate = curDate
return(recentDate)
sourceQuery = """
{
repository(owner: \"wmgeolab\", name: \"geoBoundaries\") {
object(expression: \"main\") {
... on Commit {
blame(path: \"sourceData/"""+buildType+"""/"""+cQuery+"""_"""+level+""".zip\") {
ranges {
commit {
committedDate
}
}
}
}
}
}
}
"""
result = run_query(sourceQuery, key)
buildQuery = """
{
repository(owner: \"wmgeolab\", name: \"geoBoundaries\") {
object(expression: \"main\") {
... on Commit {
blame(path: \"releaseData/"""+buildType+"""/"""+cQuery+"""/"""+level+"""/geoBoundaries-"""+cQuery+"""-"""+level+"""-all.zip\") {
ranges {
commit {
committedDate
}
}
}
}
}
}
}
"""
codeQuery = """
{
repository(owner: \"wmgeolab\", name: \"geoBoundaryBot\") {
object(expression: \"main\") {
... on Commit {
blame(path: \"gbBuild.py\") {
ranges {
commit {
committedDate
}
}
}
}
}
}
}
"""
print(result)
sysExit = 0
annotationPayload = ""
try:
commitDate = findDate(result)
print("Most recent source file is from " + commitDate + ". Contrasting to build.")
try:
buildResult = run_query(buildQuery, key)
buildDate = findDate(buildResult)
print("Most recent build is from " + buildDate +".")
if(buildDate > commitDate):
print("Build is already up-to-date. Confirming build script has not updated.")
codeResult = run_query(codeQuery, key)
codeDate = findDate(codeResult)
print("Most recent code is from " + codeDate)
if(buildDate > codeDate):
annotationPayload = "Build is up-to-date with most recent build script. No further actions necessary."
print(annotationPayload)
sysExit = 1
else:
print("Build script has been updated. Re-running build.")
else:
print("Source is newer than build data. Commencing new build.")
except:
print("No build file for this layer currently exists in the repository. Commencing new build.")
except:
annotationPayload = "No source file for this layer currently exists in the repository. Skipping any further action."
print(annotationPayload)
sys.exit("No source file in the repository.")
if(sysExit == 1):
annotationPayload = "Build is already up to date."
sys.exit(annotationPayload)