From 96f47d5d22a53426fb0c5c16dd19b58f9bcdf0c4 Mon Sep 17 00:00:00 2001 From: Sayali Gaikawad <61760125+gaiksaya@users.noreply.github.com> Date: Sat, 14 Jan 2023 10:05:50 -0800 Subject: [PATCH] Add workflow to publish snapshots via GHA (#325) * Add workflow to publish snapshots via GHA Signed-off-by: Sayali Gaikawad * Fix task name Signed-off-by: Sayali Gaikawad * Fix conflict and add documentation Signed-off-by: Sayali Gaikawad Signed-off-by: Sayali Gaikawad --- .github/workflows/publish-snapshots.yml | 30 +++++++++++++++ CHANGELOG.md | 1 + README.md | 5 ++- java-client/build.gradle.kts | 7 +++- jenkins/publish-snapshot.jenkinsfile | 50 ------------------------- 5 files changed, 40 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/publish-snapshots.yml delete mode 100644 jenkins/publish-snapshot.jenkinsfile diff --git a/.github/workflows/publish-snapshots.yml b/.github/workflows/publish-snapshots.yml new file mode 100644 index 0000000000..e90f6aaf2d --- /dev/null +++ b/.github/workflows/publish-snapshots.yml @@ -0,0 +1,30 @@ +name: Publish snapshots to maven + +on: + push: + branches: + - main + +jobs: + build-and-publish-snapshots: + runs-on: ubuntu-latest + permissions: + id-token: write + contents: write + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: 11 + distribution: adopt + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + role-to-assume: ${{ secrets.PUBLISH_SNAPSHOTS_ROLE }} + aws-region: us-east-1 + - name: publish snapshots to maven + run: | + export SONATYPE_USERNAME=$(aws secretsmanager get-secret-value --secret-id maven-snapshots-username --query SecretString --output text) + export SONATYPE_PASSWORD=$(aws secretsmanager get-secret-value --secret-id maven-snapshots-password --query SecretString --output text) + ./gradlew --no-daemon publishPublishMavenPublicationToSnapshotsRepository \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index d34fd9bf21..9afa801cd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Add javadoc link for the client ([#255](https://github.com/opensearch-project/opensearch-java/pull/255)) - Add 1-click release workflows ([#321](https://github.com/opensearch-project/opensearch-java/pull/321)) - Introduce new OpenSearchTransport based on Apache HttpClient 5 ([#281](https://github.com/opensearch-project/opensearch-java/pull/281)) +- Add workflow to publish snapshots via GHA ([#325](https://github.com/opensearch-project/opensearch-java/pull/325)) ### Dependencies - Bumps `classgraph` from 4.8.149 to 4.8.154 diff --git a/README.md b/README.md index 6b2638a067..06ec9c85cd 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Please see the [USER_GUIDE](USER_GUIDE.md) for code snippets. * [Documentation](https://opensearch.org/docs/latest/clients/java/) * [JavaDoc](https://www.javadoc.io/doc/org.opensearch.client/opensearch-java/latest/index.html) * [Maven Central](https://search.maven.org/artifact/org.opensearch.client/opensearch-java) -* [Snapshot Builds](https://aws.oss.sonatype.org/content/repositories/snapshots/org/opensearch/client/opensearch-java/) +* [Snapshot Builds](#snapshot-builds) * Need help? Try [Forums](https://discuss.opendistrocommunity.dev/) * [Project Principles](https://opensearch.org/#principles) * [Contributing to OpenSearch](CONTRIBUTING.md) @@ -52,6 +52,9 @@ This project has adopted the [Amazon Open Source Code of Conduct](CODE_OF_CONDUC See [User Guide](USER_GUIDE.md). +## Snapshot Builds +The [snapshots builds](https://aws.oss.sonatype.org/content/repositories/snapshots/org/opensearch/client/opensearch-java/) are published to sonatype using [publish-snapshots.yml](./.github/workflows/publish-snapshots.yml) workflow. Each `push` event to the main branch triggers this workflow. + ## Compatibility with OpenSearch See [Compatibility](COMPATIBILITY.md). diff --git a/java-client/build.gradle.kts b/java-client/build.gradle.kts index 81e04806b1..f82ff60d6b 100644 --- a/java-client/build.gradle.kts +++ b/java-client/build.gradle.kts @@ -257,8 +257,11 @@ publishing { repositories{ if (version.toString().endsWith("SNAPSHOT")) { maven("https://aws.oss.sonatype.org/content/repositories/snapshots/") { - name = "snapshotRepo" - credentials(PasswordCredentials::class) + name = "Snapshots" + credentials { + username = System.getenv("SONATYPE_USERNAME") + password = System.getenv("SONATYPE_PASSWORD") + } } } maven("${rootProject.buildDir}/repository") { diff --git a/jenkins/publish-snapshot.jenkinsfile b/jenkins/publish-snapshot.jenkinsfile deleted file mode 100644 index 73ffdce604..0000000000 --- a/jenkins/publish-snapshot.jenkinsfile +++ /dev/null @@ -1,50 +0,0 @@ -pipeline { - options { - timeout(time: 30, unit: 'MINUTES') - throttleJobProperty( - categories: [], - limitOneJobWithMatchingParams: false, - maxConcurrentPerNode: 0, - maxConcurrentTotal: 1, - paramsToUseForLimit: '', - throttleEnabled: true, - throttleOption: 'project', - ) - } - agent { - docker { - label 'Jenkins-Agent-AL2-X64-C54xlarge-Docker-Host' - image 'opensearchstaging/ci-runner:ci-runner-centos7-opensearch-build-v2' - args '-e JAVA_HOME=/opt/java/openjdk-11' - alwaysPull true - } - } - triggers { - GenericTrigger( - genericVariables: [ - [key: 'ref', value: '$.ref'], - ], - tokenCredentialId: 'jenkins-opensearch-java-generic-webhook-token', - causeString: 'A commit was pushed on opensearch-project/opensearch-java repository main branch causing this workflow to run', - printContributedVariables: false, - printPostContent: false, - regexpFilterText: '$ref', - regexpFilterExpression: '^(refs/heads/main)$' - ) - } - stages { - stage('Publish to Sonatype Snapshots Repo') { - steps { - git url: 'https://github.com/opensearch-project/opensearch-java.git', branch: 'main' - withCredentials([usernamePassword(credentialsId: 'jenkins-sonatype-creds', usernameVariable: 'ORG_GRADLE_PROJECT_snapshotRepoUsername', passwordVariable: 'ORG_GRADLE_PROJECT_snapshotRepoPassword')]) { - sh './gradlew --no-daemon publishPublishMavenPublicationToSnapshotRepoRepository' - } - } - post { - always { - cleanWs disableDeferredWipeout: true, deleteDirs: true - } - } - } - } -}