Skip to content

Commit

Permalink
Add Release workflow using Jenkins (#13)
Browse files Browse the repository at this point in the history
* Add Release workflow using Jenkins

Signed-off-by: Khushboo Rajput <khushbr@amazon.com>

---------

Signed-off-by: Khushboo Rajput <khushbr@amazon.com>
  • Loading branch information
khushbr authored May 24, 2023
1 parent 0df56b0 commit 73bfeb7
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 67 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/ci.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish snapshots to maven
name: Build and Publish Snapshots to Maven

on:
workflow_dispatch:
Expand Down Expand Up @@ -30,4 +30,4 @@ jobs:
export SONATYPE_PASSWORD=$(aws secretsmanager get-secret-value --secret-id maven-snapshots-password --query SecretString --output text)
echo "::add-mask::$SONATYPE_USERNAME"
echo "::add-mask::$SONATYPE_PASSWORD"
./gradlew publishShadowPublicationToSnapshotsRepository
./gradlew publishCreatePublicationToSnapshotsRepository
48 changes: 48 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Release drafter

# Push events to every tag not containing "/"
#
# Publish the commons JAR to Maven Local, and create 'artifacts.tar.gz'
# using build dir and adding the contents of repository
#
on:
push:
tags:
- "*"

jobs:
draft-a-release:
name: Draft a release
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout code
uses: actions/checkout@v3
- id: get_data
run: |
echo "approvers=$(cat .github/CODEOWNERS | grep @ | tr -d '*\n ' | sed 's/@/,/g' | sed 's/,//1')" >> $GITHUB_OUTPUT
echo "version=$(cat version.properties)" >> $GITHUB_OUTPUT
- uses: trstringer/manual-approval@v1
with:
secret: ${{ github.TOKEN }}
approvers: ${{ steps.get_data.outputs.approvers }}
minimum-approvals: 2
issue-title: 'Release spring-data-opensearch ${{ steps.get_data.outputs.version }}'
issue-body: "Please approve or deny the release of spring-data-opensearch **TAG**: ${{ github.ref_name }} **COMMIT**: ${{ github.sha }} **VERSION** : ${{ steps.get_data.outputs.version }} "
exclude-workflow-initiator-as-approver: true
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
cache: gradle
- name: Build with Gradle
run: |
./gradlew --no-daemon -Dbuild.snapshot=false publishCreatePublicationToLocalRepoRepository && tar -C build -cvf artifacts.tar.gz repository
- name: Draft a release
uses: softprops/action-gh-release@v1
with:
draft: true
generate_release_notes: true
files: |
artifacts.tar.gz
63 changes: 37 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,31 @@

buildscript {
ext {
library_version="1.0.0.0-SNAPSHOT"
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
buildVersionQualifier = System.getProperty("build.version_qualifier", "")
// Detect version from version.properties and align it with the build settings
def build = new Properties()
file("version.properties").withInputStream { build.load(it) }
var isSnapshot = "true" == System.getProperty("build.snapshot", "true")
buildVersion = build.getProperty("version")
if (isSnapshot && !buildVersion.endsWith("SNAPSHOT")) {
buildVersion = buildVersion + "-SNAPSHOT"
} else if (!isSnapshot && buildVersion.endsWith("SNAPSHOT")) {
throw GradleException("Expecting release (non-SNAPSHOT) build but version is not set accordingly: " + buildVersion)
}

// Check if tag release version (if provided) matches the version from build settings
tagVersion = System.getProperty("build.version", buildVersion)
if (!buildVersion.equals(tagVersion)) {
throw GradleException("The tagged version " + tagVersion + " does not match the build version " + buildVersion)
}
}

repositories {
mavenLocal()
mavenCentral()
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
maven { url "https://plugins.gradle.org/m2/" }
}

dependencies {
//classpath "org.opensearch.gradle:build-tools:${opensearch_version}"
classpath group: 'com.google.guava', name: 'guava', version: '30.1-jre'
}
}
Expand Down Expand Up @@ -47,17 +58,15 @@ spotbugsTest {
ignoreFailures = true
}


repositories {
mavenLocal()
mavenCentral()
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
maven { url "https://plugins.gradle.org/m2/" }
}

allprojects {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
maven { url "https://plugins.gradle.org/m2/" }
}
group 'org.opensearch.performanceanalyzer.commons'
version = library_version
version = buildVersion
}

targetCompatibility = JavaVersion.VERSION_11
Expand Down Expand Up @@ -149,10 +158,6 @@ spotless {
}
}

task sourcesJar(type: Jar) {
from sourceSets.main.allJava
}

tasks.withType(Test) {
jvmArgs('--add-opens=java.base/sun.nio.fs=ALL-UNNAMED')
jvmArgs('--add-opens=java.base/java.nio.file=ALL-UNNAMED')
Expand All @@ -163,11 +168,11 @@ tasks.withType(Test) {

publishing {
publications {
shadow(MavenPublication) {
create(MavenPublication) {
groupId = 'org.opensearch'
artifactId = 'performance-analyzer-commons'

artifact sourcesJar
from components.java

pom {
name = "OpenSearch Performance Analyzer Commons"
Expand Down Expand Up @@ -195,14 +200,20 @@ publishing {
}
}
repositories {
maven {
name = "Snapshots"
url = "https://aws.oss.sonatype.org/content/repositories/snapshots"
credentials {
username "$System.env.SONATYPE_USERNAME"
password "$System.env.SONATYPE_PASSWORD"
if (buildVersion.toString().endsWith("SNAPSHOT")) {
maven {
name = "Snapshots"
url = "https://aws.oss.sonatype.org/content/repositories/snapshots/"
credentials {
username = System.getenv("SONATYPE_USERNAME")
password = System.getenv("SONATYPE_PASSWORD")
}
}
}
maven {
name = "localRepo"
url = "${rootProject.buildDir}/repository"
}
}

gradle.startParameter.setShowStacktrace(ShowStacktrace.ALWAYS)
Expand Down
16 changes: 16 additions & 0 deletions jenkins/release.jenkinsFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
lib = library(identifier: 'jenkins@1.5.3', retriever: modernSCM([
$class: 'GitSCMSource',
remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git',
]))

standardReleasePipelineWithGenericTrigger(
tokenIdCredential: 'jenkins-performance-analyzer-commons-generic-webhook-token',
causeString: 'A tag was cut on opensearch-project/performance-analyzer-commons repository causing this workflow to run',
downloadReleaseAsset: true,
publishRelease: true) {
publishToMaven(
signingArtifactsPath: "$WORKSPACE/repository/",
mavenArtifactsPath: "$WORKSPACE/repository/",
autoPublish: true
)
}
1 change: 1 addition & 0 deletions version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=1.0.0

0 comments on commit 73bfeb7

Please sign in to comment.