forked from opensearch-project/opensearch-build-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into 1.x
- Loading branch information
Showing
23 changed files
with
602 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
--- | ||
coverage: | ||
precision: 2 | ||
round: down | ||
range: '70...90' | ||
status: | ||
project: | ||
default: | ||
target: 98% | ||
target: auto | ||
threshold: 0.2% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
name: Create a release | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
generate_release_notes: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
- [Overview](#overview) | ||
- [Versioning](#versioning) | ||
- [Releasing](#releasing) | ||
|
||
## Overview | ||
|
||
This document explains the release strategy for artifacts in this organization. | ||
|
||
## Versioning | ||
|
||
This respository, as other in this organization follows semantic versioning. | ||
|
||
- **major**: Breaking changes | ||
- **minor**: New features | ||
- **patch**: Bug fixes | ||
|
||
## Releasing | ||
|
||
The release process includes a [maintainer](MAINTAINERS.md) pushing a tag to this repository which creates a release on GitHub via [release.yml](./.github/workflows/release.yml) workflow. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package jenkins.tests | ||
|
||
import jenkins.tests.BuildPipelineTest | ||
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 TestPublishToNpm extends BuildPipelineTest { | ||
@Override | ||
@Before | ||
void setUp() { | ||
|
||
this.registerLibTester(new PublishToNpmLibTester('https://github.com/opensearch-project/opensearch-ci', '1.0.0')) | ||
super.setUp() | ||
} | ||
|
||
@Test | ||
public void test() { | ||
super.testPipeline("tests/jenkins/jobs/PublishToNpm_Jenkinsfile") | ||
} | ||
|
||
@Test | ||
void 'verify shell commands'(){ | ||
runScript('tests/jenkins/jobs/PublishToNpm_Jenkinsfile') | ||
|
||
def npmCommands = getShellCommands() | ||
assertThat(npmCommands, hasItem( | ||
'npm set registry "https://registry.npmjs.org"; npm set //registry.npmjs.org/:_authToken NPM_TOKEN; npm publish --dry-run && npm publish --access public'.toString() | ||
)) | ||
|
||
} | ||
def getShellCommands() { | ||
def shCommands = helper.callStack.findAll { call -> | ||
call.methodName == 'sh' | ||
}.collect { call -> | ||
callArgsToString(call) | ||
}.findAll { npmCommand -> | ||
npmCommand.contains('npm') | ||
} | ||
return shCommands | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
|
||
import jenkins.tests.BuildPipelineTest | ||
import org.junit.Before | ||
import org.junit.Test | ||
import static org.hamcrest.MatcherAssert.assertThat | ||
import static org.hamcrest.CoreMatchers.equalTo | ||
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString | ||
import static org.hamcrest.CoreMatchers.hasItem | ||
|
||
|
||
|
||
class TestStandardReleasePipeline extends BuildPipelineTest { | ||
|
||
@Before | ||
void setUp() { | ||
super.setUp() | ||
} | ||
|
||
@Test | ||
void testStandardReleasePipeline() { | ||
super.testPipeline('tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile') | ||
} | ||
|
||
@Test | ||
void testStandardReleasePipelineWithArgs() { | ||
super.testPipeline('tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile') | ||
} | ||
|
||
@Test | ||
void 'check override values'() { | ||
runScript("tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile") | ||
def echoCommand = getEchoCommands().findAll{ | ||
command -> command.contains('agent') | ||
} | ||
|
||
assertThat(echoCommand.size(), equalTo(1)) | ||
assertThat(echoCommand, hasItem('Executing on agent [docker:[image:test:image, reuseNode:false, stages:[:], args:, alwaysPull:true, containerPerStageRoot:false, label:AL2-X64]]')) | ||
} | ||
|
||
@Test | ||
void 'check default values'(){ | ||
runScript("tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile") | ||
def echoCommand = getEchoCommands().findAll{ | ||
command -> command.contains('agent') | ||
} | ||
|
||
assertThat(echoCommand.size(), equalTo(1)) | ||
assertThat(echoCommand, hasItem('Executing on agent [docker:[image:opensearchstaging/ci-runner:release-centos7-clients-v1, reuseNode:false, stages:[:], args:, alwaysPull:true, containerPerStageRoot:false, label:Jenkins-Agent-AL2-X64-C54xlarge-Docker-Host]]')) | ||
} | ||
|
||
def getEchoCommands() { | ||
def echoCommands = helper.callStack.findAll { call -> | ||
call.methodName == 'echo' | ||
}.collect { call -> | ||
callArgsToString(call) | ||
} | ||
return echoCommands | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
tests/jenkins/TestStandardReleasePipelineWithGenericTriggers.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
|
||
import jenkins.tests.BuildPipelineTest | ||
import org.junit.Before | ||
import org.junit.Test | ||
import static org.hamcrest.MatcherAssert.assertThat | ||
import static org.hamcrest.CoreMatchers.equalTo | ||
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString | ||
import static org.hamcrest.CoreMatchers.hasItem | ||
|
||
|
||
|
||
class TestStandardReleasePipelineWithGenericTriggers extends BuildPipelineTest { | ||
|
||
@Before | ||
void setUp() { | ||
helper.registerAllowedMethod("GenericTrigger", [Map.class], null) | ||
binding.setVariable('tag', '1.0.0') | ||
binding.setVariable('release_url', 'https://api.github.com/repos/Codertocat/Hello-World/releases/17372790') | ||
super.setUp() | ||
} | ||
|
||
|
||
@Test | ||
void testStandardReleasePipelineWithGenericTriggers() { | ||
super.testPipeline('tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile') | ||
} | ||
|
||
@Test | ||
void testStandardReleasePipelineWithTagTriggers() { | ||
super.testPipeline('tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile') | ||
} | ||
|
||
@Test | ||
void 'validate override values'() { | ||
runScript("tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile") | ||
def echoCommand = getCommands('echo').findAll{ | ||
command -> command.contains('agent') | ||
} | ||
|
||
assertThat(echoCommand.size(), equalTo(1)) | ||
assertThat(echoCommand, hasItem('Executing on agent [docker:[image:centos:7, reuseNode:false, stages:[:], args:, alwaysPull:true, containerPerStageRoot:false, label:AL2-X64]]')) | ||
} | ||
|
||
@Test | ||
void 'validate default triggers'(){ | ||
runScript("tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile") | ||
def cmd = getCommands('GenericTrigger').findAll{ | ||
c -> c.contains('generic') | ||
} | ||
assertThat(cmd.size(), equalTo(1)) | ||
assertThat(cmd, hasItem('{genericVariables=[{key=ref, value=$.release.tag_name}, {key=isDraft, value=$.release.draft}, {key=release_url, value=$.release.url}], tokenCredentialId=opensearch-ci-webhook-trigger-token, causeString=A tag was cut on opensearch-ci repo, printContributedVariables=false, printPostContent=false, regexpFilterText=$isDraft, regexpFilterExpression=true}')) | ||
} | ||
|
||
@Test | ||
void 'validate release is published'(){ | ||
runScript("tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile") | ||
def cmd = getCommands('sh').findAll{ | ||
c -> c.contains('curl') | ||
} | ||
assertThat(cmd.size(), equalTo(1)) | ||
assertThat(cmd, hasItem("curl -X PATCH -H 'Accept: application/vnd.github+json' -H 'Authorization: Bearer GITHUB_TOKEN' https://api.github.com/repos/Codertocat/Hello-World/releases/17372790 -d '{\"tag_name\":\"1.0.0\",\"draft\":false,\"prerelease\":false}'")) | ||
|
||
} | ||
|
||
@Test | ||
void 'use tag as trigger'(){ | ||
runScript("tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile") | ||
def cmd = getCommands('GenericTrigger').findAll{ | ||
c -> c.contains('generic') | ||
} | ||
assertThat(cmd.size(), equalTo(1)) | ||
assertThat(cmd, hasItem('{genericVariables=[{key=ref, value=.ref}, {key=isDraft, value=$.release.draft}, {key=release_url, value=$.release.url}], tokenCredentialId=opensearch-ci-webhook-trigger-token, causeString=A tag was cut on opensearch-ci repo, printContributedVariables=false, printPostContent=false, regexpFilterText=$ref, regexpFilterExpression=^refs/tags/.*}')) | ||
} | ||
|
||
@Test | ||
void 'validate release is not published'(){ | ||
runScript("tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile") | ||
def cmd = getCommands('sh').findAll{ | ||
c -> c.contains('curl') | ||
} | ||
assertThat(cmd.size(), equalTo(0)) | ||
} | ||
|
||
def getCommands(String method) { | ||
def echoCommands = helper.callStack.findAll { call -> | ||
call.methodName == method | ||
}.collect { call -> | ||
callArgsToString(call) | ||
} | ||
return echoCommands | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
pipeline { | ||
agent none | ||
stages { | ||
stage('publishToNpm') { | ||
steps { | ||
script { | ||
publishToNpm( | ||
repository: 'https://github.com/opensearch-project/opensearch-ci', | ||
tag: '1.0.0' | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
PublishToNpm_Jenkinsfile.run() | ||
PublishToNpm_Jenkinsfile.pipeline(groovy.lang.Closure) | ||
PublishToNpm_Jenkinsfile.echo(Executing on agent [label:none]) | ||
PublishToNpm_Jenkinsfile.stage(publishToNpm, groovy.lang.Closure) | ||
PublishToNpm_Jenkinsfile.script(groovy.lang.Closure) | ||
PublishToNpm_Jenkinsfile.publishToNpm({repository=https://github.com/opensearch-project/opensearch-ci, tag=1.0.0}) | ||
publishToNpm.checkout({$class=GitSCM, branches=[{name=1.0.0}], userRemoteConfigs=[{url=https://github.com/opensearch-project/opensearch-ci}]}) | ||
publishToNpm.string({credentialsId=jenkins-opensearch-publish-to-npm-token, variable=NPM_TOKEN}) | ||
publishToNpm.withCredentials([NPM_TOKEN], groovy.lang.Closure) | ||
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) |
12 changes: 12 additions & 0 deletions
12
tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
standardReleasePipeline(overrideAgent: 'AL2-X64', | ||
overrideDockerImage: 'test:image') | ||
{ | ||
fakePublishToMaven( | ||
mavenArtifactsPath: "/maven", | ||
autoPublish: true | ||
) | ||
} | ||
|
||
def fakePublishToMaven(Map args) { | ||
echo "fakePublishToMaven ${args}" | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
StandardReleasePipelineWithArgs_JenkinsFile.run() | ||
StandardReleasePipelineWithArgs_JenkinsFile.standardReleasePipeline({overrideAgent=AL2-X64, overrideDockerImage=test:image}, groovy.lang.Closure) | ||
standardReleasePipeline.pipeline(groovy.lang.Closure) | ||
standardReleasePipeline.timeout({time=1, unit=HOURS}) | ||
standardReleasePipeline.echo(Executing on agent [docker:[image:test:image, reuseNode:false, stages:[:], args:, alwaysPull:true, containerPerStageRoot:false, label:AL2-X64]]) | ||
standardReleasePipeline.stage(Release, groovy.lang.Closure) | ||
standardReleasePipeline.script(groovy.lang.Closure) | ||
StandardReleasePipelineWithArgs_JenkinsFile.echo(fakePublishToMaven [mavenArtifactsPath:/maven, autoPublish:true]) | ||
standardReleasePipeline.script(groovy.lang.Closure) | ||
standardReleasePipeline.postCleanup() | ||
postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true}) |
14 changes: 14 additions & 0 deletions
14
tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
standardReleasePipelineWithGenericTrigger(jsonValue: '.ref', | ||
tokenIdCredential: 'opensearch-ci-webhook-trigger-token', | ||
causeString: 'A tag was cut on opensearch-ci repo', | ||
regexpFilterText: '$ref', | ||
regexpFilterExpression: '^refs/tags/.*') | ||
{ | ||
fakePublishToNpm( | ||
tag: "${tag}" | ||
) | ||
} | ||
|
||
def fakePublishToNpm(Map args) { | ||
echo "fakePublishToNpm ${args}" | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile.run() | ||
StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile.standardReleasePipelineWithGenericTrigger({jsonValue=.ref, tokenIdCredential=opensearch-ci-webhook-trigger-token, causeString=A tag was cut on opensearch-ci repo, regexpFilterText=$ref, regexpFilterExpression=^refs/tags/.*}, groovy.lang.Closure) | ||
standardReleasePipelineWithGenericTrigger.pipeline(groovy.lang.Closure) | ||
standardReleasePipelineWithGenericTrigger.timeout({time=1, unit=HOURS}) | ||
standardReleasePipelineWithGenericTrigger.echo(Executing on agent [docker:[image:opensearchstaging/ci-runner:release-centos7-clients-v1, reuseNode:false, stages:[:], args:, alwaysPull:true, containerPerStageRoot:false, label:Jenkins-Agent-AL2-X64-C54xlarge-Docker-Host]]) | ||
standardReleasePipelineWithGenericTrigger.GenericTrigger({genericVariables=[{key=ref, value=.ref}, {key=isDraft, value=$.release.draft}, {key=release_url, value=$.release.url}], tokenCredentialId=opensearch-ci-webhook-trigger-token, causeString=A tag was cut on opensearch-ci repo, printContributedVariables=false, printPostContent=false, regexpFilterText=$ref, regexpFilterExpression=^refs/tags/.*}) | ||
standardReleasePipelineWithGenericTrigger.stage(Release, groovy.lang.Closure) | ||
standardReleasePipelineWithGenericTrigger.script(groovy.lang.Closure) | ||
StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile.echo(fakePublishToNpm [tag:1.0.0]) | ||
standardReleasePipelineWithGenericTrigger.script(groovy.lang.Closure) | ||
standardReleasePipelineWithGenericTrigger.postCleanup() | ||
postCleanup.cleanWs({disableDeferredWipeout=true, deleteDirs=true}) | ||
standardReleasePipelineWithGenericTrigger.script(groovy.lang.Closure) |
Oops, something went wrong.