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

Commit 53368eb

Browse files
authored
Add support for go packages with explicit versions (#1764)
1 parent 1ac3086 commit 53368eb

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

src/test/groovy/WithGoEnvUnixStepTests.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,20 @@ class WithGoEnvUnixStepTests extends ApmBasePipelineTest {
171171
assertJobStatusSuccess()
172172
}
173173

174+
@Test
175+
void testPkgs_with_version() throws Exception {
176+
helper.registerAllowedMethod('nodeOS', [], { "linux" })
177+
def isOK = false
178+
script.call(version: "1.16.1", pkgs: [ "P1@1", "P2@2" ]){
179+
isOK = true
180+
}
181+
printCallStack()
182+
assertTrue(isOK)
183+
assertTrue(assertMethodCallContainsPattern('sh', 'go install P1@1'))
184+
assertTrue(assertMethodCallContainsPattern('sh', 'go install P2@2'))
185+
assertJobStatusSuccess()
186+
}
187+
174188
@Test
175189
void testDefaultGoVersion() throws Exception {
176190
helper.registerAllowedMethod('nodeOS', [], { "linux" })

src/test/groovy/WithGoEnvWindowsStepTests.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ void testOSArg() throws Exception {
119119
assertJobStatusSuccess()
120120
}
121121

122+
@Test
123+
void testPkgs_with_version() throws Exception {
124+
def isOK = false
125+
script.call(version: "1.16.1", pkgs: [ "P1@1", "P2@2" ]){
126+
isOK = definedVariables('1.16.1', 'windows')
127+
}
128+
printCallStack()
129+
assertTrue(isOK)
130+
assertTrue(assertMethodCallContainsPattern('bat', 'go install P1@1'))
131+
assertTrue(assertMethodCallContainsPattern('bat', 'go install P2@2'))
132+
assertJobStatusSuccess()
133+
}
134+
122135
@Test
123136
void testDefaultGoVersion() throws Exception {
124137
helper.registerAllowedMethod('nodeOS', [], { "windows" })

vars/withGoEnvUnix.groovy

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@ def installPackages(Map args = [:]) {
7373
def atVersion = isBeforeGo1_16(version: version) ? '' : "@latest"
7474
withEnv(["GOARCH=${arch}"]){
7575
args.pkgs?.each{ p ->
76+
// If the package is already with the given version then use it
77+
def packageWithVersion = "${p}${atVersion}"
78+
if (p.contains('@')) {
79+
packageWithVersion = "${p}"
80+
}
7681
retryWithSleep(retries: 3, seconds: 5, backoff: true){
77-
sh(label: "Installing ${p}", script: "go ${method} ${p}${atVersion}")
82+
sh(label: "Installing ${packageWithVersion}", script: "go ${method} ${packageWithVersion}")
7883
}
7984
}
8085
}

vars/withGoEnvWindows.groovy

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ def call(Map args = [:], Closure body) {
6363
bat(label: "Installing Go ${version}", script: content)
6464
}
6565
pkgs?.each{ p ->
66+
// If the package is already with the given version then use it
67+
def packageWithVersion = "${p}${atVersion}"
68+
if (p.contains('@')) {
69+
packageWithVersion = "${p}"
70+
}
6671
retryWithSleep(retries: 3, seconds: 5, backoff: true){
67-
bat(label: "Installing ${p}", script: "go ${method} ${p}${atVersion}")
72+
bat(label: "Installing ${packageWithVersion}", script: "go ${method} ${packageWithVersion}")
6873
}
6974
}
7075
body()

0 commit comments

Comments
 (0)