-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
179 lines (155 loc) · 4.79 KB
/
build.gradle
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
def requiredVersionTerraform = "^1.1.2"
def requiredVersionNodeJS = "^18.0.0"
def requiredVersionTsc = "^4.3.5"
buildscript {
dependencies {
classpath localGroovy()
}
}
allprojects {
ext {
if (org.gradle.internal.os.OperatingSystem.current().isWindows()) {
nodeExecutable = ["node"]
ngExecutable = ["cmd", "/c", "ng"]
npmExecutable = ["cmd", "/c", "npm"]
terraformExecutable = ["cmd", "/c", "terraform"]
tscExecutable = ["cmd", "/c", "tsc"]
} else {
nodeExecutable = ["node"]
ngExecutable = ["ng"]
npmExecutable = ["npm"]
terraformExecutable = ["terraform"]
tscExecutable = ["tsc"]
}
}
}
static def isSemVerMatching(String actual, String expected) {
def beginIndex
def equalParts
if (expected.startsWith("^")) {
beginIndex = 1
equalParts = 1
} else if (expected.startsWith("~")) {
beginIndex = 1
equalParts = 2
} else {
beginIndex = 0
equalParts = 3
}
def expectedParts = expected.substring(beginIndex).split(/\./).collect { it as int }
def actualParts = actual.split(/\./).collect { it as int }
for (def i = 0; i < expectedParts.size(); i++) {
if (i < equalParts) {
if (actualParts[i] != expectedParts[i]) {
return false
}
} else {
if (actualParts[i] > expectedParts[i]) {
return true
}
if (actualParts[i] < expectedParts[i]) {
return false
}
}
}
return true
}
def getVersionNodeJS() {
def stdout = new ByteArrayOutputStream()
def stderr = new ByteArrayOutputStream()
try {
exec {
commandLine nodeExecutable
args "--version"
standardOutput stdout
errorOutput stderr
}
} catch (Exception ignored) {
}
return stdout.toString().trim().replace("v", "")
}
def getVersionTerraform() {
def stdout = new ByteArrayOutputStream()
def stderr = new ByteArrayOutputStream()
try {
exec {
commandLine terraformExecutable
args "--version"
standardOutput stdout
errorOutput stderr
}
} catch (Exception ignored) {
}
return stdout.toString().split("\n")[0].trim().replace("Terraform v", "")
}
def getVersionTsc() {
def stdout = new ByteArrayOutputStream()
def stderr = new ByteArrayOutputStream()
try {
exec {
commandLine tscExecutable
args "--v"
standardOutput stdout
errorOutput stderr
}
} catch (Exception ignored) {
}
return stdout.toString().trim().replace("Version ", "")
}
task verifyNodeJS {
def actualVersion = getVersionNodeJS()
inputs.property("VERSION_NODE_JS", requiredVersionNodeJS)
outputs.upToDateWhen { isSemVerMatching(actualVersion, requiredVersionNodeJS) }
doLast {
if (!isSemVerMatching(actualVersion, requiredVersionNodeJS)) {
throw new Exception("Required Node version " + requiredVersionNodeJS + " not found. Detected version " + actualVersion)
}
}
}
task verifyTerraform {
def actualVersion = getVersionTerraform()
inputs.property("VERSION_TERRAFORM", requiredVersionTerraform)
outputs.upToDateWhen { isSemVerMatching(actualVersion, requiredVersionTerraform) }
doLast {
if (!isSemVerMatching(actualVersion, requiredVersionTerraform)) {
throw new Exception("Required Terraform version " + requiredVersionTerraform + " not found. Detected version " + actualVersion)
}
}
}
task verifyTsc {
def actualVersion = getVersionTsc()
inputs.property("VERSION_TSC", requiredVersionTsc)
outputs.upToDateWhen { isSemVerMatching(actualVersion, requiredVersionTsc) }
doLast {
if (!isSemVerMatching(actualVersion, requiredVersionTsc)) {
throw new Exception("Required tsc version " + requiredVersionTsc + " not found. Detected version " + actualVersion)
}
}
}
task build {
dependsOn "aws:build"
}
task clean {}
afterEvaluate {
// avoiding simultaneous connections to npmjs.com
def prevTask = null
project.subprojects.each {
def task = it.tasks.find { task -> task.name.contains('npmUpdate') }
if (task != null) {
if (prevTask != null) {
task.mustRunAfter(prevTask)
}
prevTask = task
}
}
prevTask = null
project.subprojects.each {
def task = it.tasks.find { task -> task.name.contains('npmInstall') }
if (task != null) {
if (prevTask != null) {
task.mustRunAfter(prevTask)
}
prevTask = task
}
}
}