Skip to content

Commit c47987e

Browse files
authored
Enable label handling for integ-test workflows (#4400)
Signed-off-by: Sayali Gaikawad <gaiksaya@amazon.com>
1 parent 73d3a96 commit c47987e

File tree

6 files changed

+204
-125
lines changed

6 files changed

+204
-125
lines changed

jenkins/opensearch-dashboards/integ-test.jenkinsfile

+14-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* compatible open source license.
88
*/
99

10-
lib = library(identifier: 'jenkins@5.11.1', retriever: modernSCM([
10+
lib = library(identifier: 'jenkins@6.3.0', retriever: modernSCM([
1111

1212
$class: 'GitSCMSource',
1313
remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git',
@@ -256,14 +256,13 @@ pipeline {
256256
localPath: "${WORKSPACE}/${distribution}",
257257
switchUserNonRoot: "${switch_user_non_root}"
258258
)
259-
String closeCommentMessage = "Closing the issue as the Integration Test passed for ${local_component}<br>Version: ${version}<br>Distribution: ${distribution}<br>Architecture: ${architecture}<br>Platform: ${platform}<br><br>Please check the logs: ${RUN_DISPLAY_URL}<br><br> *"
260259
if (env.updateGithubIssues.toBoolean()) {
261-
closeGithubIssue(
260+
updateGitHubIssueLabels(
262261
repoUrl: buildManifestObj.getRepo("${local_component}"),
263-
issueTitle: "[AUTOCUT] Integration Test failed for ${local_component}: ${version} ${distribution} distribution",
264-
closeComment: closeCommentMessage,
265-
label: "autocut,v${version},integ-test-failure"
266-
)
262+
issueTitle: "[AUTOCUT] Integration Test failed for ${local_component}: ${version}",
263+
label: "${platform}:${distribution}:${architecture}",
264+
action: "remove"
265+
)
267266
}
268267
}
269268
} catch (e) {
@@ -272,10 +271,16 @@ pipeline {
272271
if (env.updateGithubIssues.toBoolean()) {
273272
createGithubIssue(
274273
repoUrl: buildManifestObj.getRepo("${local_component}"),
275-
issueTitle: "[AUTOCUT] Integration Test failed for ${local_component}: ${version} ${distribution} distribution",
274+
issueTitle: "[AUTOCUT] Integration Test failed for ${local_component}: ${version}",
276275
issueBody: issueBodyMessage,
277-
label: "autocut,v${version},integ-test-failure"
276+
label: "autocut,v${version}"
278277
)
278+
updateGitHubIssueLabels(
279+
repoUrl: buildManifestObj.getRepo("${local_component}"),
280+
issueTitle: "[AUTOCUT] Integration Test failed for ${local_component}: ${version}",
281+
label: "integ-test-failure,${platform}:${distribution}:${architecture}",
282+
action: "add"
283+
)
279284
}
280285
throw new Exception("Error running integtest for component ${local_component}", e)
281286
} finally {

jenkins/opensearch/integ-test.jenkinsfile

+14-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* compatible open source license.
88
*/
99

10-
lib = library(identifier: 'jenkins@6.1.0', retriever: modernSCM([
10+
lib = library(identifier: 'jenkins@6.3.0', retriever: modernSCM([
1111

1212
$class: 'GitSCMSource',
1313
remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git',
@@ -210,14 +210,13 @@ pipeline {
210210
localPath: "${WORKSPACE}/${distribution}",
211211
switchUserNonRoot: "${switch_user_non_root}"
212212
)
213-
String closeCommentMessage = "Closing the issue as the Integration Test passed for ${local_component}<br>Version: ${version}<br>Distribution: ${distribution}<br>Architecture: ${architecture}<br>Platform: ${platform}<br><br>Please check the logs: ${RUN_DISPLAY_URL}<br><br> *"
214213
if (env.updateGithubIssues.toBoolean()) {
215-
closeGithubIssue(
214+
updateGitHubIssueLabels(
216215
repoUrl: buildManifestObj.getRepo("${local_component}"),
217-
issueTitle: "[AUTOCUT] Integration Test failed for ${local_component}: ${version} ${distribution} distribution",
218-
closeComment: closeCommentMessage,
219-
label: "autocut,v${version},integ-test-failure"
220-
)
216+
issueTitle: "[AUTOCUT] Integration Test failed for ${local_component}: ${version}",
217+
label: "${platform}:${distribution}:${architecture}",
218+
action: "remove"
219+
)
221220
}
222221
}
223222
} catch (e) {
@@ -226,10 +225,16 @@ pipeline {
226225
if (env.updateGithubIssues.toBoolean()) {
227226
createGithubIssue(
228227
repoUrl: buildManifestObj.getRepo("${local_component}"),
229-
issueTitle: "[AUTOCUT] Integration Test failed for ${local_component}: ${version} ${distribution} distribution",
228+
issueTitle: "[AUTOCUT] Integration Test failed for ${local_component}: ${version}",
230229
issueBody: issueBodyMessage,
231-
label: "autocut,v${version},integ-test-failure"
230+
label: "autocut,v${version}"
232231
)
232+
updateGitHubIssueLabels(
233+
repoUrl: buildManifestObj.getRepo("${local_component}"),
234+
issueTitle: "[AUTOCUT] Integration Test failed for ${local_component}: ${version}",
235+
label: "integ-test-failure,${platform}:${distribution}:${architecture}",
236+
action: "add"
237+
)
233238
}
234239
throw new Exception("Error running integtest for component ${local_component}", e)
235240
} finally {

tests/jenkins/TestOpenSearchDashboardsIntegTest.groovy

+44-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
1313
import static com.lesfurets.jenkins.unit.global.lib.GitSource.gitSource
1414
import static org.hamcrest.CoreMatchers.hasItem
1515
import static org.hamcrest.CoreMatchers.equalTo
16+
import static org.hamcrest.CoreMatchers.not
1617
import static org.hamcrest.CoreMatchers.hasItems
1718
import static org.hamcrest.MatcherAssert.assertThat
1819
import static org.junit.jupiter.api.Assertions.assertThrows
@@ -25,7 +26,7 @@ class TestOpenSearchDashboardsIntegTest extends BuildPipelineTest {
2526

2627
helper.registerSharedLibrary(
2728
library().name('jenkins')
28-
.defaultVersion('5.11.1')
29+
.defaultVersion('6.3.0')
2930
.allowOverride(true)
3031
.implicit(true)
3132
.targetPath('vars')
@@ -139,35 +140,34 @@ class TestOpenSearchDashboardsIntegTest extends BuildPipelineTest {
139140
helper.addShMock("date -d \"3 days ago\" +'%Y-%m-%d'") { script ->
140141
return [stdout: "2023-10-24", exitValue: 0]
141142
}
142-
helper.addShMock("""gh issue list --repo https://github.com/opensearch-project/dashboards-visualizations.git -S "[AUTOCUT] Integration Test failed for ganttChartDashboards: 3.0.0 tar distribution in:title" --label autocut,v3.0.0,integ-test-failure --json number --jq '.[0].number'""") { script ->
143+
helper.addShMock("""gh issue list --repo https://github.com/opensearch-project/dashboards-visualizations.git -S "[AUTOCUT] Integration Test failed for ganttChartDashboards: 3.0.0 in:title" --label autocut,v3.0.0 --json number --jq '.[0].number'""") { script ->
143144
return [stdout: "", exitValue: 0]
144145
}
145-
helper.addShMock("""gh issue list --repo https://github.com/opensearch-project/dashboards-visualizations.git -S "[AUTOCUT] Integration Test failed for ganttChartDashboards: 3.0.0 tar distribution in:title is:closed closed:>=2023-10-24" --label autocut,v3.0.0,integ-test-failure --json number --jq '.[0].number'""") { script ->
146+
helper.addShMock("""gh issue list --repo https://github.com/opensearch-project/dashboards-visualizations.git -S "[AUTOCUT] Integration Test failed for ganttChartDashboards: 3.0.0 in:title is:closed closed:>=2023-10-24" --label autocut,v3.0.0 --json number --jq '.[0].number'""") { script ->
146147
return [stdout: "", exitValue: 0]
147148
}
148149
helper.addShMock('env PATH=$PATH ./test.sh integ-test manifests/tests/jenkins/data/opensearch-dashboards-3.0.0-test.yml --component ganttChartDashboards --test-run-id 215 --paths opensearch=/tmp/workspace/tar opensearch-dashboards=/tmp/workspace/tar --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/3.0.0/215/linux/x64/tar ', '', 1)
149150
assertThrows(Exception) {
150151
runScript('jenkins/opensearch-dashboards/integ-test.jenkinsfile')
151152
}
152153
assertJobStatusFailure()
153-
assertThat(getCommandExecutions('sh', 'script'), hasItem("{script=gh issue list --repo https://github.com/opensearch-project/dashboards-observability.git -S \"[AUTOCUT] Integration Test failed for observabilityDashboards: 3.0.0 tar distribution in:title\" --label autocut,v3.0.0,integ-test-failure --json number --jq '.[0].number', returnStdout=true}"))
154+
assertThat(getCommandExecutions('sh', 'script'), hasItem("{script=gh issue list --repo https://github.com/opensearch-project/dashboards-observability.git -S \"[AUTOCUT] Integration Test failed for observabilityDashboards: 3.0.0 in:title\" --json number --jq '.[0].number', returnStdout=true}"))
154155
}
155156

156157
@Test
157-
void CheckCloseGHissue() {
158+
void CheckNotClosingGHissue() {
158159
addParam('UPDATE_GITHUB_ISSUES', true)
159160
helper.addShMock("date -d \"3 days ago\" +'%Y-%m-%d'") { script ->
160161
return [stdout: "2023-10-24", exitValue: 0]
161162
}
162163
helper.addShMock('env PATH=$PATH ./test.sh integ-test manifests/tests/jenkins/data/opensearch-dashboards-3.0.0-test.yml --component observabilityDashboards --test-run-id 215 --paths opensearch=/tmp/workspace/tar opensearch-dashboards=/tmp/workspace/tar --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/3.0.0/215/linux/x64/tar ', '', 1)
163-
helper.addShMock('gh issue list --repo https://github.com/opensearch-project/dashboards-visualization.git -S "[AUTOCUT] Integration Test failed for ganttChartDashboards: 3.0.0 tar distribution in:title" --label autocut,v3.0.0,integ-test-failure', '', 0)
164+
helper.addShMock('gh issue list --repo https://github.com/opensearch-project/dashboards-visualization.git -S "[AUTOCUT] Integration Test failed for ganttChartDashboards: 3.0.0 in:title" --label autocut,v3.0.0', '', 0)
164165
assertThrows(Exception) {
165166
runScript('jenkins/opensearch-dashboards/integ-test.jenkinsfile')
166167
}
167168
assertJobStatusFailure()
168169
runScript('jenkins/opensearch-dashboards/integ-test.jenkinsfile')
169-
assertThat(getCommandExecutions('sh', 'script'), hasItem("{script=gh issue list --repo https://github.com/opensearch-project/dashboards-visualizations.git -S \"[AUTOCUT] Integration Test failed for ganttChartDashboards: 3.0.0 tar distribution in:title\" --label autocut,v3.0.0,integ-test-failure --json number --jq '.[0].number', returnStdout=true}"))
170-
assertThat(getCommandExecutions('sh', 'script'), hasItem("{script=gh issue close bbb\nccc -R opensearch-project/dashboards-visualizations --comment \"Closing the issue as the Integration Test passed for ganttChartDashboards<br>Version: 3.0.0<br>Distribution: tar<br>Architecture: x64<br>Platform: linux<br><br>Please check the logs: https://some/url/redirect<br><br> *\", returnStdout=true}"))
170+
assertThat(getCommandExecutions('sh', 'script'), not(hasItem("{script=gh issue close bbb\nccc -R opensearch-project/dashboards-visualizations --comment \"Closing the issue as the Integration Test passed for ganttChartDashboards<br>Version: 3.0.0<br>Distribution: tar<br>Architecture: x64<br>Platform: linux<br><br>Please check the logs: https://some/url/redirect<br><br> *\", returnStdout=true}")))
171171
}
172172

173173
@Test
@@ -176,10 +176,10 @@ class TestOpenSearchDashboardsIntegTest extends BuildPipelineTest {
176176
helper.addShMock("date -d \"3 days ago\" +'%Y-%m-%d'") { script ->
177177
return [stdout: "2023-10-24", exitValue: 0]
178178
}
179-
helper.addShMock("""gh issue list --repo https://github.com/opensearch-project/dashboards-observability.git -S "[AUTOCUT] Integration Test failed for observabilityDashboards: 3.0.0 tar distribution in:title is:closed closed:>=2023-10-24" --label autocut,v3.0.0,integ-test-failure --json number --jq '.[0].number'""") { script ->
179+
helper.addShMock("""gh issue list --repo https://github.com/opensearch-project/dashboards-observability.git -S "[AUTOCUT] Integration Test failed for observabilityDashboards: 3.0.0 in:title is:closed closed:>=2023-10-24" --label autocut,v3.0.0 --json number --jq '.[0].number'""") { script ->
180180
return [stdout: "", exitValue: 0]
181181
}
182-
helper.addShMock("""gh issue list --repo https://github.com/opensearch-project/sql.git -S "[AUTOCUT] Integration Test failed for observabilityDashboards: 3.0.0 tar distribution in:title" --label autocut,v3.0.0,integ-test-failure --json number --jq '.[0].number'""") { script ->
182+
helper.addShMock("""gh issue list --repo https://github.com/opensearch-project/sql.git -S "[AUTOCUT] Integration Test failed for observabilityDashboards: 3.0.0 in:title" --label autocut,v3.0.0 --json number --jq '.[0].number'""") { script ->
183183
return [stdout: "22", exitValue: 0]
184184
}
185185
helper.addShMock('env PATH=$PATH ./test.sh integ-test manifests/tests/jenkins/data/opensearch-dashboards-3.0.0-test.yml --component observabilityDashboards --test-run-id 215 --paths opensearch=/tmp/workspace/tar opensearch-dashboards=/tmp/workspace/tar --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/3.0.0/215/linux/x64/tar ', '', 1)
@@ -202,6 +202,40 @@ class TestOpenSearchDashboardsIntegTest extends BuildPipelineTest {
202202
assertThat(getCommandExecutions('sh', 'gh issue').size(), equalTo(0))
203203
}
204204

205+
@Test
206+
void verifyLabelRemoval() {
207+
addParam('UPDATE_GITHUB_ISSUES', true)
208+
helper.addShMock("""gh issue list --repo https://github.com/opensearch-project/dashboards-observability.git -S "[AUTOCUT] Integration Test failed for observabilityDashboards: 3.0.0 in:title" --json number --jq '.[0].number'""") { script ->
209+
return [stdout: '65', exitValue: 0]
210+
}
211+
helper.addShMock("""gh label list --repo https://github.com/opensearch-project/dashboards-observability.git -S linux:tar:x64 --json name --jq '.[0].name'""") { script ->
212+
return [stdout: 'linux:tar:x64', exitValue: 0]
213+
}
214+
helper.addShMock('env PATH=$PATH ./test.sh integ-test manifests/tests/jenkins/data/opensearch-dashboards-3.0.0-test.yml --component observabilityDashboards --test-run-id 215 --paths opensearch=/tmp/workspace/tar opensearch-dashboards=/tmp/workspace/tar --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/3.0.0/215/linux/x64/tar ') { script ->
215+
return [stdout: 'Completed running integtest for component observabilityDashboards', exitValue: 0]
216+
}
217+
runScript('jenkins/opensearch-dashboards/integ-test.jenkinsfile')
218+
assertThat(getCommandExecutions('sh', 'gh issue'), hasItem('{script=gh issue edit 65 -R https://github.com/opensearch-project/dashboards-observability.git --remove-label \"linux:tar:x64\", returnStdout=true}'))
219+
}
220+
221+
@Test
222+
void verifyLabelAddition() {
223+
addParam('UPDATE_GITHUB_ISSUES', true)
224+
helper.addShMock('env PATH=$PATH ./test.sh integ-test manifests/tests/jenkins/data/opensearch-dashboards-3.0.0-test.yml --component observabilityDashboards --test-run-id 215 --paths opensearch=/tmp/workspace/tar opensearch-dashboards=/tmp/workspace/tar --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/3.0.0/215/linux/x64/tar ') { script ->
225+
return [stdout: 'Error running integtest for component observabilityDashboards, creating Github issue', exitValue: 127]}
226+
helper.addShMock("""gh issue list --repo https://github.com/opensearch-project/dashboards-observability.git -S "[AUTOCUT] Integration Test failed for observabilityDashboards: 3.0.0 in:title" --json number --jq '.[0].number'""") { script ->
227+
return [stdout: '99', exitValue: 0]
228+
}
229+
helper.addShMock("""gh label list --repo https://github.com/opensearch-project/dashboards-observability.git -S linux:tar:x64 --json name --jq '.[0].name'""") { script ->
230+
return [stdout: 'no labels in opensearch-project/dashboards-observability matched your search', exitValue: 0]
231+
}
232+
assertThrows(Exception) {
233+
runScript('jenkins/opensearch/integ-test.jenkinsfile')
234+
}
235+
assertThat(getCommandExecutions('sh', 'label'), hasItem('{script=gh label create linux:tar:x64 --repo https://github.com/opensearch-project/dashboards-observability.git, returnStdout=true}'))
236+
assertThat(getCommandExecutions('sh', 'gh issue'), hasItem('{script=gh issue edit 99 -R https://github.com/opensearch-project/dashboards-observability.git --add-label \"linux:tar:x64\", returnStdout=true}'))
237+
}
238+
205239
def getCommandExecutions(methodName, command) {
206240
def shCommands = helper.callStack.findAll {
207241
call ->

0 commit comments

Comments
 (0)