Skip to content

Commit

Permalink
chore: Add publishing support to workflow & gradle build script
Browse files Browse the repository at this point in the history
  • Loading branch information
booniepepper committed Sep 11, 2023
1 parent 5deabb8 commit 672aed8
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 15 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,47 @@ jobs:
- name: Build with Gradle
run: |
./gradlew build
publish:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
needs: [test]

steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.2

- name: Set up JDK
uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0
with:
java-version: 11
distribution: 'temurin'
cache: gradle

- name: Build with Gradle
run: |
./gradlew build
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@56b90f209b02bf6d1deae490e9ef18b21a389cd4 # v1.1.0

- name: Publish package
uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0
with:
arguments: publish
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}

create-release:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
needs: publish

steps:
- uses: actions/checkout@v3

- uses: Roang-zero1/github-create-release-action@5cf058ddffa6fa04e5cda07c98570c757dc4a0e1
with:
version_regex: ^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ gradle/wrapper/gradle-wrapper.jar
gradle/wrapper/gradle-wrapper.properties
gradlew
gradlew.bat
publish.gradle
settings.gradle
src/main/java/dev/openfga/sdk/api/OpenFgaApi.java
src/main/java/dev/openfga/sdk/api/auth/AccessToken.java
Expand Down
29 changes: 17 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
plugins {
id 'java'

// Quality
id 'jvm-test-suite'
id 'maven-publish'
id 'com.diffplug.spotless' version '6.20.0'

// IDE
id 'idea'
id 'eclipse'
id 'com.diffplug.spotless' version '6.20.0'

// Publishing
id 'maven-publish'
id 'signing'
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
}

apply from: 'publish.gradle'

group = 'dev.openfga'
version = '0.0.1'
version = '0.1.0'

repositories {
mavenCentral()
}

publishing {
publications {
maven(MavenPublication) {
artifactId = 'openfga-sdk'
from components.java
}
}
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
Expand Down Expand Up @@ -117,3 +118,7 @@ tasks.register('fmt') {
tasks.register('test-integration') {
dependsOn testing.suites.integration
}

tasks.named('check').configure {
dependsOn 'spotlessCheck'
}
56 changes: 56 additions & 0 deletions publish.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Configuration for Maven Central by Sonatype.
// See: https://github.com/gradle-nexus/publish-plugin
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri('https://s01.oss.sonatype.org/service/local/'))
snapshotRepositoryUrl.set(uri('https://s01.oss.sonatype.org/content/repositories/snapshots/'))
username = System.getenv('MAVEN_USERNAME')
password = System.getenv('MAVEN_PASSWORD')
}
}
}

publishing {
publications {
maven(MavenPublication) {
from components.java

pom {
group = 'dev.openfga'
name = 'openfga-sdk'
version = '0.1.0'
description = 'This is an autogenerated Java SDK for OpenFGA. It provides a wrapper around the [OpenFGA API definition](https://openfga.dev/api).'
url = 'https://openfga.dev'
licenses {
license {
name = 'Apache-2.0'
url = 'https://github.com/openfga/openfga/blob/main/LICENSE'
}
}
developers {
developer {
name = 'OpenFGA'
url = 'https://openfga.dev'
}
}
contributors {
contributor {
id = 'booniepepper'
name = 'J.R. Hill'
url = 'https://so.dang.cool'
}
}
scm {
url = 'https://github.com/openfga/java-sdk'
connection = 'scm:git:[email protected]:openfga/java-sdk.git'
developerConnection = 'scm:git:[email protected]:openfga/java-sdk.git'
}
}
}
}
}

signing {
sign publishing.publications.maven
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
* Configurations for an api client.
*/
public class Configuration implements BaseConfiguration {
public static final String VERSION = "0.0.1";
public static final String VERSION = "0.1.0";

private static final String DEFAULT_API_URL = "http://localhost:8080";
private static final String DEFAULT_USER_AGENT = "openfga-sdk java/0.0.1";
private static final String DEFAULT_USER_AGENT = "openfga-sdk java/0.1.0";
private static final Duration DEFAULT_READ_TIMEOUT = Duration.ofSeconds(10);
private static final Duration DEFAULT_CONNECT_TIMEOUT = Duration.ofSeconds(10);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class ConfigurationTest {
private static final String DEFAULT_API_URL = "http://localhost:8080";
private static final String DEFAULT_USER_AGENT = "openfga-sdk java/0.0.1";
private static final String DEFAULT_USER_AGENT = "openfga-sdk java/0.1.0";
private static final Duration DEFAULT_READ_TIMEOUT = Duration.ofSeconds(10);
private static final Duration DEFAULT_CONNECT_TIMEOUT = Duration.ofSeconds(10);

Expand Down

0 comments on commit 672aed8

Please sign in to comment.