Skip to content

Commit

Permalink
chore: configure gitHub actions for automated deployment to maven cen…
Browse files Browse the repository at this point in the history
…tral
  • Loading branch information
h-beeen committed Nov 8, 2024
1 parent 42bbe97 commit b39d500
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 6 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}
37 changes: 31 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<MavenPublication>("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()
Expand Down Expand Up @@ -42,14 +65,16 @@ dependencies {

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
languageVersion.set(JavaLanguageVersion.of(17))
}
}

tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.add("-Xlint:all")
tasks.test {
useJUnitPlatform()
}

tasks.named<Test>("test") {
useJUnitPlatform()
tasks.register("printVersion") {
doLast {
println(project.version)
}
}
5 changes: 5 additions & 0 deletions src/main/java/io/codef/api/CodefException.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/io/codef/api/EasyCodefTokenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit b39d500

Please sign in to comment.