diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml deleted file mode 100644 index c6c7fce..0000000 --- a/.github/workflows/deploy-docs.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Deploy Documentation - -on: - workflow_run: - workflows: ["Build and Test"] - branches: [main] - types: - - completed - -jobs: - generate-docs: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 - - - name: Generate docs - run: ./gradlew :dokkaHtml - - - name: Bundle Docs - uses: actions/upload-pages-artifact@v1 - with: - path: "./docs" - - deploy-docs: - needs: generate-docs - - permissions: - pages: write - id-token: write - - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - - runs-on: ubuntu-latest - steps: - - name: Deploy docs - id: deployment - uses: actions/deploy-pages@v3 diff --git a/.github/workflows/publish-maven.yml b/.github/workflows/publish-maven.yml new file mode 100644 index 0000000..405da59 --- /dev/null +++ b/.github/workflows/publish-maven.yml @@ -0,0 +1,73 @@ +name: Publish Package to Maven Registry + +on: + push: + tags: + - 'v*' + +jobs: + create-release: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Create a release + uses: ncipollo/release-action@v1 + with: + generateReleaseNotes: true + + generate-docs: + needs: create-release + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Generate docs + run: ./gradlew :dokkaHtml + + - name: Bundle Docs + uses: actions/upload-pages-artifact@v3 + with: + path: "./docs" + + publish-package: + needs: create-release + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Publish package + run: ./gradlew :publish + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_PRIVATE_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} + + deploy-docs: + needs: [generate-docs, publish-package] + + permissions: + pages: write + id-token: write + + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + runs-on: ubuntu-latest + steps: + - name: Deploy docs + id: deployment + uses: actions/deploy-pages@v3 diff --git a/build.gradle.kts b/build.gradle.kts index 71cb30c..d7b7c27 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,10 +1,14 @@ +import com.vanniktech.maven.publish.JavadocJar +import com.vanniktech.maven.publish.KotlinJvm +import com.vanniktech.maven.publish.SonatypeHost import org.jetbrains.dokka.gradle.DokkaTask import java.net.URI plugins { - kotlin("jvm") version "2.0.0" - alias(libs.plugins.dokka) - `java-library` + kotlin("jvm") version "2.0.0" + alias(libs.plugins.dokka) + alias(libs.plugins.maven.publishing) + `java-library` } group = "io.github.cybercodernaj" @@ -13,33 +17,70 @@ version = libs.versions.lib.get() val docsDir = layout.projectDirectory.dir("docs/") repositories { - mavenCentral() + mavenCentral() } dependencies { - testImplementation(kotlin("test")) + testImplementation(kotlin("test")) } tasks.test { - useJUnitPlatform() + useJUnitPlatform() } kotlin { - jvmToolchain(18) + jvmToolchain(18) } tasks.withType().configureEach { - moduleName.set(project.name) - moduleVersion.set(project.version.toString()) - outputDirectory.set(docsDir) - dokkaSourceSets.configureEach { - sourceLink { - localDirectory.set(projectDir.resolve("src")) - remoteUrl.set(URI.create("https://github.com/cybercoder-naj/Parkour/blob/main/src").toURL()) - remoteLineSuffix.set("#L") - } + moduleName.set(project.name) + moduleVersion.set(project.version.toString()) + outputDirectory.set(docsDir) + dokkaSourceSets.configureEach { + sourceLink { + localDirectory.set(projectDir.resolve("src")) + remoteUrl.set(URI.create("https://github.com/cybercoder-naj/Parkour/blob/main/src").toURL()) + remoteLineSuffix.set("#L") } + } } tasks.clean { - delete = setOf(docsDir, layout.buildDirectory) + delete = setOf(docsDir, layout.buildDirectory) +} + +mavenPublishing { + configure(KotlinJvm( + javadocJar = JavadocJar.Dokka("dokkaHtml"), + sourcesJar = true + )) + + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true) + + coordinates(project.group.toString(), project.name, project.version.toString()) + + pom { + name.set("Parkour") + description.set("Parser Combinator library for Kotlin") + inceptionYear.set("2024") + url.set("https://github.com/cybercoder-naj/Parkour/") + licenses { + license { + name.set("MIT License") + url.set("https://github.com/cybercoder-naj/Parkour/blob/main/LICENSE") + distribution.set("repo") + } + } + developers { + developer { + id.set("cybercoder-naj") + name.set("Nishant Aanjaney Jalan") + url.set("https://github.com/cybercoder-naj/") + } + } + scm { + url.set("https://github.com/cybercoder-naj/Parkour/") + connection.set("scm:git:git://github.com/cybercoder-naj/Parkour.git") + developerConnection.set("scm:git:ssh://git@github.com/cybercoder-naj/Parkour.git") + } + } } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b4ebedb..9522ca4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,6 +3,8 @@ [versions] lib = "0.0.1" dokkaVer = "1.9.20" +mavenPublishingVer = "0.28.0" [plugins] -dokka = { id = "org.jetbrains.dokka", version.ref = "dokkaVer" } \ No newline at end of file +dokka = { id = "org.jetbrains.dokka", version.ref = "dokkaVer" } +maven-publishing = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublishingVer" } \ No newline at end of file