diff --git a/.github/workflows/publish_snapshot.yml b/.github/workflows/publish_snapshot.yml new file mode 100644 index 0000000..a15d27c --- /dev/null +++ b/.github/workflows/publish_snapshot.yml @@ -0,0 +1,41 @@ +name: Publish Snapshot to Maven + +on: + push: + branches: + - main + tags-ignore: + - '*' + +jobs: + publish: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 1 + + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + distribution: adopt + java-version: 11 + + - name: Install dependencies + run: bash ./install_deps.sh + + - name: Compile and prepare package + run: | + ./gradlew buildHeaders build assemble androidSourcesJar + + - name: Publish Snapshot to MavenCentral + run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} + SNAPSHOT: true diff --git a/build.gradle b/build.gradle index 8fb1893..705abef 100644 --- a/build.gradle +++ b/build.gradle @@ -20,20 +20,3 @@ apply plugin: 'io.github.gradle-nexus.publish-plugin' task clean(type: Delete) { delete rootProject.buildDir } - -Properties properties = new Properties() -if (rootProject.file("local.properties").exists()) { - properties.load(rootProject.file("local.properties").newDataInputStream()) -} -// Publish to Maven Central -nexusPublishing { - repositories { - sonatype { - stagingProfileId = properties.getProperty("sonatypeStagingProfileId", System.getenv('SONATYPE_STAGING_PROFILE_ID')) - username = properties.getProperty("ossrhUsername", System.getenv('OSSRH_USERNAME')) - password = properties.getProperty("ossrhPassword", System.getenv('OSSRH_PASSWORD')) - nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) - snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) - } -} -} diff --git a/lib/build.gradle b/lib/build.gradle index 23e5ed8..e35598f 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -15,6 +15,7 @@ ext["key"] = properties.getProperty("signing.key", System.getenv('SIGNING_KEY')) ext["ossrhUsername"] = properties.getProperty("ossrhUsername", System.getenv('OSSRH_USERNAME')) ext["ossrhPassword"] = properties.getProperty("ossrhPassword", System.getenv('OSSRH_PASSWORD')) ext["sonatypeStagingProfileId"] = properties.getProperty("sonatypeStagingProfileId", System.getenv('SONATYPE_STAGING_PROFILE_ID')) +ext["snapshot"] = System.getenv('SNAPSHOT') ?: false ext { set("GROUP_ID", "org.kiwix.libkiwix") @@ -22,6 +23,30 @@ ext { set("VERSION", "1.0.0") } +if (snapshot) { + ext["VERSION_CODE"] = VERSION + "-SNAPSHOT" +} else { + ext["VERSION_CODE"] = VERSION +} + +// Publish to Maven Central +nexusPublishing { + useStaging.set(provider { + def release = publishing.publications.release + release.version.endsWith("-SNAPSHOT") + }) + repositories { + sonatype { + stagingProfileId = properties.getProperty("sonatypeStagingProfileId", System.getenv('SONATYPE_STAGING_PROFILE_ID')) + username = properties.getProperty("ossrhUsername", System.getenv('OSSRH_USERNAME')) + password = properties.getProperty("ossrhPassword", System.getenv('OSSRH_PASSWORD')) + version = VERSION_CODE + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + } + } +} + // Replace these versions with the latest available versions of libkiwix and libzim ext.libkiwix_version = "12.0.0" ext.libzim_version = "8.2.0" diff --git a/lib/publish.gradle b/lib/publish.gradle index b8e4fb9..2198c50 100644 --- a/lib/publish.gradle +++ b/lib/publish.gradle @@ -22,7 +22,7 @@ def siteUrl = 'https://www.kiwix.org/en/' def gitUrl = 'https://github.com/kiwix/libkiwix.git' group = GROUP_ID -version = VERSION +version = VERSION_CODE afterEvaluate { publishing { @@ -31,7 +31,7 @@ afterEvaluate { groupId GROUP_ID artifactId ARTIFACT_ID - version VERSION + version VERSION_CODE from components.release @@ -61,15 +61,6 @@ afterEvaluate { } } } - repositories { - maven { - url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") - credentials { - username = ossrhUsername - password = ossrhPassword - } - } - } } }