From c66bc1c3060b8154f86b0fdf335fec8049421b42 Mon Sep 17 00:00:00 2001 From: Sayali Gaikawad <61760125+gaiksaya@users.noreply.github.com> Date: Wed, 1 Feb 2023 18:17:53 -0800 Subject: [PATCH] Support switching ruby gems version and fix regex (#119) Signed-off-by: Sayali Gaikawad --- build.gradle | 2 +- tests/jenkins/TestPublishToRubyGems.groovy | 4 ++-- tests/jenkins/jobs/PublishToRubyGemWithArgs_Jenkinsfile | 2 +- .../jobs/PublishToRubyGemWithArgs_Jenkinsfile.txt | 7 ++++--- tests/jenkins/jobs/PublishToRubyGems_JenkinsFile.txt | 5 +++-- vars/publishToRubyGems.groovy | 9 ++++++--- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 3b77521e8..7b9fa8400 100644 --- a/build.gradle +++ b/build.gradle @@ -120,7 +120,7 @@ jacocoTestReport { } } -String version = '1.5.4' +String version = '1.5.5' task updateVersion { doLast { diff --git a/tests/jenkins/TestPublishToRubyGems.groovy b/tests/jenkins/TestPublishToRubyGems.groovy index 1055879ed..e605c7286 100644 --- a/tests/jenkins/TestPublishToRubyGems.groovy +++ b/tests/jenkins/TestPublishToRubyGems.groovy @@ -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 @@ -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) { diff --git a/tests/jenkins/jobs/PublishToRubyGemWithArgs_Jenkinsfile b/tests/jenkins/jobs/PublishToRubyGemWithArgs_Jenkinsfile index 8748ade44..ac3c55403 100644 --- a/tests/jenkins/jobs/PublishToRubyGemWithArgs_Jenkinsfile +++ b/tests/jenkins/jobs/PublishToRubyGemWithArgs_Jenkinsfile @@ -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') } } } diff --git a/tests/jenkins/jobs/PublishToRubyGemWithArgs_Jenkinsfile.txt b/tests/jenkins/jobs/PublishToRubyGemWithArgs_Jenkinsfile.txt index 8fb8cd3ac..ec27f1dd2 100644 --- a/tests/jenkins/jobs/PublishToRubyGemWithArgs_Jenkinsfile.txt +++ b/tests/jenkins/jobs/PublishToRubyGemWithArgs_Jenkinsfile.txt @@ -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 ) diff --git a/tests/jenkins/jobs/PublishToRubyGems_JenkinsFile.txt b/tests/jenkins/jobs/PublishToRubyGems_JenkinsFile.txt index b0df09929..ddef58a03 100644 --- a/tests/jenkins/jobs/PublishToRubyGems_JenkinsFile.txt +++ b/tests/jenkins/jobs/PublishToRubyGems_JenkinsFile.txt @@ -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 ) diff --git a/vars/publishToRubyGems.groovy b/vars/publishToRubyGems.groovy index d9cdee620..f6c1ee27d 100644 --- a/vars/publishToRubyGems.groovy +++ b/vars/publishToRubyGems.groovy @@ -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 - Credential id consisting api key for publishing the gem to rubyGems.org @param args.gemsDir - The directory containing the gem to be published. Defaults to 'dist' @params args.publicCertPath - The relative path to public key. Defaults to 'certs/opensearch-rubygems.pem' +@params args.rubyVersion - 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 """