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 311d4b2
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
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: 'temurin'
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 }}
31 changes: 30 additions & 1 deletion 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 @@ -52,4 +75,10 @@ tasks.withType<JavaCompile>().configureEach {

tasks.named<Test>("test") {
useJUnitPlatform()
}

tasks.register("printVersion") {
doLast {
println(project.version)
}
}

0 comments on commit 311d4b2

Please sign in to comment.