mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
Enable golang
This commit is contained in:
parent
1870c6ab9c
commit
8da169d2a8
@ -305,9 +305,9 @@ steps:
|
|||||||
- 'buildDescriptor'
|
- 'buildDescriptor'
|
||||||
- 'opensourceConfiguration'
|
- 'opensourceConfiguration'
|
||||||
golang:
|
golang:
|
||||||
buildDescriptorFile: './setup.py'
|
buildDescriptorFile: './glide.yaml'
|
||||||
dockerImage: 'golang:1.12.1-stretch'
|
dockerImage: 'instrumentisto/glide:0.13.1-go1.10'
|
||||||
dockerWorkspace: '/home/golang'
|
dockerWorkspace: '/home/glide'
|
||||||
stashContent:
|
stashContent:
|
||||||
- 'buildDescriptor'
|
- 'buildDescriptor'
|
||||||
- 'opensourceConfiguration'
|
- 'opensourceConfiguration'
|
||||||
|
@ -72,7 +72,7 @@ def getSbtGAV(file = 'sbtDescriptor.json') {
|
|||||||
|
|
||||||
def getPipGAV(file = 'setup.py') {
|
def getPipGAV(file = 'setup.py') {
|
||||||
def result = [:]
|
def result = [:]
|
||||||
def descriptor = sh(returnStdout: true, script: "cat ${file}")
|
def descriptor = readFile(file: file)
|
||||||
|
|
||||||
result['group'] = ''
|
result['group'] = ''
|
||||||
result['packaging'] = ''
|
result['packaging'] = ''
|
||||||
@ -81,16 +81,41 @@ def getPipGAV(file = 'setup.py') {
|
|||||||
|
|
||||||
if (result['version'] == '' || matches(method, result['version'])) {
|
if (result['version'] == '' || matches(method, result['version'])) {
|
||||||
file = file.replace('setup.py', 'version.txt')
|
file = file.replace('setup.py', 'version.txt')
|
||||||
def versionString = sh(returnStdout: true, script: "cat ${file}")
|
result['version'] = getVersionFromFile(file)
|
||||||
if (versionString) {
|
|
||||||
result['version'] = versionString.trim()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "loaded ${result} from ${file}"
|
echo "loaded ${result} from ${file}"
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def getGoGAV(file = './') {
|
||||||
|
def f = new File(file)
|
||||||
|
def path = f.getAbsoluteFile().getParentFile()
|
||||||
|
def result = [:]
|
||||||
|
|
||||||
|
result['group'] = ''
|
||||||
|
result['packaging'] = ''
|
||||||
|
result['artifact'] = path.getName()
|
||||||
|
file = new File(path, 'version.txt').getAbsolutePath()
|
||||||
|
result['version'] = getVersionFromFile(file)
|
||||||
|
|
||||||
|
if (!result['version']) {
|
||||||
|
file = new File(path, 'VERSION').getAbsolutePath()
|
||||||
|
result['version'] = getVersionFromFile(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "loaded ${result} from ${file}"
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
private getVersionFromFile(file) {
|
||||||
|
def versionString = readFile(file: file)
|
||||||
|
if (versionString) {
|
||||||
|
return versionString.trim()
|
||||||
|
}
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
@NonCPS
|
@NonCPS
|
||||||
private def matches(regex, input) {
|
private def matches(regex, input) {
|
||||||
def m = new Matcher(regex, input)
|
def m = new Matcher(regex, input)
|
||||||
|
@ -452,6 +452,63 @@ class WhitesourceExecuteScanTest extends BasePiperTest {
|
|||||||
assertThat(writeFileRule.files['./wss-unified-agent.config.d3aa80454919391024374ba46b4df082d15ab9a3'], containsString('projectName=com.sap.sbt.test-scala'))
|
assertThat(writeFileRule.files['./wss-unified-agent.config.d3aa80454919391024374ba46b4df082d15ab9a3'], containsString('projectName=com.sap.sbt.test-scala'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGo() {
|
||||||
|
helper.registerAllowedMethod("readFile", [Map.class], {
|
||||||
|
map ->
|
||||||
|
def path = 'test/resources/DescriptorUtils/go/' + map.file.substring(map.file.lastIndexOf(File.separator) + 1, map.file.length())
|
||||||
|
def descriptorFile = new File(path)
|
||||||
|
if(descriptorFile.exists())
|
||||||
|
return descriptorFile.text
|
||||||
|
else
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
helper.registerAllowedMethod("readProperties", [Map], {
|
||||||
|
def result = new Properties()
|
||||||
|
result.putAll([
|
||||||
|
"apiKey": "b39d1328-52e2-42e3-98f0-932709daf3f0",
|
||||||
|
"productName": "SHC - Piper",
|
||||||
|
"checkPolicies": "true",
|
||||||
|
"projectName": "python-test",
|
||||||
|
"projectVersion": "1.0.0"
|
||||||
|
])
|
||||||
|
return result
|
||||||
|
})
|
||||||
|
|
||||||
|
stepRule.step.whitesourceExecuteScan([
|
||||||
|
script : nullScript,
|
||||||
|
whitesourceRepositoryStub : whitesourceStub,
|
||||||
|
whitesourceOrgAdminRepositoryStub : whitesourceOrgAdminRepositoryStub,
|
||||||
|
descriptorUtilsStub : descriptorUtilsStub,
|
||||||
|
scanType : 'golang',
|
||||||
|
juStabUtils : utils,
|
||||||
|
productName : 'testProductName',
|
||||||
|
orgToken : 'testOrgToken',
|
||||||
|
reporting : false,
|
||||||
|
buildDescriptorFile : './myProject/glide.yaml'
|
||||||
|
])
|
||||||
|
|
||||||
|
assertThat(loggingRule.log, containsString('Unstash content: buildDescriptor'))
|
||||||
|
assertThat(loggingRule.log, containsString('Unstash content: opensourceConfiguration'))
|
||||||
|
|
||||||
|
assertThat(dockerExecuteRule.dockerParams, hasEntry('dockerImage', 'instrumentisto/glide:0.13.1-go1.10'))
|
||||||
|
assertThat(dockerExecuteRule.dockerParams, hasEntry('dockerWorkspace', '/home/glide'))
|
||||||
|
assertThat(dockerExecuteRule.dockerParams, hasEntry('stashContent', ['buildDescriptor', 'opensourceConfiguration', 'modified whitesource config d3aa80454919391024374ba46b4df082d15ab9a3']))
|
||||||
|
|
||||||
|
assertThat(shellRule.shell, Matchers.hasItems(
|
||||||
|
is('curl --location --output wss-unified-agent.jar https://github.com/whitesource/unified-agent-distribution/raw/master/standAlone/wss-unified-agent.jar'),
|
||||||
|
is('./bin/java -jar wss-unified-agent.jar -c \'./myProject/wss-unified-agent.config.d3aa80454919391024374ba46b4df082d15ab9a3\' -apiKey \'testOrgToken\' -userKey \'token-0815\' -product \'testProductName\'')
|
||||||
|
))
|
||||||
|
|
||||||
|
assertThat(writeFileRule.files['./myProject/wss-unified-agent.config.d3aa80454919391024374ba46b4df082d15ab9a3'], containsString('apiKey=testOrgToken'))
|
||||||
|
assertThat(writeFileRule.files['./myProject/wss-unified-agent.config.d3aa80454919391024374ba46b4df082d15ab9a3'], containsString('productName=testProductName'))
|
||||||
|
assertThat(writeFileRule.files['./myProject/wss-unified-agent.config.d3aa80454919391024374ba46b4df082d15ab9a3'], containsString('userKey=token-0815'))
|
||||||
|
assertThat(writeFileRule.files['./myProject/wss-unified-agent.config.d3aa80454919391024374ba46b4df082d15ab9a3'], containsString('productVersion=1.2.3'))
|
||||||
|
assertThat(writeFileRule.files['./myProject/wss-unified-agent.config.d3aa80454919391024374ba46b4df082d15ab9a3'], containsString('projectName=myProject'))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAgentNoDownloads() {
|
void testAgentNoDownloads() {
|
||||||
helper.registerAllowedMethod("readProperties", [Map], {
|
helper.registerAllowedMethod("readProperties", [Map], {
|
||||||
|
@ -131,9 +131,9 @@ class DescriptorUtilsTest extends BasePiperTest {
|
|||||||
@Test
|
@Test
|
||||||
void testGetPipGAV() {
|
void testGetPipGAV() {
|
||||||
|
|
||||||
helper.registerAllowedMethod("sh", [Map.class], {
|
helper.registerAllowedMethod("readFile", [Map.class], {
|
||||||
map ->
|
map ->
|
||||||
def descriptorFile = new File("test/resources/utilsTest/${map.script.substring(4, map.script.size())}")
|
def descriptorFile = new File("test/resources/utilsTest/${map.file}")
|
||||||
return descriptorFile.text
|
return descriptorFile.text
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -147,9 +147,9 @@ class DescriptorUtilsTest extends BasePiperTest {
|
|||||||
@Test
|
@Test
|
||||||
void testGetPipGAVFromVersionTxt() {
|
void testGetPipGAVFromVersionTxt() {
|
||||||
|
|
||||||
helper.registerAllowedMethod("sh", [Map.class], {
|
helper.registerAllowedMethod("readFile", [Map.class], {
|
||||||
map ->
|
map ->
|
||||||
def descriptorFile = new File("test/resources/DescriptorUtils/pip/${map.script.substring(4, map.script.size())}")
|
def descriptorFile = new File("test/resources/DescriptorUtils/pip/${map.file}")
|
||||||
return descriptorFile.text
|
return descriptorFile.text
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -208,4 +208,24 @@ class DescriptorUtilsTest extends BasePiperTest {
|
|||||||
assertEquals(gav.version, '1.2.4')
|
assertEquals(gav.version, '1.2.4')
|
||||||
assertEquals(gav.packaging, 'jar')
|
assertEquals(gav.packaging, 'jar')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetGoGAV() {
|
||||||
|
|
||||||
|
helper.registerAllowedMethod("readFile", [Map.class], {
|
||||||
|
map ->
|
||||||
|
def path = 'test/resources/DescriptorUtils/go/' + map.file.substring(map.file.lastIndexOf(File.separator) + 1, map.file.length())
|
||||||
|
def descriptorFile = new File(path)
|
||||||
|
if(descriptorFile.exists())
|
||||||
|
return descriptorFile.text
|
||||||
|
else
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
def gav = descriptorUtils.getGoGAV('./myProject/glide.yaml')
|
||||||
|
|
||||||
|
assertEquals('', gav.group)
|
||||||
|
assertEquals('myProject', gav.artifact)
|
||||||
|
assertEquals('1.2.3', gav.version)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ class WhiteSourceConfigurationHelperTest extends BasePiperTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testExtendConfigurationFileUnifiedAgentVerbose() {
|
void testExtendConfigurationFileUnifiedAgentGolangVerbose() {
|
||||||
def config = [scanType: 'golang', whitesource: [configFilePath: './config', serviceUrl: "http://some.host.whitesource.com/api/", orgToken: 'abcd', productName: 'SHC - name2', productToken: '1234', userKey: '0000'], stashContent: ['some', 'stashes'], verbose: true]
|
def config = [scanType: 'golang', whitesource: [configFilePath: './config', serviceUrl: "http://some.host.whitesource.com/api/", orgToken: 'abcd', productName: 'SHC - name2', productToken: '1234', userKey: '0000'], stashContent: ['some', 'stashes'], verbose: true]
|
||||||
WhitesourceConfigurationHelper.extendUAConfigurationFile(nullScript, utils, config, "./")
|
WhitesourceConfigurationHelper.extendUAConfigurationFile(nullScript, utils, config, "./")
|
||||||
assertThat(jwfr.files['./config.847f9aec2f93de9000d5fa4e6eaace2283ae6377'], containsString("apiKey=abcd"))
|
assertThat(jwfr.files['./config.847f9aec2f93de9000d5fa4e6eaace2283ae6377'], containsString("apiKey=abcd"))
|
||||||
|
1
test/resources/DescriptorUtils/go/VERSION
Normal file
1
test/resources/DescriptorUtils/go/VERSION
Normal file
@ -0,0 +1 @@
|
|||||||
|
1.2.3
|
@ -353,6 +353,13 @@ private def triggerWhitesourceScanWithUserKey(script, config, utils, descriptorU
|
|||||||
config.whitesource.projectName = gav.artifact
|
config.whitesource.projectName = gav.artifact
|
||||||
config.whitesource.productVersion = gav.version
|
config.whitesource.productVersion = gav.version
|
||||||
break
|
break
|
||||||
|
case 'golang':
|
||||||
|
gav = descriptorUtils.getGoGAV(config.buildDescriptorFile)
|
||||||
|
config.whitesource.projectName = gav.artifact
|
||||||
|
config.whitesource.productVersion = gav.version
|
||||||
|
break
|
||||||
|
case 'dlang':
|
||||||
|
break
|
||||||
case 'maven':
|
case 'maven':
|
||||||
gav = descriptorUtils.getMavenGAV(config.buildDescriptorFile)
|
gav = descriptorUtils.getMavenGAV(config.buildDescriptorFile)
|
||||||
config.whitesource.projectName = gav.group + "." + gav.artifact
|
config.whitesource.projectName = gav.group + "." + gav.artifact
|
||||||
|
Loading…
Reference in New Issue
Block a user