Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup workflow to upload to Maven central #49

Merged
merged 12 commits into from
Feb 29, 2024
57 changes: 53 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
name: Release

on:
release:
types:
- created
push:
branches: [main]

jobs:
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
pkgs: ${{ steps.filter.outputs.changes }}
steps:
- 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 +37,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 }}
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("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(
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
Loading