1
0
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:
Sven Merk 2019-03-22 11:55:50 +01:00
parent 1870c6ab9c
commit 8da169d2a8
7 changed files with 123 additions and 13 deletions

View File

@ -305,9 +305,9 @@ steps:
- 'buildDescriptor'
- 'opensourceConfiguration'
golang:
buildDescriptorFile: './setup.py'
dockerImage: 'golang:1.12.1-stretch'
dockerWorkspace: '/home/golang'
buildDescriptorFile: './glide.yaml'
dockerImage: 'instrumentisto/glide:0.13.1-go1.10'
dockerWorkspace: '/home/glide'
stashContent:
- 'buildDescriptor'
- 'opensourceConfiguration'

View File

@ -72,7 +72,7 @@ def getSbtGAV(file = 'sbtDescriptor.json') {
def getPipGAV(file = 'setup.py') {
def result = [:]
def descriptor = sh(returnStdout: true, script: "cat ${file}")
def descriptor = readFile(file: file)
result['group'] = ''
result['packaging'] = ''
@ -81,16 +81,41 @@ def getPipGAV(file = 'setup.py') {
if (result['version'] == '' || matches(method, result['version'])) {
file = file.replace('setup.py', 'version.txt')
def versionString = sh(returnStdout: true, script: "cat ${file}")
if (versionString) {
result['version'] = versionString.trim()
}
result['version'] = getVersionFromFile(file)
}
echo "loaded ${result} from ${file}"
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
private def matches(regex, input) {
def m = new Matcher(regex, input)

View File

@ -452,6 +452,63 @@ class WhitesourceExecuteScanTest extends BasePiperTest {
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
void testAgentNoDownloads() {
helper.registerAllowedMethod("readProperties", [Map], {

View File

@ -131,9 +131,9 @@ class DescriptorUtilsTest extends BasePiperTest {
@Test
void testGetPipGAV() {
helper.registerAllowedMethod("sh", [Map.class], {
helper.registerAllowedMethod("readFile", [Map.class], {
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
})
@ -147,9 +147,9 @@ class DescriptorUtilsTest extends BasePiperTest {
@Test
void testGetPipGAVFromVersionTxt() {
helper.registerAllowedMethod("sh", [Map.class], {
helper.registerAllowedMethod("readFile", [Map.class], {
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
})
@ -208,4 +208,24 @@ class DescriptorUtilsTest extends BasePiperTest {
assertEquals(gav.version, '1.2.4')
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)
}
}

View File

@ -90,7 +90,7 @@ class WhiteSourceConfigurationHelperTest extends BasePiperTest {
}
@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]
WhitesourceConfigurationHelper.extendUAConfigurationFile(nullScript, utils, config, "./")
assertThat(jwfr.files['./config.847f9aec2f93de9000d5fa4e6eaace2283ae6377'], containsString("apiKey=abcd"))

View File

@ -0,0 +1 @@
1.2.3

View File

@ -353,6 +353,13 @@ private def triggerWhitesourceScanWithUserKey(script, config, utils, descriptorU
config.whitesource.projectName = gav.artifact
config.whitesource.productVersion = gav.version
break
case 'golang':
gav = descriptorUtils.getGoGAV(config.buildDescriptorFile)
config.whitesource.projectName = gav.artifact
config.whitesource.productVersion = gav.version
break
case 'dlang':
break
case 'maven':
gav = descriptorUtils.getMavenGAV(config.buildDescriptorFile)
config.whitesource.projectName = gav.group + "." + gav.artifact