Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Add support for go packages with explicit versions (#1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
v1v authored Jul 6, 2022
1 parent 1ac3086 commit 53368eb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/test/groovy/WithGoEnvUnixStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ class WithGoEnvUnixStepTests extends ApmBasePipelineTest {
assertJobStatusSuccess()
}

@Test
void testPkgs_with_version() throws Exception {
helper.registerAllowedMethod('nodeOS', [], { "linux" })
def isOK = false
script.call(version: "1.16.1", pkgs: [ "P1@1", "P2@2" ]){
isOK = true
}
printCallStack()
assertTrue(isOK)
assertTrue(assertMethodCallContainsPattern('sh', 'go install P1@1'))
assertTrue(assertMethodCallContainsPattern('sh', 'go install P2@2'))
assertJobStatusSuccess()
}

@Test
void testDefaultGoVersion() throws Exception {
helper.registerAllowedMethod('nodeOS', [], { "linux" })
Expand Down
13 changes: 13 additions & 0 deletions src/test/groovy/WithGoEnvWindowsStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ void testOSArg() throws Exception {
assertJobStatusSuccess()
}

@Test
void testPkgs_with_version() throws Exception {
def isOK = false
script.call(version: "1.16.1", pkgs: [ "P1@1", "P2@2" ]){
isOK = definedVariables('1.16.1', 'windows')
}
printCallStack()
assertTrue(isOK)
assertTrue(assertMethodCallContainsPattern('bat', 'go install P1@1'))
assertTrue(assertMethodCallContainsPattern('bat', 'go install P2@2'))
assertJobStatusSuccess()
}

@Test
void testDefaultGoVersion() throws Exception {
helper.registerAllowedMethod('nodeOS', [], { "windows" })
Expand Down
7 changes: 6 additions & 1 deletion vars/withGoEnvUnix.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ def installPackages(Map args = [:]) {
def atVersion = isBeforeGo1_16(version: version) ? '' : "@latest"
withEnv(["GOARCH=${arch}"]){
args.pkgs?.each{ p ->
// If the package is already with the given version then use it
def packageWithVersion = "${p}${atVersion}"
if (p.contains('@')) {
packageWithVersion = "${p}"
}
retryWithSleep(retries: 3, seconds: 5, backoff: true){
sh(label: "Installing ${p}", script: "go ${method} ${p}${atVersion}")
sh(label: "Installing ${packageWithVersion}", script: "go ${method} ${packageWithVersion}")
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion vars/withGoEnvWindows.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ def call(Map args = [:], Closure body) {
bat(label: "Installing Go ${version}", script: content)
}
pkgs?.each{ p ->
// If the package is already with the given version then use it
def packageWithVersion = "${p}${atVersion}"
if (p.contains('@')) {
packageWithVersion = "${p}"
}
retryWithSleep(retries: 3, seconds: 5, backoff: true){
bat(label: "Installing ${p}", script: "go ${method} ${p}${atVersion}")
bat(label: "Installing ${packageWithVersion}", script: "go ${method} ${packageWithVersion}")
}
}
body()
Expand Down

0 comments on commit 53368eb

Please sign in to comment.