Skip to content

Commit

Permalink
Add overwrite support (#115)
Browse files Browse the repository at this point in the history
Signed-off-by: Sayali Gaikawad <[email protected]>
  • Loading branch information
gaiksaya authored Feb 1, 2023
1 parent 02df1d4 commit 4df61b2
Show file tree
Hide file tree
Showing 20 changed files with 119 additions and 39 deletions.
4 changes: 2 additions & 2 deletions tests/jenkins/TestPublishToMaven.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TestPublishToMaven extends BuildPipelineTest {
def release_sh = getCommands('sh', 'stage-maven-release.sh')

assertThat(signing, hasItem('{artifactPath=/path/to/signing, type=maven, platform=linux, sigtype=.asc}'))
assertThat(signing_sh, hasItem('\n #!/bin/bash\n set +x\n export ROLE=SIGNER_CLIENT_ROLE\n export EXTERNAL_ID=SIGNER_CLIENT_EXTERNAL_ID\n export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET\n export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET\n\n workspace/sign.sh /path/to/signing --type=maven --platform=linux --sigtype=.asc\n '))
assertThat(signing_sh, hasItem('\n #!/bin/bash\n set +x\n export ROLE=SIGNER_CLIENT_ROLE\n export EXTERNAL_ID=SIGNER_CLIENT_EXTERNAL_ID\n export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET\n export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET\n\n workspace/sign.sh /path/to/signing --type maven --platform linux --sigtype .asc\n '))
assertThat(release_sh, hasItem('./stage-maven-release.sh /path/to/maven/artifacts true'))
assertThat(release_sh, hasItem('chmod a+x ./stage-maven-release.sh'))

Expand All @@ -45,7 +45,7 @@ class TestPublishToMaven extends BuildPipelineTest {
def release_sh = getCommands('sh', 'stage-maven-release.sh')

assertThat(signing, hasItem('{artifactPath=/path/to/signing/manifest.yml, type=maven, platform=linux, sigtype=.asc}'))
assertThat(signing_sh, hasItem('\n #!/bin/bash\n set +x\n export ROLE=SIGNER_CLIENT_ROLE\n export EXTERNAL_ID=SIGNER_CLIENT_EXTERNAL_ID\n export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET\n export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET\n\n workspace/sign.sh /path/to/signing/manifest.yml --type=maven --platform=linux --sigtype=.asc\n '))
assertThat(signing_sh, hasItem('\n #!/bin/bash\n set +x\n export ROLE=SIGNER_CLIENT_ROLE\n export EXTERNAL_ID=SIGNER_CLIENT_EXTERNAL_ID\n export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET\n export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET\n\n workspace/sign.sh /path/to/signing/manifest.yml --type maven --platform linux --sigtype .asc\n '))
assertThat(release_sh, hasItem('./stage-maven-release.sh /path/to/maven/artifacts false'))
assertThat(release_sh, hasItem('chmod a+x ./stage-maven-release.sh'))
}
Expand Down
4 changes: 2 additions & 2 deletions tests/jenkins/TestPublishToPyPi.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TestPublishToPyPi extends BuildPipelineTest {
def signing = getCommands('signArtifacts', '')
def signing_sh = getCommands('sh', 'sign.sh')
assertThat(signing, hasItem('{artifactPath=/tmp/workspace/dist, sigtype=.asc, platform=linux}'))
assertThat(signing_sh, hasItem('\n #!/bin/bash\n set +x\n export ROLE=SIGNER_CLIENT_ROLE\n export EXTERNAL_ID=SIGNER_CLIENT_EXTERNAL_ID\n export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET\n export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET\n\n /tmp/workspace/sign.sh /tmp/workspace/dist --sigtype=.asc --platform=linux\n '))
assertThat(signing_sh, hasItem('\n #!/bin/bash\n set +x\n export ROLE=SIGNER_CLIENT_ROLE\n export EXTERNAL_ID=SIGNER_CLIENT_EXTERNAL_ID\n export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET\n export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET\n\n /tmp/workspace/sign.sh /tmp/workspace/dist --sigtype .asc --platform linux\n '))
}

@Test
Expand All @@ -48,7 +48,7 @@ class TestPublishToPyPi extends BuildPipelineTest {
assertThat(signing, hasItem('{artifactPath=/tmp/workspace/test, sigtype=.asc, platform=linux}'))

def signing_sh = getCommands('sh', 'sign.sh')
assertThat(signing_sh, hasItem('\n #!/bin/bash\n set +x\n export ROLE=SIGNER_CLIENT_ROLE\n export EXTERNAL_ID=SIGNER_CLIENT_EXTERNAL_ID\n export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET\n export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET\n\n /tmp/workspace/sign.sh /tmp/workspace/test --sigtype=.asc --platform=linux\n '))
assertThat(signing_sh, hasItem('\n #!/bin/bash\n set +x\n export ROLE=SIGNER_CLIENT_ROLE\n export EXTERNAL_ID=SIGNER_CLIENT_EXTERNAL_ID\n export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET\n export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET\n\n /tmp/workspace/sign.sh /tmp/workspace/test --sigtype .asc --platform linux\n '))
}

def getCommands(method, text) {
Expand Down
36 changes: 34 additions & 2 deletions tests/jenkins/TestSignArtifacts.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@


import jenkins.tests.BuildPipelineTest
import org.junit.*
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.MatcherAssert.assertThat
import org.junit.Before
import org.junit.Test


class TestSignArtifacts extends BuildPipelineTest {
Expand All @@ -18,13 +22,41 @@ class TestSignArtifacts extends BuildPipelineTest {
void setUp() {

this.registerLibTester(new SignArtifactsLibTester('.sig', 'linux', "${this.workspace}/artifacts", null, null))
this.registerLibTester(new SignArtifactsLibTester('.rpm', 'linux', "${this.workspace}/artifacts", 'null', null))
this.registerLibTester(new SignArtifactsLibTester('.rpm', 'linux', "${this.workspace}/artifacts", 'null', null, false))
this.registerLibTester(new SignArtifactsLibTester(null, 'linux', "${this.workspace}/file.yml", 'maven', null))
this.registerLibTester(new SignArtifactsLibTester(null, 'windows', "${this.workspace}/the_msi.msi", null, null, true))
super.setUp()
}

@Test
void testSignArtifacts() {
super.testPipeline("tests/jenkins/jobs/SignArtifacts_Jenkinsfile")
}

@Test
void 'verify shell commands'() {
runScript('tests/jenkins/jobs/SignArtifacts_Jenkinsfile')

def signCommands = getShellCommands('sign.sh')
assertThat(signCommands, hasItem('\n #!/bin/bash\n set +x\n export ROLE=SIGNER_CLIENT_ROLE\n export EXTERNAL_ID=SIGNER_CLIENT_EXTERNAL_ID\n export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET\n export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET\n\n /tmp/workspace/sign.sh /tmp/workspace/artifacts --sigtype .sig --platform linux\n '))
}

@Test
void 'verify_overwrite'(){
runScript('tests/jenkins/jobs/SignArtifacts_Jenkinsfile')

def signCommands = getShellCommands('sign.sh')
assertThat(signCommands, hasItem('\n #!/bin/bash\n set +x\n export ROLE=SIGNER_WINDOWS_ROLE\n export EXTERNAL_ID=SIGNER_WINDOWS_EXTERNAL_ID\n export UNSIGNED_BUCKET=SIGNER_WINDOWS_UNSIGNED_BUCKET\n export SIGNED_BUCKET=SIGNER_WINDOWS_SIGNED_BUCKET\n export PROFILE_IDENTIFIER=SIGNER_WINDOWS_PROFILE_IDENTIFIER\n export PLATFORM_IDENTIFIER=SIGNER_WINDOWS_PLATFORM_IDENTIFIER\n\n /tmp/workspace/sign.sh /tmp/workspace/the_msi.msi --platform windows --overwrite \n '))
}

def getShellCommands(matchstring) {
def shCommands = helper.callStack.findAll { call ->
call.methodName == 'sh'
}.collect { call ->
callArgsToString(call)
}.findAll { command ->
command.contains(matchstring)
}
return shCommands
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET
export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET

tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype=.sig
tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype .sig
)
promoteArtifacts.withAWS({role=ARTIFACT_PROMOTION_ROLE_NAME, roleAccount=AWS_ACCOUNT_ARTIFACT, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
promoteArtifacts.s3Upload({bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=releases/core/opensearch/2.0.0-rc1/, workingDir=tests/jenkins/artifacts/tar/vars-build/2.0.0-rc1/33/linux/x64/tar/builds/opensearch/dist/, includePathPattern=**/opensearch-min-2.0.0-rc1-linux-x64*})
Expand Down Expand Up @@ -89,7 +89,7 @@
export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET
export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET

tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype=.sig
tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype .sig
)
promoteArtifacts.withAWS({role=ARTIFACT_PROMOTION_ROLE_NAME, roleAccount=AWS_ACCOUNT_ARTIFACT, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
promoteArtifacts.s3Upload({bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=releases/bundle/opensearch/2.0.0-rc1/, workingDir=tests/jenkins/artifacts/rpm/vars-build/2.0.0-rc1/33/linux/x64/rpm/dist/opensearch/, includePathPattern=**/opensearch-2.0.0-rc1-linux-x64*})
Expand Down Expand Up @@ -126,7 +126,7 @@
export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET
export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET

tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype=.sig
tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype .sig
)
promoteArtifacts.withAWS({role=ARTIFACT_PROMOTION_ROLE_NAME, roleAccount=AWS_ACCOUNT_ARTIFACT, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
promoteArtifacts.s3Upload({bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=releases/bundle/opensearch/2.0.0-rc1/, workingDir=tests/jenkins/artifacts/deb/vars-build/2.0.0-rc1/33/linux/x64/deb/dist/opensearch/, includePathPattern=**/opensearch-2.0.0-rc1-linux-x64*})
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET
export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET

tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype=.sig
tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype .sig
)
promoteArtifacts.withAWS({role=ARTIFACT_PROMOTION_ROLE_NAME, roleAccount=AWS_ACCOUNT_ARTIFACT, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
promoteArtifacts.s3Upload({bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=releases/bundle/opensearch/2.0.0-rc1/, workingDir=tests/jenkins/artifacts/zip/vars-build/2.0.0-rc1/33/windows/x64/zip/dist/opensearch/, includePathPattern=**/opensearch-2.0.0-rc1-windows-x64*})
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET
export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET

tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype=.sig
tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype .sig
)
promoteArtifacts.withAWS({role=ARTIFACT_PROMOTION_ROLE_NAME, roleAccount=AWS_ACCOUNT_ARTIFACT, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
promoteArtifacts.s3Upload({bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=releases/core/opensearch-dashboards/2.0.0-rc1/, workingDir=tests/jenkins/artifacts/tar/vars-build/2.0.0-rc1/33/linux/x64/tar/builds/opensearch-dashboards/dist/, includePathPattern=**/opensearch-dashboards-min-2.0.0-rc1-linux-x64*})
Expand Down Expand Up @@ -89,7 +89,7 @@
export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET
export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET

tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype=.sig
tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype .sig
)
promoteArtifacts.withAWS({role=ARTIFACT_PROMOTION_ROLE_NAME, roleAccount=AWS_ACCOUNT_ARTIFACT, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
promoteArtifacts.s3Upload({bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=releases/bundle/opensearch-dashboards/2.0.0-rc1/, workingDir=tests/jenkins/artifacts/rpm/vars-build/2.0.0-rc1/33/linux/x64/rpm/dist/opensearch-dashboards/, includePathPattern=**/opensearch-dashboards-2.0.0-rc1-linux-x64*})
Expand Down Expand Up @@ -126,7 +126,7 @@
export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET
export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET

tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype=.sig
tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype .sig
)
promoteArtifacts.withAWS({role=ARTIFACT_PROMOTION_ROLE_NAME, roleAccount=AWS_ACCOUNT_ARTIFACT, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
promoteArtifacts.s3Upload({bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=releases/bundle/opensearch-dashboards/2.0.0-rc1/, workingDir=tests/jenkins/artifacts/deb/vars-build/2.0.0-rc1/33/linux/x64/deb/dist/opensearch-dashboards/, includePathPattern=**/opensearch-dashboards-2.0.0-rc1-linux-x64*})
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET
export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET

tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype=.sig
tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype .sig
)
promoteArtifacts.withAWS({role=ARTIFACT_PROMOTION_ROLE_NAME, roleAccount=AWS_ACCOUNT_ARTIFACT, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
promoteArtifacts.s3Upload({bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=releases/bundle/opensearch-dashboards/2.0.0-rc1/, workingDir=tests/jenkins/artifacts/zip/vars-build/2.0.0-rc1/33/windows/x64/zip/dist/opensearch-dashboards/, includePathPattern=**/opensearch-dashboards-2.0.0-rc1-windows-x64*})
8 changes: 4 additions & 4 deletions tests/jenkins/jobs/PromoteArtifacts_actions_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET
export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET

tests/jenkins/sign.sh tests/jenkins/artifacts/tar/vars-build/1.3.0/33/linux/x64/tar/builds/opensearch/core-plugins --sigtype=.sig
tests/jenkins/sign.sh tests/jenkins/artifacts/tar/vars-build/1.3.0/33/linux/x64/tar/builds/opensearch/core-plugins --sigtype .sig
)
promoteArtifacts.println(Signing Core/Bundle Artifacts)
promoteArtifacts.findFiles({glob=**/opensearch-min-1.3.0*.tar*,**/opensearch-1.3.0*.tar*})
Expand Down Expand Up @@ -83,7 +83,7 @@
export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET
export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET

tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype=.sig
tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype .sig
)
promoteArtifacts.withAWS({role=ARTIFACT_PROMOTION_ROLE_NAME, roleAccount=AWS_ACCOUNT_ARTIFACT, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
promoteArtifacts.s3Upload({bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=releases/plugins/discovery-ec2/1.3.0/, workingDir=tests/jenkins/artifacts/tar/vars-build/1.3.0/33/linux/x64/tar/builds/opensearch/core-plugins/, includePathPattern=**/discovery-ec2*})
Expand Down Expand Up @@ -141,7 +141,7 @@
export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET
export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET

tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype=.sig
tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype .sig
)
promoteArtifacts.withAWS({role=ARTIFACT_PROMOTION_ROLE_NAME, roleAccount=AWS_ACCOUNT_ARTIFACT, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
promoteArtifacts.s3Upload({bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=releases/bundle/opensearch/1.3.0/, workingDir=tests/jenkins/artifacts/rpm/vars-build/1.3.0/33/linux/x64/rpm/dist/opensearch/, includePathPattern=**/opensearch-1.3.0-linux-x64*})
Expand Down Expand Up @@ -178,7 +178,7 @@
export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET
export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET

tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype=.sig
tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype .sig
)
promoteArtifacts.withAWS({role=ARTIFACT_PROMOTION_ROLE_NAME, roleAccount=AWS_ACCOUNT_ARTIFACT, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
promoteArtifacts.s3Upload({bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=releases/bundle/opensearch/1.3.0/, workingDir=tests/jenkins/artifacts/deb/vars-build/1.3.0/33/linux/x64/deb/dist/opensearch/, includePathPattern=**/opensearch-1.3.0-linux-x64*})
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
export UNSIGNED_BUCKET=SIGNER_CLIENT_UNSIGNED_BUCKET
export SIGNED_BUCKET=SIGNER_CLIENT_SIGNED_BUCKET

tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype=.sig
tests/jenkins/sign.sh tests/jenkins/tests/jenkins/file/found.zip --sigtype .sig
)
promoteArtifacts.withAWS({role=ARTIFACT_PROMOTION_ROLE_NAME, roleAccount=AWS_ACCOUNT_ARTIFACT, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
promoteArtifacts.s3Upload({bucket=ARTIFACT_PRODUCTION_BUCKET_NAME, path=releases/bundle/opensearch/1.3.0/, workingDir=tests/jenkins/artifacts/zip/vars-build/1.3.0/33/windows/x64/zip/dist/opensearch/, includePathPattern=**/opensearch-1.3.0-windows-x64*})
Loading

0 comments on commit 4df61b2

Please sign in to comment.