diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml new file mode 100644 index 0000000..3a798d0 --- /dev/null +++ b/.github/workflows/prepare-release.yml @@ -0,0 +1,91 @@ +name: Prepare Release +on: + pull_request: + +env: + NEXUS_SDK_REF: release-publishing + NEXUS_SDK_TAG: v0.1.0-alpha1 +# workflow_dispatch: +# inputs: +# tag: +# type: string +# description: "Release version tag (e.g. v1.2.3)" +# required: true +# ref: +# type: string +# description: "Git ref from which to release" +# required: true +# default: "main" +# do_publish_jars: +# type: boolean +# description: "Publish Java artifacts for staging" +# required: true +# default: "true" +# env: +# NEXUS_SDK_REF: ${{ github.event.inputs.ref }} +# NEXUS_SDK_TAG: ${{ github.event.inputs.tag }} + +jobs: + create_draft_release: + name: Create Github draft release + runs-on: ubuntu-latest + steps: + - name: Audit gh version + run: gh --version + + - name: Check for existing release + id: check_release + run: | + echo "::echo::on" + gh release view --repo "$GITHUB_REPOSITORY" "$NEXUS_SDK_TAG" \ + && echo "::set-output name=already_exists::true" \ + || echo "::set-output name=already_exists::false" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout repo + if: steps.check_release.outputs.already_exists == 'false' + uses: actions/checkout@v4 + with: + ref: ${{ env.NEXUS_SDK_REF }} + + - name: Create release + if: steps.check_release.outputs.already_exists == 'false' + run: > + gh release create + "$NEXUS_SDK_REF" + --draft + --repo "$GITHUB_REPOSITORY" + --title "$NEXUS_SDK_TAG" + --target "$NEXUS_SDK_REF" + --generate-notes + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + publish_java_artifacts: + name: Publish Java artifacts + # if: ${{ github.event.inputs.do_publish_jars == 'true' }} + runs-on: ubuntu-latest + needs: create_draft_release + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + ref: ${{ env.NEXUS_SDK_REF }} + + - name: Set up Java + uses: actions/setup-java@v4 + with: + java-version: "11" + distribution: "temurin" + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Stage + run: ./gradlew nexus-sdk:publishToMavenCentral --no-configuration-cache + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_IN_MEMORY_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_IN_MEMORY_KEY_PASSWORD }} \ No newline at end of file diff --git a/nexus-sdk/build.gradle b/nexus-sdk/build.gradle index aa0cae1..a6353e0 100644 --- a/nexus-sdk/build.gradle +++ b/nexus-sdk/build.gradle @@ -2,6 +2,7 @@ plugins { id 'java-library' id 'com.diffplug.spotless' + id 'com.vanniktech.maven.publish' version '0.29.0' } dependencies { @@ -30,3 +31,62 @@ spotless { } classes.dependsOn 'spotlessApply' + +ext.getVersionName = { -> + def version = System.getenv('NEXUS_SDK_TAG') + if (version == null || version.isEmpty()) { + return null + } + + // Remove "v" prefix if present + if (version.startsWith("v")) { + version = version.substring(1) + } + return version +} + +group = 'io.nexusrpc' +version = getVersionName() + +import com.vanniktech.maven.publish.SonatypeHost + +mavenPublishing { + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) + + signAllPublications() + + pom { + name = 'Nexus Java SDK' + description = 'Java SDK for working with Nexus RPC' + url = 'https://github.com/nexus-rpc/sdk-java' + licenses { + license { + name = 'MIT License' + url = 'https://opensource.org/license/mit' + } + } + scm { + connection = 'scm:git@github.com:nexus-rpc/sdk-java.git' + developerConnection = 'scm:git@github.com:nexus-rpc/sdk-java.git' + url = 'https://github.com/nexus-rpc/sdk-java.git' + } + developers { + developer { + id = 'team-sdk' + name = 'Temporal.io SDK Team' + email = 'team-sdk@temporal.io' + } + } + } +} + +// Make sure there is a tag at publish time +tasks.whenTaskAdded { task -> + if (task.name == 'generateMetadataFileForMavenPublication') { + task.doFirst { + if (getVersionName() == null) { + throw new GradleException('Must set NEXUS_SDK_TAG env var') + } + } + } +} \ No newline at end of file