Skip to content

Commit 8b8a05a

Browse files
Improved snapshot uploading to maven.
* We have added the `SNAPSHOT` env variable in publish_snapshot.yml and match it our code if found then it means this workflow trigged to publish the snapshot on maven so on behalf of this we have rectify our code.
1 parent 774d570 commit 8b8a05a

File tree

4 files changed

+30
-33
lines changed

4 files changed

+30
-33
lines changed

.github/workflows/publish_snapshot.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,22 @@ jobs:
2929
run: |
3030
./gradlew buildHeaders build
3131
32+
- name: Release build
33+
run: |
34+
./gradlew assemble
35+
3236
- name: Generate Source jar
3337
run: |
3438
./gradlew androidSourcesJar
3539
3640
- name: Publish Snapshot to MavenCentral
37-
run: ./gradlew publishToSonatype --info
41+
run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
3842
env:
3943
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
4044
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
4145
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
4246
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
4347
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
48+
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
49+
SNAPSHOT: true
4450

build.gradle

Lines changed: 0 additions & 17 deletions
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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,34 @@ 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+
repositories {
35+
sonatype {
36+
stagingProfileId = properties.getProperty("sonatypeStagingProfileId", System.getenv('SONATYPE_STAGING_PROFILE_ID'))
37+
username = properties.getProperty("ossrhUsername", System.getenv('OSSRH_USERNAME'))
38+
password = properties.getProperty("ossrhPassword", System.getenv('OSSRH_PASSWORD'))
39+
version = VERSION_CODE
40+
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
41+
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
42+
}
43+
}
44+
}
45+
2546
// Replace these versions with the latest available versions of libkiwix and libzim
2647
ext.libkiwix_version = "12.0.0"
2748
ext.libzim_version = "8.2.0"

lib/publish.gradle

Lines changed: 2 additions & 15 deletions
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,19 +61,6 @@ afterEvaluate {
6161
}
6262
}
6363
}
64-
repositories {
65-
maven {
66-
if (VERSION.endsWith('-SNAPSHOT')) {
67-
url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
68-
} else {
69-
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
70-
}
71-
credentials {
72-
username = ossrhUsername
73-
password = ossrhPassword
74-
}
75-
}
76-
}
7764
}
7865
}
7966

0 commit comments

Comments
 (0)