Skip to content

Commit

Permalink
Setup workflow to upload to Maven central (#49)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
darwin67 committed Feb 29, 2024
1 parent fb78f3d commit a311231
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 11 deletions.
56 changes: 52 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 '[email protected]'
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 }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ gradle-app.setting
/.direnv
.DS_Store
.factorypath
bundle.zip
**/tmp/

# LSP generated
**/.settings/
Expand Down
4 changes: 2 additions & 2 deletions inngest-spring-boot-demo/fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
1 change: 1 addition & 0 deletions inngest/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.2.0
64 changes: 59 additions & 5 deletions inngest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<MavenPublication>("gpr") {
register<MavenPublication>("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("[email protected]")
}
}

scm {
url.set("https://github.com/inngest/inngest-kt")
connection.set("scm:git:https://github.com/inngest/inngest-kt.git")
developerConnection.set("scm:git:[email protected]: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(
Expand All @@ -70,6 +118,12 @@ tasks.jar {
}
}

tasks.javadoc {
if (JavaVersion.current().isJava9Compatible) {
(options as StandardJavadocDocletOptions).addBooleanOption("html5", true)
}
}

tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
Expand Down
19 changes: 19 additions & 0 deletions inngest/maven-bundle
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a311231

Please sign in to comment.