forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateSha512Checksums.groovy
39 lines (35 loc) · 1.59 KB
/
createSha512Checksums.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
/*
* 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.
*/
Closure call() {
allowedFileTypes = [".tar.gz", ".zip", ".rpm"]
return { argsMap -> body: {
final foundFiles = sh(script: "find ${argsMap.artifactPath} -type f", returnStdout: true).split()
for (file in foundFiles) {
acceptTypeFound = false
for (fileType in allowedFileTypes) {
if (file.endsWith(fileType)) {
echo("Creating sha for ${file}")
final sha512 = sh(script: "sha512sum ${file}", returnStdout: true).split()
//sha512 is an array [shasum, filename]
final basename = sh(script: "basename ${sha512[1]}", returnStdout: true)
// writing to file accroding to opensearch requirement - "512shaHash<space><space>basename"
writeFile file: "${file}.sha512", text: "${sha512[0]} ${basename}"
acceptTypeFound = true
break
}
}
if (!acceptTypeFound) {
if(foundFiles.length == 1){
echo("Not generating sha for ${file} with artifact Path ${argsMap.artifactPath}, doesn't match allowed types ${allowedFileTypes}")
} else {
echo("Not generating sha for ${file} in ${argsMap.artifactPath}, doesn't match allowed types ${allowedFileTypes}")
}
}
}
}}
}