diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..91068a8 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,34 @@ +name: Publish Authsignal Java SDK + +on: + release: + types: [published] + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: "17" + distribution: "temurin" + cache: gradle + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build and Publish + env: + SIGNING_PUBLIC_KEY: ${{ secrets.SIGNING_PUBLIC_KEY }} + SIGNING_SECRET_KEY: ${{ secrets.SIGNING_SECRET_KEY }} + SIGNING_PASSPHRASE: ${{ secrets.SIGNING_PASSPHRASE }} + MAVENCENTRAL_USERNAME: ${{ secrets.MAVENCENTRAL_USERNAME }} + MAVENCENTRAL_PASSWORD: ${{ secrets.MAVENCENTRAL_PASSWORD }} + run: | + ./gradlew clean + ./gradlew build + ./gradlew jreleaserDeploy diff --git a/README.md b/README.md index 82932fd..ce0c1ac 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Check out our [official Java SDK documentation](https://docs.authsignal.com/sdks Add this dependency to your project's build file: ```groovy -implementation 'com.authsignal:authsignal-java:2.3.0' +implementation 'com.authsignal:authsignal-java:2.6.0' ``` ### Maven users @@ -26,7 +26,7 @@ Add this dependency to your project's POM: com.authsignal authsignal-java - 2.3.0 + 2.6.0 ``` diff --git a/build.gradle b/build.gradle index befaf29..ca0c091 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java-library' id 'maven-publish' id 'signing' - id 'io.github.gradle-nexus.publish-plugin' version '1.3.0' + id 'org.jreleaser' version '1.19.0' } repositories { @@ -11,25 +11,9 @@ repositories { dependencies { implementation 'com.google.code.gson:gson:2.10.1' - testImplementation 'junit:junit:4.13.2' } -def Properties properties = new Properties() -properties.load(project.rootProject.file("local.properties").newDataInputStream()) - -nexusPublishing { - repositories { - sonatype { - username.set(properties.getProperty("ossrhUsername")) - password.set(properties.getProperty("ossrhPassword")) - stagingProfileId.set(properties.getProperty("sonatypeStagingProfileId")) - nexusUrl.set(uri(properties.getProperty("nexusUrl"))) - snapshotRepositoryUrl.set(uri(properties.getProperty("snapshotRepositoryUrl"))) - } - } -} - java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 @@ -40,19 +24,13 @@ java { publishing { publications { - mavenJava(MavenPublication) { - artifactId = project.pomArtifactId - groupId = project.pomGroup - version = project.versionName + maven(MavenPublication) { + groupId = 'com.authsignal' + artifactId = 'authsignal-java' + version = project.version + from components.java - versionMapping { - usage('java-api') { - fromResolutionOf('runtimeClasspath') - } - usage('java-runtime') { - fromResolutionResult() - } - } + pom { name = 'authsignal-java' description = 'The Authsignal Server SDK for Java.' @@ -77,16 +55,42 @@ publishing { } } } -} -signing { - useInMemoryPgpKeys( - properties.getProperty("signing.keyId"), - properties.getProperty("signing.key"), - properties.getProperty("signing.password"), - ) + repositories { + maven { + url = layout.buildDirectory.dir('staging-deploy') + } + } +} - sign publishing.publications.mavenJava +jreleaser { + project { + java { + groupId = 'com.authsignal' + artifactId = 'authsignal-java' + description = 'The Authsignal Server SDK for Java.' + version = project.version + } + } + signing { + active = 'ALWAYS' + publicKey = System.getenv('SIGNING_PUBLIC_KEY') + secretKey = System.getenv('SIGNING_SECRET_KEY') + passphrase = System.getenv('SIGNING_PASSPHRASE') + } + deploy { + maven { + mavenCentral { + sonatype { + active = 'ALWAYS' + url = 'https://central.sonatype.com/api/v1/publisher' + username = System.getenv('MAVENCENTRAL_USERNAME') + password = System.getenv('MAVENCENTRAL_PASSWORD') + stagingRepository('build/staging-deploy') + } + } + } + } } test { diff --git a/gradle.properties b/gradle.properties index 7aa77fd..64dd7a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1 @@ -pomName=Authsignal Server SDK for Java -pomArtifactId=authsignal-java -pomGroup=com.authsignal -pomPackaging=jar -versionName=2.5.0 -versionCode=2025 \ No newline at end of file +version=2.6.0 \ No newline at end of file diff --git a/src/main/java/com/authsignal/AuthsignalClient.java b/src/main/java/com/authsignal/AuthsignalClient.java index 4820cf4..684bd07 100644 --- a/src/main/java/com/authsignal/AuthsignalClient.java +++ b/src/main/java/com/authsignal/AuthsignalClient.java @@ -27,7 +27,7 @@ public class AuthsignalClient { private static final String DEFAULT_API_URL = "https://api.authsignal.com/v1"; private static final int DEFAULT_RETRIES = 2; - private static final String VERSION = "2.5.0"; + private static final String VERSION = "2.6.0"; public Webhook webhook; diff --git a/src/test/java/com/authsignal/AuthsignalClientTests.java b/src/test/java/com/authsignal/AuthsignalClientTests.java index c3e6780..6cb2dfb 100644 --- a/src/test/java/com/authsignal/AuthsignalClientTests.java +++ b/src/test/java/com/authsignal/AuthsignalClientTests.java @@ -7,7 +7,6 @@ import com.authsignal.model.*; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.HashMap; @@ -18,17 +17,30 @@ public class AuthsignalClientTests { private final String baseURL; private AuthsignalClient client; - public AuthsignalClientTests() throws FileNotFoundException, IOException { - Properties localProperties = new Properties(); - localProperties.load(new FileInputStream(System.getProperty("user.dir") + "/local.properties")); + public AuthsignalClientTests() { + baseURL = getProp("AUTHSIGNAL_URL"); - baseURL = localProperties.getProperty("test.baseURL"); - - String secret = localProperties.getProperty("test.secret"); + String secret = getProp("AUTHSIGNAL_SECRET"); client = new AuthsignalClient(secret, baseURL); } + private String getProp(String name) { + String value = System.getenv(name); + + if (value == null) { + try { + Properties localProperties = new Properties(); + localProperties.load(new FileInputStream(System.getProperty("user.dir") + "/local.properties")); + value = localProperties.getProperty(name); + } catch (IOException e) { + throw new RuntimeException("Failed to load properties file", e); + } + } + + return value; + } + @Test public void testInvalidApiSecretKey() { AuthsignalClient invalidClient = new AuthsignalClient("invalid_secret", baseURL); diff --git a/src/test/java/com/authsignal/WebhookTests.java b/src/test/java/com/authsignal/WebhookTests.java index 05fa905..b83c050 100644 --- a/src/test/java/com/authsignal/WebhookTests.java +++ b/src/test/java/com/authsignal/WebhookTests.java @@ -7,20 +7,32 @@ import com.authsignal.model.WebhookEvent; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; public class WebhookTests { private Webhook webhook; - public WebhookTests() throws FileNotFoundException, IOException { - Properties localProperties = new Properties(); - localProperties.load(new FileInputStream(System.getProperty("user.dir") + "/local.properties")); + public WebhookTests() { + String secret = getProp("AUTHSIGNAL_SECRET"); - String apiSecretKey = localProperties.getProperty("test.secret"); + webhook = new Webhook(secret); + } + + private String getProp(String name) { + String value = System.getenv(name); + + if (value == null) { + try { + Properties localProperties = new Properties(); + localProperties.load(new FileInputStream(System.getProperty("user.dir") + "/local.properties")); + value = localProperties.getProperty(name); + } catch (IOException e) { + throw new RuntimeException("Failed to load properties file", e); + } + } - webhook = new Webhook(apiSecretKey); + return value; } @Test