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

[Backport 6.x] Add tagging feature to npm publishing #494

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jacocoTestReport {
}
}

String version = '6.8.4'
String version = '6.9.0'

task updateVersion {
doLast {
Expand Down
4 changes: 2 additions & 2 deletions tests/jenkins/TestPublishToNpm.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
}
Expand All @@ -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'))
}
Expand Down
2 changes: 1 addition & 1 deletion tests/jenkins/jobs/PublishToNpmUsingTarball_JenkinsFile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion tests/jenkins/jobs/PublishToNpm_Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pipeline {
steps {
script {
publishToNpm(
publicationType: 'github'
publicationType: 'github',
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/jenkins/jobs/PublishToNpm_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 9 additions & 1 deletion vars/publishToNpm.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
}
Loading