diff --git a/build.gradle b/build.gradle index 4fcdc413..dca8e5be 100644 --- a/build.gradle +++ b/build.gradle @@ -127,7 +127,7 @@ jacocoTestReport { } } -String version = '6.8.4' +String version = '6.9.0' task updateVersion { doLast { diff --git a/tests/jenkins/TestPublishToNpm.groovy b/tests/jenkins/TestPublishToNpm.groovy index e7d1c1b2..8a9e35aa 100644 --- a/tests/jenkins/TestPublishToNpm.groovy +++ b/tests/jenkins/TestPublishToNpm.groovy @@ -29,7 +29,7 @@ class TestPublishToNpm extends BuildPipelineTest { this.registerLibTester(new PublishToNpmLibTester('artifact', '/tmp/workspace/example.tgz')) super.testPipeline('tests/jenkins/jobs/PublishToNpmUsingTarball_JenkinsFile') assertThat(getShellCommands('npm'), hasItem( - '\n npm set registry \"https://registry.npmjs.org\"\n npm set //registry.npmjs.org/:_authToken NPM_TOKEN\n npm publish /tmp/workspace/example.tgz --dry-run && npm publish /tmp/workspace/example.tgz --access public\n ' + '\n npm set registry \"https://registry.npmjs.org\"\n npm set //registry.npmjs.org/:_authToken NPM_TOKEN\n npm publish /tmp/workspace/example.tgz --dry-run && npm publish /tmp/workspace/example.tgz --access public --tag beta\n ' )) assertThat(getShellCommands('nvmrc'), hasItem('rm -rf /tmp/workspace/.nvmrc && rm -rf ~/.nvmrc')) } @@ -39,7 +39,7 @@ class TestPublishToNpm extends BuildPipelineTest { this.registerLibTester(new PublishToNpmLibTester('github')) super.testPipeline('tests/jenkins/jobs/PublishToNpm_Jenkinsfile') assertThat(getShellCommands('npm'), hasItem( - '\n npm set registry \"https://registry.npmjs.org\"\n npm set //registry.npmjs.org/:_authToken NPM_TOKEN\n npm publish --dry-run && npm publish --access public\n ' + '\n npm set registry \"https://registry.npmjs.org\"\n npm set //registry.npmjs.org/:_authToken NPM_TOKEN\n npm publish --dry-run && npm publish --access public --tag latest\n ' )) assertThat(getShellCommands('nvmrc'), hasItem('rm -rf /tmp/workspace/.nvmrc && rm -rf ~/.nvmrc')) } diff --git a/tests/jenkins/jobs/PublishToNpmUsingTarball_JenkinsFile b/tests/jenkins/jobs/PublishToNpmUsingTarball_JenkinsFile index 90ff2ccf..f79e2017 100644 --- a/tests/jenkins/jobs/PublishToNpmUsingTarball_JenkinsFile +++ b/tests/jenkins/jobs/PublishToNpmUsingTarball_JenkinsFile @@ -9,7 +9,7 @@ pipeline { environment { - tag = '2.0.0' + tag = '2.0.0-beta.1' repository = 'https://github.com/opensearch-project/opensearch-ci' } agent none diff --git a/tests/jenkins/jobs/PublishToNpmUsingTarball_JenkinsFile.txt b/tests/jenkins/jobs/PublishToNpmUsingTarball_JenkinsFile.txt index f9d5ffda..910efbb9 100644 --- a/tests/jenkins/jobs/PublishToNpmUsingTarball_JenkinsFile.txt +++ b/tests/jenkins/jobs/PublishToNpmUsingTarball_JenkinsFile.txt @@ -9,6 +9,6 @@ publishToNpm.sh( npm set registry "https://registry.npmjs.org" npm set //registry.npmjs.org/:_authToken NPM_TOKEN - npm publish /tmp/workspace/example.tgz --dry-run && npm publish /tmp/workspace/example.tgz --access public + npm publish /tmp/workspace/example.tgz --dry-run && npm publish /tmp/workspace/example.tgz --access public --tag beta ) publishToNpm.sh(rm -rf /tmp/workspace/.nvmrc && rm -rf ~/.nvmrc) diff --git a/tests/jenkins/jobs/PublishToNpm_Jenkinsfile b/tests/jenkins/jobs/PublishToNpm_Jenkinsfile index 86942e1f..18e4e055 100644 --- a/tests/jenkins/jobs/PublishToNpm_Jenkinsfile +++ b/tests/jenkins/jobs/PublishToNpm_Jenkinsfile @@ -18,7 +18,7 @@ pipeline { steps { script { publishToNpm( - publicationType: 'github' + publicationType: 'github', ) } } diff --git a/tests/jenkins/jobs/PublishToNpm_Jenkinsfile.txt b/tests/jenkins/jobs/PublishToNpm_Jenkinsfile.txt index b06d475f..0bd58fe5 100644 --- a/tests/jenkins/jobs/PublishToNpm_Jenkinsfile.txt +++ b/tests/jenkins/jobs/PublishToNpm_Jenkinsfile.txt @@ -10,6 +10,6 @@ publishToNpm.sh( npm set registry "https://registry.npmjs.org" npm set //registry.npmjs.org/:_authToken NPM_TOKEN - npm publish --dry-run && npm publish --access public + npm publish --dry-run && npm publish --access public --tag latest ) publishToNpm.sh(rm -rf /tmp/workspace/.nvmrc && rm -rf ~/.nvmrc) diff --git a/vars/publishToNpm.groovy b/vars/publishToNpm.groovy index 0bad12cd..5f54697d 100644 --- a/vars/publishToNpm.groovy +++ b/vars/publishToNpm.groovy @@ -18,12 +18,13 @@ void call(Map args = [:]) { if (args.publicationType == 'github') { checkout([$class: 'GitSCM', branches: [[name: "${env.tag}" ]], userRemoteConfigs: [[url: "${env.repository}" ]]]) } + def npmTag = getNpmTag("${env.tag}") withCredentials([string(credentialsId: 'jenkins-opensearch-publish-to-npm-token', variable: 'NPM_TOKEN')]) { sh """ npm set registry "https://registry.npmjs.org" npm set //registry.npmjs.org/:_authToken ${NPM_TOKEN} - npm publish ${artifactPath} --dry-run && npm publish ${artifactPath} --access public + npm publish ${artifactPath} --dry-run && npm publish ${artifactPath} --access public --tag ${npmTag} """ } println('Cleaning up') @@ -45,3 +46,10 @@ void parameterCheck(String publicationType, String artifactPath) { error('publicationType: github does take any argument with it.') } } + +String getNpmTag(String githubTag) { + def matcher = githubTag =~ /-(\w+)\./ + def npmTag = matcher ? matcher[0][1] : 'latest' + println("Tagging the release as '${npmTag}'") + return npmTag +} \ No newline at end of file