Skip to content

Commit

Permalink
Support switching ruby gems version and fix regex (#119)
Browse files Browse the repository at this point in the history
Signed-off-by: Sayali Gaikawad <[email protected]>
  • Loading branch information
gaiksaya authored Feb 2, 2023
1 parent 4df61b2 commit c66bc1c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jacocoTestReport {
}
}

String version = '1.5.4'
String version = '1.5.5'

task updateVersion {
doLast {
Expand Down
4 changes: 2 additions & 2 deletions tests/jenkins/TestPublishToRubyGems.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TestPublishToRubyGems extends BuildPipelineTest {
assertThat(curlCommands, hasItem(
"cd /tmp/workspace/dist && curl --fail --data-binary @`ls *.gem` -H 'Authorization:API_KEY' -H 'Content-Type: application/octet-stream' https://rubygems.org/api/v1/gems".toString()
))
assertThat(gemCommands, hasItem("\n gem cert --add /tmp/workspace/certs/opensearch-rubygems.pem\n cd /tmp/workspace/dist && gemNameWithVersion=\$(ls *.gem)\n gem install \$gemNameWithVersion\n gemName=\$(echo \$gemNameWithVersion | sed -E 's/(-[0-9.]+.gem\$)//g')\n gem uninstall \$gemName\n gem install \$gemNameWithVersion -P HighSecurity\n "))
assertThat(gemCommands, hasItem("#!/bin/bash\n gem cert --add /tmp/workspace/certs/opensearch-rubygems.pem\n source /usr/share/opensearch/.rvm/scripts/rvm && rvm use 2.6.0 && ruby --version\n cd /tmp/workspace/dist && gemNameWithVersion=\$(ls *.gem)\n gem install \$gemNameWithVersion\n gemName=\$(echo \$gemNameWithVersion | sed -E 's/(-[0-9.]+-*[a-z]*.gem\$)//g')\n gem uninstall \$gemName\n gem install \$gemNameWithVersion -P HighSecurity\n "))
}

@Test
Expand All @@ -40,7 +40,7 @@ class TestPublishToRubyGems extends BuildPipelineTest {
def gemCommands = getCommands('sh', 'gem')
assertThat(curlCommands, hasItem(
"cd /tmp/workspace/test && curl --fail --data-binary @`ls *.gem` -H 'Authorization:API_KEY' -H 'Content-Type: application/octet-stream' https://rubygems.org/api/v1/gems".toString()))
assertThat(gemCommands, hasItem("\n gem cert --add /tmp/workspace/certificate/path\n cd /tmp/workspace/test && gemNameWithVersion=\$(ls *.gem)\n gem install \$gemNameWithVersion\n gemName=\$(echo \$gemNameWithVersion | sed -E 's/(-[0-9.]+.gem\$)//g')\n gem uninstall \$gemName\n gem install \$gemNameWithVersion -P HighSecurity\n "))
assertThat(gemCommands, hasItem("#!/bin/bash\n gem cert --add /tmp/workspace/certificate/path\n source /usr/share/opensearch/.rvm/scripts/rvm && rvm use jruby-9.3.0.0 && ruby --version\n cd /tmp/workspace/test && gemNameWithVersion=\$(ls *.gem)\n gem install \$gemNameWithVersion\n gemName=\$(echo \$gemNameWithVersion | sed -E 's/(-[0-9.]+-*[a-z]*.gem\$)//g')\n gem uninstall \$gemName\n gem install \$gemNameWithVersion -P HighSecurity\n "))
}

def getCommands(method, text) {
Expand Down
2 changes: 1 addition & 1 deletion tests/jenkins/jobs/PublishToRubyGemWithArgs_Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pipeline {
stage('publishRubyGems'){
steps {
script {
publishToRubyGems(apiKeyCredentialId: 'ruby-api-key', gemsDir: 'test', publicCertPath: 'certificate/path')
publishToRubyGems(apiKeyCredentialId: 'ruby-api-key', gemsDir: 'test', publicCertPath: 'certificate/path', rubyVersion: 'jruby-9.3.0.0')
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions tests/jenkins/jobs/PublishToRubyGemWithArgs_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
PublishToRubyGemWithArgs_Jenkinsfile.echo(Executing on agent [label:none])
PublishToRubyGemWithArgs_Jenkinsfile.stage(publishRubyGems, groovy.lang.Closure)
PublishToRubyGemWithArgs_Jenkinsfile.script(groovy.lang.Closure)
PublishToRubyGemWithArgs_Jenkinsfile.publishToRubyGems({apiKeyCredentialId=ruby-api-key, gemsDir=test, publicCertPath=certificate/path})
publishToRubyGems.sh(
PublishToRubyGemWithArgs_Jenkinsfile.publishToRubyGems({apiKeyCredentialId=ruby-api-key, gemsDir=test, publicCertPath=certificate/path, rubyVersion=jruby-9.3.0.0})
publishToRubyGems.sh(#!/bin/bash
gem cert --add /tmp/workspace/certificate/path
source /usr/share/opensearch/.rvm/scripts/rvm && rvm use jruby-9.3.0.0 && ruby --version
cd /tmp/workspace/test && gemNameWithVersion=$(ls *.gem)
gem install $gemNameWithVersion
gemName=$(echo $gemNameWithVersion | sed -E 's/(-[0-9.]+.gem$)//g')
gemName=$(echo $gemNameWithVersion | sed -E 's/(-[0-9.]+-*[a-z]*.gem$)//g')
gem uninstall $gemName
gem install $gemNameWithVersion -P HighSecurity
)
Expand Down
5 changes: 3 additions & 2 deletions tests/jenkins/jobs/PublishToRubyGems_JenkinsFile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
PublishToRubyGems_JenkinsFile.stage(publishRubyGems, groovy.lang.Closure)
PublishToRubyGems_JenkinsFile.script(groovy.lang.Closure)
PublishToRubyGems_JenkinsFile.publishToRubyGems({apiKeyCredentialId=ruby-api-key})
publishToRubyGems.sh(
publishToRubyGems.sh(#!/bin/bash
gem cert --add /tmp/workspace/certs/opensearch-rubygems.pem
source /usr/share/opensearch/.rvm/scripts/rvm && rvm use 2.6.0 && ruby --version
cd /tmp/workspace/dist && gemNameWithVersion=$(ls *.gem)
gem install $gemNameWithVersion
gemName=$(echo $gemNameWithVersion | sed -E 's/(-[0-9.]+.gem$)//g')
gemName=$(echo $gemNameWithVersion | sed -E 's/(-[0-9.]+-*[a-z]*.gem$)//g')
gem uninstall $gemName
gem install $gemNameWithVersion -P HighSecurity
)
Expand Down
9 changes: 6 additions & 3 deletions vars/publishToRubyGems.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@
*/

/** Library to publish ruby gems to rubygems.org registry with OpenSearch as the owner.
Note: Please make sure the gem is already signed.
Note: Please make sure the gem is already signed. For ruby versions, they to be preinstalled as a part of docker. See the default docker file: https://github.com/opensearch-project/opensearch-build/blob/main/docker/ci/dockerfiles/current/release.centos.clients.x64.arm64.dockerfile
@param Map args = [:] args A map of the following parameters
@param args.apiKeyCredentialId <required> - Credential id consisting api key for publishing the gem to rubyGems.org
@param args.gemsDir <optional> - The directory containing the gem to be published. Defaults to 'dist'
@params args.publicCertPath <optional> - The relative path to public key. Defaults to 'certs/opensearch-rubygems.pem'
@params args.rubyVersion <optional> - Ruby version to be used. Defaults to 2.6.0
*/


void call(Map args = [:]) {
String releaseArtifactsDir = args.gemsDir ? "${WORKSPACE}/${args.gemsDir}" : "${WORKSPACE}/dist"
String certPath = args.publicCertPath ? "${WORKSPACE}/${args.publicCertPath}" : "${WORKSPACE}/certs/opensearch-rubygems.pem"
String rubyVersion = args.rubyVersion ?: '2.6.0'

sh """
sh """#!/bin/bash
gem cert --add ${certPath}
source /usr/share/opensearch/.rvm/scripts/rvm && rvm use ${rubyVersion} && ruby --version
cd ${releaseArtifactsDir} && gemNameWithVersion=\$(ls *.gem)
gem install \$gemNameWithVersion
gemName=\$(echo \$gemNameWithVersion | sed -E 's/(-[0-9.]+.gem\$)//g')
gemName=\$(echo \$gemNameWithVersion | sed -E 's/(-[0-9.]+-*[a-z]*.gem\$)//g')
gem uninstall \$gemName
gem install \$gemNameWithVersion -P HighSecurity
"""
Expand Down

0 comments on commit c66bc1c

Please sign in to comment.