diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..751a799 --- /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: '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 }} diff --git a/build.gradle.kts b/build.gradle.kts index ad66ffa..9bc16f6 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() @@ -52,4 +75,10 @@ tasks.withType().configureEach { tasks.named("test") { useJUnitPlatform() +} + +tasks.register("printVersion") { + doLast { + println(project.version) + } } \ No newline at end of file