From a3112312b0ff28ac5fced18f0d1ca3e5486dc2e6 Mon Sep 17 00:00:00 2001 From: Darwin <5746693+darwin67@users.noreply.github.com> Date: Thu, 29 Feb 2024 14:49:03 -0800 Subject: [PATCH] Setup workflow to upload to Maven central (#49) Update the SDK core's `build.gradle.kts` to publish to a local Maven repo (which is just basically a file path), and bundle that to send it over to Maven Central's publisher API. The new Maven Central don't have integration with gradle atm, so unfortunately, we'll just have to automate it in a way simulating a manual upload. https://central.sonatype.org/publish/publish-portal-api/ The `Release` github workflow is set to trigger when there are changes made to each project's `VERSION` file. Which assumes that we'll want to publish a new version. --------- Co-authored-by: Darwin D Wu --- .github/workflows/release.yml | 56 +++++++++++++++++++++++++-- .gitignore | 2 + inngest-spring-boot-demo/fly.toml | 4 +- inngest/VERSION | 1 + inngest/build.gradle.kts | 64 ++++++++++++++++++++++++++++--- inngest/maven-bundle | 19 +++++++++ 6 files changed, 135 insertions(+), 11 deletions(-) create mode 100644 inngest/VERSION create mode 100755 inngest/maven-bundle diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c90a489c..152a8f5b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,13 +1,30 @@ name: Release on: - release: - types: - - created + push: + branches: [main] jobs: + changes: + runs-on: ubuntu-latest + outputs: + pkgs: ${{ steps.filter.outputs.changes }} + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + inngest: inngest/VERSION + + # Publish will only run when it detects a change on top publish: + needs: changes runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + pkg: ${{ fromJSON(needs.changes.outputs.pkgs) }} steps: - uses: actions/checkout@v4 - name: Setup Java @@ -19,9 +36,40 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v3 + - name: Set version + working-directory: ${{ matrix.pkg }} + run: echo "PKG_VERSION=$(cat VERSION)" >> $GITHUB_ENV + - name: Publish package - run: gradle publish + working-directory: ${{ matrix.pkg }} + run: gradle publish --info env: MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }} + GPG_SIGNING_KEY_PASSWORD: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }} + + - name: Create bundle for Maven Central + working-directory: ${{ matrix.pkg }} + run: ./maven-bundle + + - name: Upload bundle to Maven Central + working-directory: ${{ matrix.pkg }} + run: | + # Generate bearer token + TOKEN=$(echo -n $AUTH | base64) + + # Upload via API + curl -v -X POST "$PUBLISHER_API?name=$PKG_NAME&publishingType=AUTOMATIC" \ + -H "Authorization: Bearer $TOKEN" \ + -F 'bundle=@bundle.zip' + env: + AUTH: "${{ secrets.MAVEN_USERNAME }}:${{ secrets.MAVEN_PASSWORD }}" + PKG_NAME: com.inngest:${{ matrix.pkg }}:${{ env.PKG_VERSION }} + PUBLISHER_API: https://central.sonatype.com/api/v1/publisher/upload + + - name: Create tag for pkg + run: git tag $TAG && git push $TAG + env: + TAG: ${{ matrix.pkg }}-${{ env.PKG_VERSION }} diff --git a/.gitignore b/.gitignore index 40cbef64..dc8efd54 100644 --- a/.gitignore +++ b/.gitignore @@ -72,6 +72,8 @@ gradle-app.setting /.direnv .DS_Store .factorypath +bundle.zip +**/tmp/ # LSP generated **/.settings/ diff --git a/inngest-spring-boot-demo/fly.toml b/inngest-spring-boot-demo/fly.toml index 0b4b3272..c9014747 100644 --- a/inngest-spring-boot-demo/fly.toml +++ b/inngest-spring-boot-demo/fly.toml @@ -12,8 +12,8 @@ processes = [] [env] INNGEST_ENV = "prod" - INNGEST_API_BASE_URL = "https://api.inngest.net" - INNGEST_BASE_URL = "https://stage.inn.gs" + # INNGEST_API_BASE_URL = "https://api.inngest.net" + # INNGEST_BASE_URL = "https://stage.inn.gs" INNGEST_SERVE_ORIGIN = "https://inngest-spring-boot-demo.fly.dev" [[services]] diff --git a/inngest/VERSION b/inngest/VERSION new file mode 100644 index 00000000..0ea3a944 --- /dev/null +++ b/inngest/VERSION @@ -0,0 +1 @@ +0.2.0 diff --git a/inngest/build.gradle.kts b/inngest/build.gradle.kts index 1ac47803..c627f72d 100644 --- a/inngest/build.gradle.kts +++ b/inngest/build.gradle.kts @@ -3,16 +3,20 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent group = "com.inngest" description = "Inngest SDK" -version = "0.0.2" +version = file("VERSION").readText().trim() plugins { + id("java-library") id("maven-publish") + id("signing") id("org.jetbrains.kotlin.jvm") version "1.9.10" } // TODO - Move this to share conventions gradle file java { toolchain { languageVersion.set(JavaLanguageVersion.of(8)) } + withJavadocJar() + withSourcesJar() } repositories { @@ -34,31 +38,75 @@ dependencies { publishing { repositories { + // NOTE: Does not work: https://central.sonatype.org/publish/publish-portal-gradle/ // maven { // name = "OSSRH" - // url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + // url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") // credentials { // username = System.getenv("MAVEN_USERNAME") // password = System.getenv("MAVEN_PASSWORD") // } // } + // NOTE: create a local repo and bundle this to upload it to Maven Central for now + maven { + // local repo + val releasesRepoUrl = uri(layout.buildDirectory.dir("repos/releases")) + val snapshotsRepoUrl = uri(layout.buildDirectory.dir("repos/snapshots")) + url = if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl + } + maven { name = "GitHubPackages" url = uri("https://maven.pkg.github.com/inngest/inngest-kt") credentials { - username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") - password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") } } } publications { - register("gpr") { + register("inngest") { from(components["java"]) + + pom { + name.set(project.name) + description.set("Inngest SDK for Kotlin/Java") + url.set("https://github.com/inngest/inngest-kt") + inceptionYear.set("2024") + + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + + developers { + developer { + id.set("eng") + name.set("Inngest Engineering") + email.set("eng@inngest.com") + } + } + + scm { + url.set("https://github.com/inngest/inngest-kt") + connection.set("scm:git:https://github.com/inngest/inngest-kt.git") + developerConnection.set("scm:git:git@github.com:inngest/inngest-kt.git") + } + } } } } +signing { + val signingKey = System.getenv("GPG_SIGNING_KEY") + val signingPasswd = System.getenv("GPG_SIGNING_KEY_PASSWORD") + useInMemoryPgpKeys(signingKey, signingPasswd) + sign(publishing.publications) +} + tasks.jar { manifest { attributes( @@ -70,6 +118,12 @@ tasks.jar { } } +tasks.javadoc { + if (JavaVersion.current().isJava9Compatible) { + (options as StandardJavadocDocletOptions).addBooleanOption("html5", true) + } +} + tasks.named("test") { // Use JUnit Platform for unit tests. useJUnitPlatform() diff --git a/inngest/maven-bundle b/inngest/maven-bundle new file mode 100755 index 00000000..900565a8 --- /dev/null +++ b/inngest/maven-bundle @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +RELEASES=build/repos/releases/com +ASSEMBLE=$(mktemp -d) +cp -R $RELEASES $ASSEMBLE + +# Enter temp dir +pushd $ASSEMBLE + +rm com/inngest/inngest/maven-* +zip -r bundle.zip com + +popd + +cp $ASSEMBLE/bundle.zip . + +rm -rf $ASSEMBLE