Skip to content

Commit 4751ef1

Browse files
Publish snapshot on maven for testing the java-libkiwix
* Introduce publish_snapshot.yml for uploading the snapshot artifact on the mavenCentral. * We have added the `SNAPSHOT` env variable in publish_snapshot.yml and match it our code if found then it means this workflow triggered to publish the snapshot on maven so on behalf of this we have rectify our code.
1 parent f561034 commit 4751ef1

File tree

4 files changed

+68
-28
lines changed

4 files changed

+68
-28
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Publish Snapshot to Maven
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags-ignore:
8+
- '*'
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-20.04
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 1
18+
19+
- name: Set up JDK 11
20+
uses: actions/setup-java@v2
21+
with:
22+
distribution: adopt
23+
java-version: 11
24+
25+
- name: Install dependencies
26+
run: bash ./install_deps.sh
27+
28+
- name: Compile and prepare package
29+
run: |
30+
./gradlew buildHeaders build assemble androidSourcesJar
31+
32+
- name: Publish Snapshot to MavenCentral
33+
run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
34+
env:
35+
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
36+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
37+
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
38+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
39+
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
40+
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
41+
SNAPSHOT: true

build.gradle

-17
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,3 @@ apply plugin: 'io.github.gradle-nexus.publish-plugin'
2020
task clean(type: Delete) {
2121
delete rootProject.buildDir
2222
}
23-
24-
Properties properties = new Properties()
25-
if (rootProject.file("local.properties").exists()) {
26-
properties.load(rootProject.file("local.properties").newDataInputStream())
27-
}
28-
// Publish to Maven Central
29-
nexusPublishing {
30-
repositories {
31-
sonatype {
32-
stagingProfileId = properties.getProperty("sonatypeStagingProfileId", System.getenv('SONATYPE_STAGING_PROFILE_ID'))
33-
username = properties.getProperty("ossrhUsername", System.getenv('OSSRH_USERNAME'))
34-
password = properties.getProperty("ossrhPassword", System.getenv('OSSRH_PASSWORD'))
35-
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
36-
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
37-
}
38-
}
39-
}

lib/build.gradle

+25
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,38 @@ ext["key"] = properties.getProperty("signing.key", System.getenv('SIGNING_KEY'))
1515
ext["ossrhUsername"] = properties.getProperty("ossrhUsername", System.getenv('OSSRH_USERNAME'))
1616
ext["ossrhPassword"] = properties.getProperty("ossrhPassword", System.getenv('OSSRH_PASSWORD'))
1717
ext["sonatypeStagingProfileId"] = properties.getProperty("sonatypeStagingProfileId", System.getenv('SONATYPE_STAGING_PROFILE_ID'))
18+
ext["snapshot"] = System.getenv('SNAPSHOT') ?: false
1819

1920
ext {
2021
set("GROUP_ID", "org.kiwix.libkiwix")
2122
set("ARTIFACT_ID", "libkiwix")
2223
set("VERSION", "1.0.0")
2324
}
2425

26+
if (snapshot) {
27+
ext["VERSION_CODE"] = VERSION + "-SNAPSHOT"
28+
} else {
29+
ext["VERSION_CODE"] = VERSION
30+
}
31+
32+
// Publish to Maven Central
33+
nexusPublishing {
34+
useStaging.set(provider {
35+
def release = publishing.publications.release
36+
release.version.endsWith("-SNAPSHOT")
37+
})
38+
repositories {
39+
sonatype {
40+
stagingProfileId = properties.getProperty("sonatypeStagingProfileId", System.getenv('SONATYPE_STAGING_PROFILE_ID'))
41+
username = properties.getProperty("ossrhUsername", System.getenv('OSSRH_USERNAME'))
42+
password = properties.getProperty("ossrhPassword", System.getenv('OSSRH_PASSWORD'))
43+
version = VERSION_CODE
44+
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
45+
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
46+
}
47+
}
48+
}
49+
2550
// Replace these versions with the latest available versions of libkiwix and libzim
2651
ext.libkiwix_version = "12.0.0"
2752
ext.libzim_version = "8.2.0"

lib/publish.gradle

+2-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def siteUrl = 'https://www.kiwix.org/en/'
2222
def gitUrl = 'https://github.com/kiwix/libkiwix.git'
2323

2424
group = GROUP_ID
25-
version = VERSION
25+
version = VERSION_CODE
2626

2727
afterEvaluate {
2828
publishing {
@@ -31,7 +31,7 @@ afterEvaluate {
3131

3232
groupId GROUP_ID
3333
artifactId ARTIFACT_ID
34-
version VERSION
34+
version VERSION_CODE
3535

3636
from components.release
3737

@@ -61,15 +61,6 @@ afterEvaluate {
6161
}
6262
}
6363
}
64-
repositories {
65-
maven {
66-
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
67-
credentials {
68-
username = ossrhUsername
69-
password = ossrhPassword
70-
}
71-
}
72-
}
7364
}
7465
}
7566

0 commit comments

Comments
 (0)