From b39d50042c76a55e9807441c57a4541d8e8a3395 Mon Sep 17 00:00:00 2001 From: h-beeen Date: Fri, 8 Nov 2024 15:13:31 +0900 Subject: [PATCH] chore: configure gitHub actions for automated deployment to maven central --- .github/workflows/publish.yml | 52 +++++++++++++++++++ build.gradle.kts | 37 ++++++++++--- .../java/io/codef/api/CodefException.java | 5 ++ .../java/io/codef/api/EasyCodefTokenTest.java | 5 ++ 4 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..b430be1 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,52 @@ +name: Publish to Maven Central Repository + +on: + push: + branches: + - master + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up JDK 21 + uses: actions/setup-java@v3 + with: + distribution: 'adoptopenjdk' + java-version: '21' + + - name: Cache Gradle packages + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Extract version from build.gradle.kts + id: get_version + run: echo "::set-output name=VERSION::$(./gradlew -q printVersion)" + + - name: Create Git tag + env: + VERSION: ${{ steps.get_version.outputs.VERSION }} + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git tag -a "v${VERSION}" -m "Release version ${VERSION}" + git push origin "v${VERSION}" + + - name: Publish to Maven Central + run: ./gradlew publish + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} diff --git a/build.gradle.kts b/build.gradle.kts index ad66ffa..c25bf61 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,32 @@ plugins { java + `maven-publish` } group = "io.codef.api" -version = "2.0.0-ALPHA-01" +version = "2.0.0-ALPHA-001" + +publishing { + publications { + create("mavenJava") { + from(components["java"]) + groupId = "api.codef.io" + artifactId = "easycodef-java-v2" + version = "2.0.0-ALPHA-001" + } + } + repositories { + maven { + name = "MavenCentral" + url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + + credentials { + username = project.findProperty("ossrhUsername") as String? ?: System.getenv("OSSRH_USERNAME") + password = project.findProperty("ossrhPassword") as String? ?: System.getenv("OSSRH_PASSWORD") + } + } + } +} repositories { mavenCentral() @@ -42,14 +65,16 @@ dependencies { java { toolchain { - languageVersion = JavaLanguageVersion.of(17) + languageVersion.set(JavaLanguageVersion.of(17)) } } -tasks.withType().configureEach { - options.compilerArgs.add("-Xlint:all") +tasks.test { + useJUnitPlatform() } -tasks.named("test") { - useJUnitPlatform() +tasks.register("printVersion") { + doLast { + println(project.version) + } } \ No newline at end of file diff --git a/src/main/java/io/codef/api/CodefException.java b/src/main/java/io/codef/api/CodefException.java index f491000..a21f2b5 100644 --- a/src/main/java/io/codef/api/CodefException.java +++ b/src/main/java/io/codef/api/CodefException.java @@ -1,7 +1,12 @@ package io.codef.api; +import java.io.Serial; + public class CodefException extends RuntimeException { + @Serial + private static final long serialVersionUID = 1L; + private static final String LOG_WITH_CAUSE_FORMAT = "%s\n→ %s\n\n"; private final CodefError codefError; diff --git a/src/test/java/io/codef/api/EasyCodefTokenTest.java b/src/test/java/io/codef/api/EasyCodefTokenTest.java index dfce55d..8674416 100644 --- a/src/test/java/io/codef/api/EasyCodefTokenTest.java +++ b/src/test/java/io/codef/api/EasyCodefTokenTest.java @@ -9,5 +9,10 @@ public class EasyCodefTokenTest { @Test public void usageExample() { + EasyCodef easyCodef = EasyCodefProperty.builder() + .clientId("a5395a2e-cc4a-464f-810a-85937e49d61b") + .clientSecret("55a2ccbd-1dca-4c43-9ef1-3680f27e24bf") + .publicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtZiU31DkbuTxm/lcS2Nr0cHTOm4Snz1F4+wmtS7KEVVWgCsWr4xl4Vzup9OFZPrhkZLIs8AdCS79MCW7xjZ9WklopE7kPGGZBbxIkAo2qbxa0FxYM/C08cPy0kJ48yzi2RhBKcsxaDPMI5K6j84r94TBvhTF9lU2YXqh3FNpGs9T9qqEAsnaBfRqvDcEIjIYE3JNgBnT7edSQ3JelhzJ2SfTAugXGCILE9DbrK7nB+lFho48U7rf2wwJXa3vdl+v14MJ+ppYKSX07Z+5Bj7RLfGazLBuVc0ReIyeNKKCJ9Wx/pE68Wj5ZXIq+4s1W+lwH0iDaVlpjRQEYZ6uGF2LTwIDAQAB") + .build(); } }