From f2b44094e55e65e5954be3a5ad3edbf95f7da928 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 | 65 +++++++++++++++++ LICENSE | 2 +- build.gradle.kts | 70 +++++++++++++++++-- gradle.properties | 0 .../java/io/codef/api/CodefException.java | 5 ++ .../java/io/codef/api/EasyCodefTokenTest.java | 1 + 6 files changed, 136 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/publish.yml create mode 100644 gradle.properties diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..cccb8b0 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,65 @@ +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: 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 --force origin "v${VERSION}" + + - name: Set up GPG + run: | + echo "$GPG_PRIVATE_KEY" | gpg --batch --import + echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf + echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf + gpg-connect-agent reloadagent /bye + env: + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + + - name: Configure gradle-wrapper.properties + run: | + echo "mavenCentralUsername=${{ secrets.OSSRH_USERNAME }}" >> gradle.properties + echo "mavenCentralPassword=${{ secrets.OSSRH_PASSWORD }}" >> gradle.properties + + - name: Publish to Maven Central + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} + run: | + ./gradlew publishAllPublicationsToMavenCentralRepository --stacktrace \ No newline at end of file diff --git a/LICENSE b/LICENSE index e97da5b..17d54ff 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020~2025 Hectodata co,. Ltd +Copyright (c) 2024~2025 Hectodata co,. Ltd Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/build.gradle.kts b/build.gradle.kts index ad66ffa..f345b9c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,14 +1,69 @@ +import com.vanniktech.maven.publish.JavaLibrary +import com.vanniktech.maven.publish.JavadocJar +import com.vanniktech.maven.publish.SonatypeHost + plugins { java + signing + id("com.vanniktech.maven.publish") version "0.30.0" } + group = "io.codef.api" -version = "2.0.0-ALPHA-01" +version = "2.0.0-alpha+001" + +signing { + useInMemoryPgpKeys( + System.getenv("GPG_PRIVATE_KEY"), + System.getenv("GPG_PASSPHRASE") + ) + sign(publishing.publications) +} repositories { mavenCentral() } +mavenPublishing { + configure(JavaLibrary(JavadocJar.Javadoc(), true)) + publishToMavenCentral(SonatypeHost.S01) + + coordinates("io.codef.api", "easycodef-jdk-v2", version.toString()) + pom { + url = "api.codef.io" + name = "easycodef-jdk-v2" + description = "Advanced EasyCodef Library for JDK" + inceptionYear = "2024" + + licenses { + license { + name = "MIT License" + url = "https://opensource.org/licenses/MIT" + distribution = "https://opensource.org/licenses/MIT" + } + } + developers { + developer { + id = "happybean" + name = "Haebin Byeon" + email = "happybean@hecto.co.kr" + } + } + + scm { + connection = "scm:git:git@github.com:codef-io/easycodef-jdk-v2.git" + developerConnection = "scm:git:ssh://github.com/codef-io/easycodef-jdk-v2.git" + url = "https://github.com/codef-io/easycodef-jdk-v2" + } + + issueManagement { + system = "GitHub" + url = "https://github.com/codef-io/easycodef-jdk-v2/issues" + } + } +} + + dependencies { /** @@ -40,16 +95,19 @@ dependencies { testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.11.3") } + 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/gradle.properties b/gradle.properties new file mode 100644 index 0000000..e69de29 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..aa99dcc 100644 --- a/src/test/java/io/codef/api/EasyCodefTokenTest.java +++ b/src/test/java/io/codef/api/EasyCodefTokenTest.java @@ -9,5 +9,6 @@ public class EasyCodefTokenTest { @Test public void usageExample() { + } }