Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor releaseTag workflow and add tests #4974

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions jenkins/release-workflows/release-tag.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,43 @@ pipeline {
description: 'Version of the release.',
trim: true
)
choice(
choices: ['opensearch', 'opensearch-dashboards'],
name: 'PRODUCT',
description: 'Product for tag creation.'
)
}
environment {
DISTRIBUTION_MANIFEST = "$PRODUCT-$VERSION/manifest.yml"
OS_DISTRIBUTION_MANIFEST = "opensearch-$VERSION/manifest.yml"
OSD_DISTRIBUTION_MANIFEST = "opensearch-dashboards-$VERSION/manifest.yml"
}
stages {
stage('Create Release Tag') {
stage('Create Release Tag for OpenSearch components') {
steps {
script {
release_url = "https://artifacts.opensearch.org/releases/bundle/$PRODUCT/$VERSION/$PRODUCT-$VERSION-linux-x64.tar.gz"
sh "curl -SLO $release_url && tar -xf $PRODUCT-$VERSION-linux-x64.tar.gz $PRODUCT-$VERSION/manifest.yml"
echo "The release distribution manifest is downloaded to $DISTRIBUTION_MANIFEST"
os_artifact_url = "https://artifacts.opensearch.org/releases/bundle/opensearch/$VERSION/opensearch-$VERSION-linux-x64.tar.gz"
sh "curl -SLO $os_artifact_url && tar -xf opensearch-$VERSION-linux-x64.tar.gz ${OS_DISTRIBUTION_MANIFEST}"
echo "The release distribution manifest is downloaded to $OS_DISTRIBUTION_MANIFEST"
createReleaseTag(
distManifest: "$DISTRIBUTION_MANIFEST",
distManifest: "$OS_DISTRIBUTION_MANIFEST",
tagVersion: VERSION
)
}
}
}
stage('Create Release Tag for OpenSearch-Dasboards components') {
steps {
script {
osd_artifact_url = "https://artifacts.opensearch.org/releases/bundle/opensearch-dashboards/$VERSION/opensearch-dashboards-$VERSION-linux-x64.tar.gz"
sh "curl -SLO $osd_artifact_url && tar -xf opensearch-dashboards-$VERSION-linux-x64.tar.gz ${OSD_DISTRIBUTION_MANIFEST}l"
echo "The release distribution manifest is downloaded to $OSD_DISTRIBUTION_MANIFEST"
createReleaseTag(
distManifest: "$OSD_DISTRIBUTION_MANIFEST",
tagVersion: VERSION
)

}
}
}
stage('Update Manifest') {
stage('Lock Manifests to tags') {
steps {
echo 'Triggering manifest lock workflow'
build job: 'release-manifest-commit-lock', wait: true, parameters: [
string(name: 'RELEASE_VERSION', value: "${params.RELEASE_VERSION}"),
string(name: 'RELEASE_VERSION', value: "${params.VERSION}"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How we lock the manifest to tag in this triggered job? We have a product parameters in this tag creation job but seems like we locked both OS & OSD manifests with tags in one job.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are in discussion to merge both OS and OSD tag creation into one run.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified the workflow to accommodate both OS and OSD tag creation. In this way manifest lock would also happen once and for all.
Thanks!

string(name: 'MANIFEST_LOCK_ACTION', value: "UPDATE_TO_TAGS")
]
echo 'Pull Request to lock manifest created successfully!'
Expand Down
98 changes: 98 additions & 0 deletions tests/jenkins/TestReleaseTagJob.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
import jenkins.tests.BuildPipelineTest
import org.junit.Before
import org.junit.Test
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
import static com.lesfurets.jenkins.unit.global.lib.GitSource.gitSource
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
import static org.assertj.core.api.Assertions.assertThat
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.CoreMatchers.hasItems
import org.yaml.snakeyaml.Yaml


class TestReleaseTag extends BuildPipelineTest {

@Override
@Before
void setUp() {
String releaseVersion = '2.16.0'

helper.registerSharedLibrary(
library().name('jenkins')
.defaultVersion('1.0.4')
.allowOverride(true)
.implicit(true)
.targetPath('vars')
.retriever(gitSource('https://github.com/opensearch-project/opensearch-build-libraries.git'))
.build()
)
super.setUp()
addParam('VERSION', releaseVersion)
binding.setVariable('GITHUB_BOT_TOKEN_NAME', 'github_bot_token_name')
binding.setVariable('env', [
'VERSION': releaseVersion,
'OS_DISTRIBUTION_MANIFEST': 'opensearch-2.16.0/manifest.yml',
'OSD_DISTRIBUTION_MANIFEST': 'opensearch-dashboards-2.16.0/manifest.yml'
])
helper.registerAllowedMethod('readYaml', [Map.class], { args ->
if (args.file == 'opensearch-2.16.0/manifest.yml') {
return new Yaml().load(('tests/jenkins/data/opensearch-dist-2.16.0.yml' as File).text)
} else if (args.file == 'opensearch-dashboards-2.16.0/manifest.yml') {
return new Yaml().load(('tests/jenkins/data/opensearch-dashboards-dist-2.16.0.yml' as File).text)
}
})
helper.addShMock("git ls-remote --tags https://github.com/opensearch-project/security.git 2.16.0.0 | awk 'NR==1{print \$1}'") { script ->
return [stdout: '30760168263404e628a25fd13a54100d2610810c', exitValue: 0]
}
helper.addShMock("git ls-remote --tags https://github.com/opensearch-project/job-scheduler.git 2.16.0.0 | awk 'NR==1{print \$1}'") { script ->
return [stdout: 'b36f79336db82fd45db5665a5ac2e9368f0a1cdf', exitValue: 0]
}
helper.addShMock("git ls-remote --tags https://github.com/opensearch-project/k-NN.git 2.16.0.0 | awk 'NR==1{print \$1}'") { script ->
return [stdout: 'c8ec49f1e2c9603498ca679727a499dc0b296e26', exitValue: 0]
}
helper.addShMock("git ls-remote --tags https://github.com/opensearch-project/common-utils.git 2.16.0.0 | awk 'NR==1{print \$1}'") { script ->
return [stdout: 'cbc06a5eafe0009edbb2c865d7cd30262d04e502', exitValue: 0]
}
helper.addShMock("git ls-remote --tags https://github.com/opensearch-project/OpenSearch.git 2.16.0 | awk 'NR==1{print \$1}'") { script ->
return [stdout: 'f84a26e76807ea67a69822c37b1a1d89e7177d9b', exitValue: 0]
}
helper.addShMock("git ls-remote --tags https://github.com/opensearch-project/dashboards-visualizations.git 2.16.0.0 | awk 'NR==1{print \$1}'") { script ->
return [stdout: '5e86965658791648fad9d0fc573e470c59cce674', exitValue: 0]
}
helper.addShMock("git ls-remote --tags https://github.com/opensearch-project/OpenSearch-Dashboards.git 2.16.0 | awk 'NR==1{print \$1}'") { script ->
return [stdout: '4b8826e7ffa6562825ca8aad676a8d89983c2d70', exitValue: 0]
}
helper.addShMock("git ls-remote --tags https://github.com/opensearch-project/opensearch-dashboards-functional-test.git 2.16.0 | awk 'NR==1{print \$1}'") { script ->
return [stdout: '7c5e0482b844828cf2aec3b63841bd5d336d5668', exitValue: 0]
}
helper.addShMock("git ls-remote --tags https://github.com/opensearch-project/dashboards-reporting.git 2.16.0.0 | awk 'NR==1{print \$1}'") { script ->
return [stdout: '49057e4f82b0390dc28d0e08009ec5f892d7af1a', exitValue: 0]
}
helper.addShMock("git ls-remote --tags https://github.com/opensearch-project/dashboards-observability.git 2.16.0.0 | awk 'NR==1{print \$1}'") { script ->
return [stdout: '24d368e882ec01ff98e556725b84e332d4ab825e', exitValue: 0]
}
}
@Test
public void checkTagCreation() {
super.testPipeline("jenkins/release-workflows/release-tag.jenkinsfile",
"tests/jenkins/jenkinsjob-regression-files/release-workflows/release-tag.jenkinsfile")
assertJobStatusSuccess()
}

@Test
public void testManifestLock(){
runScript('jenkins/release-workflows/release-tag.jenkinsfile')
assertCallStack().contains('release-tag.stage(Lock Manifests to tags, groovy.lang.Closure',
'release-tag.string({name=RELEASE_VERSION, value=2.16.0})',
'release-tag.string({name=MANIFEST_LOCK_ACTION, value=UPDATE_TO_TAGS})',
'release-tag.build({job=release-manifest-commit-lock, wait=true, parameters=[null, null]})')
}
}
35 changes: 35 additions & 0 deletions tests/jenkins/data/opensearch-dashboards-dist-2.16.0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
schema-version: '1.1'
build:
name: OpenSearch Dashboards
version: 2.16.0
platform: linux
architecture: x64
distribution: tar
location: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/2.16.0/7858/linux/x64/tar/dist/opensearch-dashboards/opensearch-dashboards-2.16.0-linux-x64.tar.gz
id: '7858'
components:
- name: OpenSearch-Dashboards
repository: https://github.com/opensearch-project/OpenSearch-Dashboards.git
ref: 4b8826e7ffa6562825ca8aad676a8d89983c2d70
commit_id: 4b8826e7ffa6562825ca8aad676a8d89983c2d70
location: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/2.16.0/7858/linux/x64/tar/builds/opensearch-dashboards/dist/opensearch-dashboards-min-2.16.0-linux-x64.tar.gz
- name: functionalTestDashboards
repository: https://github.com/opensearch-project/opensearch-dashboards-functional-test.git
ref: '2.16'
commit_id: 7c5e0482b844828cf2aec3b63841bd5d336d5668
- name: observabilityDashboards
repository: https://github.com/opensearch-project/dashboards-observability.git
ref: 24d368e882ec01ff98e556725b84e332d4ab825e
commit_id: 24d368e882ec01ff98e556725b84e332d4ab825e
location: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/2.16.0/7858/linux/x64/tar/builds/opensearch-dashboards/plugins/observabilityDashboards-2.16.0.zip
- name: reportsDashboards
repository: https://github.com/opensearch-project/dashboards-reporting.git
ref: 49057e4f82b0390dc28d0e08009ec5f892d7af1a
commit_id: 49057e4f82b0390dc28d0e08009ec5f892d7af1a
location: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/2.16.0/7858/linux/x64/tar/builds/opensearch-dashboards/plugins/reportsDashboards-2.16.0.zip
- name: ganttChartDashboards
repository: https://github.com/opensearch-project/dashboards-visualizations.git
ref: 5e86965658791648fad9d0fc573e470c59cce674
commit_id: 5e86965658791648fad9d0fc573e470c59cce674
location: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/2.16.0/7858/linux/x64/tar/builds/opensearch-dashboards/plugins/ganttChartDashboards-2.16.0.zip
35 changes: 35 additions & 0 deletions tests/jenkins/data/opensearch-dist-2.16.0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
schema-version: '1.1'
build:
name: OpenSearch
version: 2.16.0
platform: linux
architecture: x64
distribution: tar
location: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.16.0/10154/linux/x64/tar/dist/opensearch/opensearch-2.16.0-linux-x64.tar.gz
id: '10154'
components:
- name: OpenSearch
repository: https://github.com/opensearch-project/OpenSearch.git
ref: f84a26e76807ea67a69822c37b1a1d89e7177d9b
commit_id: f84a26e76807ea67a69822c37b1a1d89e7177d9b
location: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.16.0/10154/linux/x64/tar/builds/opensearch/dist/opensearch-min-2.16.0-linux-x64.tar.gz
- name: common-utils
repository: https://github.com/opensearch-project/common-utils.git
ref: cbc06a5eafe0009edbb2c865d7cd30262d04e502
commit_id: cbc06a5eafe0009edbb2c865d7cd30262d04e502
- name: job-scheduler
repository: https://github.com/opensearch-project/job-scheduler.git
ref: b36f79336db82fd45db5665a5ac2e9368f0a1cdf
commit_id: b36f79336db82fd45db5665a5ac2e9368f0a1cdf
location: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.16.0/10154/linux/x64/tar/builds/opensearch/plugins/opensearch-job-scheduler-2.16.0.0.zip
- name: security
repository: https://github.com/opensearch-project/security.git
ref: 30760168263404e628a25fd13a54100d2610810c
commit_id: 30760168263404e628a25fd13a54100d2610810c
location: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.16.0/10154/linux/x64/tar/builds/opensearch/plugins/opensearch-security-2.16.0.0.zip
- name: k-NN
repository: https://github.com/opensearch-project/k-NN.git
ref: c8ec49f1e2c9603498ca679727a499dc0b296e26
commit_id: c8ec49f1e2c9603498ca679727a499dc0b296e26
location: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.16.0/10154/linux/x64/tar/builds/opensearch/plugins/opensearch-knn-2.16.0.0.zip
Loading
Loading