forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildManifest.groovy
137 lines (116 loc) · 4.05 KB
/
BuildManifest.groovy
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
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package jenkins
class BuildManifest implements Serializable {
class Build implements Serializable {
String id
String name
String version
String platform
String architecture
Build(Map data) {
this.id = data.id
this.name = data.name
this.version = data.version
this.platform = data.platform
this.architecture = data.architecture
}
String getFilename() {
return this.name.toLowerCase().replaceAll(' ', '-')
}
String getFilenameWithExtension(String platform = null, String architecture = null) {
String resolvedPlatform = platform ?: this.platform
String resolvedArchitecture = architecture ?: this.architecture
return "${this.getFilename()}-${this.version}-${resolvedPlatform}-${resolvedArchitecture}.${resolvedPlatform == 'windows' ? 'zip' : 'tar.gz'}"
}
String getPackageName() {
return [
this.getFilename(),
this.version,
this.platform,
this.architecture,
].join('-') + '.tar.gz'
}
}
class Components extends HashMap<String, Component> {
Components(ArrayList data) {
data.each { item ->
Component component = new Component(item)
this[component.name] = component
}
}
}
class Component implements Serializable {
String name
String version
String ref
String commit_id
String repository
Map<String, ArrayList> artifacts
Component(Map data) {
this.name = data.name
this.version = data.version
this.ref = data.ref
this.commit_id = data.commit_id
this.repository = data.repository
this.artifacts = data.artifacts ? new HashMap<>(data.artifacts) : new HashMap<>()
}
}
Build build
Components components
BuildManifest(Map data) {
this.build = new BuildManifest.Build(data.build)
this.components = new BuildManifest.Components(data.components)
}
public String getArtifactRoot(String jobName, String buildNumber) {
return [
jobName,
this.build.version,
buildNumber,
this.build.platform,
this.build.architecture
].join("/")
}
public String getIndexFileRoot(String jobName) {
return [
jobName,
this.build.version
].join("/")
}
public String getArtifactRootUrl(String publicArtifactUrl = 'https://ci.opensearch.org/ci/dbc', String jobName, String buildNumber) {
return [
publicArtifactUrl,
this.getArtifactRoot(jobName, buildNumber)
].join('/')
}
public String getUrl(String publicArtifactUrl = 'https://ci.opensearch.org/ci/dbc', String jobName, String buildNumber) {
return [
this.getArtifactRootUrl(publicArtifactUrl, jobName, buildNumber),
'builds',
this.build.getFilename(),
'manifest.yml'
].join("/")
}
public String getArtifactUrl(String publicArtifactUrl = 'https://ci.opensearch.org/ci/dbc', String jobName, String buildNumber) {
return [
this.getArtifactRootUrl(publicArtifactUrl, jobName, buildNumber),
'dist',
this.build.getFilename(),
this.build.getFilenameWithExtension()
].join("/")
}
public String getArtifactArchitecture() {
return this.build.architecture
}
public String getArtifactBuildId() {
return this.build.id
}
public String getMinArtifact() {
components.get(build.name.replace(' ','-'))?.artifacts?.get("dist")?.first()
}
}