Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhuamazon committed Nov 5, 2022
2 parents 93ba564 + 8c4a662 commit e39e217
Show file tree
Hide file tree
Showing 23 changed files with 602 additions and 3 deletions.
6 changes: 5 additions & 1 deletion .codecov.yml
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%
18 changes: 18 additions & 0 deletions .github/workflows/release.yml
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
2 changes: 1 addition & 1 deletion MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
| ---------------- | --------------------------------------------------- | ----------- |
| Peter Zhu | [peterzhuamazon](https://github.com/peterzhuamazon) | Amazon |
| Sayali Gaikawad | [gaiksaya](https://github.com/gaiksaya) | Amazon |
| Prudhvi Godithi | [prudhvigodithi](https://github.com/prudhvigodithi) | Amazon |
| Prudhvi Godithi | [prudhvigodithi](https://github.com/prudhvigodithi) | Amazon |


[This document](https://github.com/opensearch-project/.github/blob/main/MAINTAINERS.md) explains what maintainers do in this repo, and how they should be doing it. If you're interested in contributing, see [CONTRIBUTING](CONTRIBUTING.md).
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ lib = library(identifier: 'jenkins@<tag>', retriever: modernSCM([
]))
```

#### Library Details

| Name | Description |
|--------------------------------------------------------|:-----------------------------------------------------------------------------------------|
| [standardReleasePipeline.groovy](./vars/standardReleasePipeline.groovy) | The library sets up the necessary jenkins properties for you such as agent label, docker image to use as well as workflow time out. Check how to use the [default](./tests/jenkins/jobs/StandardReleasePipeline_JenkinsFile) in your workflow and how to [overide](./tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile) agent & docker image if you need.|
| [standardReleasePipelineWithGenericTrigger.groovy](./vars/standardReleasePipelineWithGenericTrigger.groovy) | A standard release pipeline for OpenSearch projects including generic triggers. A tag or a draft release can be used as a trigger using this library. The defaults are all set to trigger via a draft release. If the release is successful, the release can be published by using right params.. Check how to use the [default](./tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggers_Jenkinsfile) in your workflow and how to [overide](./tests/jenkins/jobs/StandardReleasePipelineWithGenericTriggersTag_Jenkinsfile) values|
| [publishToNpm.groovy](./vars/publishToNpm.groovy) | A library to publish artifacts to NPM registry under @opensearch-project namespace. You can use [PublishToNpmLibTester](./tests/jenkins/lib-testers/PublishToNpmLibTester.groovy) to add tests in your repository. See how to use the lib in your [jenkinsFile](./tests/jenkins/jobs/PublishToNpm_Jenkinsfile)|

## Contributing

See [developer guide](DEVELOPER_GUIDE.md) and [how to contribute to this project](CONTRIBUTING.md).
Expand Down
19 changes: 19 additions & 0 deletions RELEASING.md
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.
53 changes: 53 additions & 0 deletions tests/jenkins/TestPublishToNpm.groovy
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
}
}
68 changes: 68 additions & 0 deletions tests/jenkins/TestStandardReleasePipeline.groovy
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 tests/jenkins/TestStandardReleasePipelineWithGenericTriggers.groovy
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
}
}
24 changes: 24 additions & 0 deletions tests/jenkins/jobs/PublishToNpm_Jenkinsfile
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'
)
}
}
}
}
}
10 changes: 10 additions & 0 deletions tests/jenkins/jobs/PublishToNpm_Jenkinsfile.txt
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 tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile
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 tests/jenkins/jobs/StandardReleasePipelineWithArgs_JenkinsFile.txt
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})
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}"
}
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)
Loading

0 comments on commit e39e217

Please sign in to comment.