Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(android): mavencentral publishing and CI (#4961)
- Loading branch information
Showing
7 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
apply plugin: 'maven-publish' | ||
apply plugin: 'signing' | ||
|
||
def LIB_VERSION = System.getenv('CAP_VERSION') | ||
|
||
task androidSourcesJar(type: Jar) { | ||
archiveClassifier.set('sources') | ||
if (project.plugins.findPlugin("com.android.library")) { | ||
from android.sourceSets.main.java.srcDirs | ||
} else { | ||
from sourceSets.main.java.srcDirs | ||
} | ||
} | ||
|
||
artifacts { | ||
archives androidSourcesJar | ||
} | ||
|
||
group = 'com.capacitorjs' | ||
version = LIB_VERSION | ||
|
||
afterEvaluate { | ||
publishing { | ||
publications { | ||
release(MavenPublication) { | ||
// Coordinates | ||
groupId 'com.capacitorjs' | ||
artifactId 'core' | ||
version LIB_VERSION | ||
|
||
// Two artifacts, the `aar` (or `jar`) and the sources | ||
if (project.plugins.findPlugin("com.android.library")) { | ||
from components.release | ||
} else { | ||
artifact("$buildDir/libs/${project.getName()}-${version}.jar") | ||
} | ||
|
||
artifact androidSourcesJar | ||
|
||
// POM Data | ||
pom { | ||
name = 'core' | ||
description = 'Capacitor Android Core Native Library' | ||
url = 'https://github.com/ionic-team/capacitor' | ||
licenses { | ||
license { | ||
name = 'MIT' | ||
url = 'https://github.com/ionic-team/capacitor/blob/main/LICENSE' | ||
} | ||
} | ||
developers { | ||
developer { | ||
name = 'Ionic' | ||
email = 'hi@ionic.io' | ||
} | ||
} | ||
|
||
// Version Control Info | ||
scm { | ||
connection = 'scm:git:github.com:ionic-team/capacitor.git' | ||
developerConnection = 'scm:git:ssh://github.com:ionic-team/capacitor.git' | ||
url = 'https://github.com/ionic-team/capacitor/tree/main' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
signing { | ||
useInMemoryPgpKeys( | ||
rootProject.ext["signing.keyId"], | ||
rootProject.ext["signing.key"], | ||
rootProject.ext["signing.password"], | ||
) | ||
sign publishing.publications | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Create variables with empty default values | ||
ext["signing.keyId"] = '' | ||
ext["signing.key"] = '' | ||
ext["signing.password"] = '' | ||
ext["ossrhUsername"] = '' | ||
ext["ossrhPassword"] = '' | ||
ext["sonatypeStagingProfileId"] = '' | ||
|
||
File secretPropsFile = file('../local.properties') | ||
if (secretPropsFile.exists()) { | ||
// Read local.properties file first if it exists | ||
Properties p = new Properties() | ||
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) } | ||
p.each { name, value -> ext[name] = value } | ||
} else { | ||
// Use system environment variables | ||
ext["ossrhUsername"] = System.getenv('ANDROID_OSSRH_USERNAME') | ||
ext["ossrhPassword"] = System.getenv('ANDROID_OSSRH_PASSWORD') | ||
ext["sonatypeStagingProfileId"] = System.getenv('ANDROID_SONATYPE_STAGING_PROFILE_ID') | ||
ext["signing.keyId"] = System.getenv('ANDROID_SIGNING_KEY_ID') | ||
ext["signing.key"] = System.getenv('ANDROID_SIGNING_KEY') | ||
ext["signing.password"] = System.getenv('ANDROID_SIGNING_PASSWORD') | ||
} | ||
|
||
// Set up Sonatype repository | ||
nexusPublishing { | ||
repositories { | ||
sonatype { | ||
stagingProfileId = sonatypeStagingProfileId | ||
username = ossrhUsername | ||
password = ossrhPassword | ||
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) | ||
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) | ||
} | ||
} | ||
repositoryDescription = 'Capacitor Android Core v' + System.getenv('CAP_VERSION') | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env bash | ||
|
||
DIR=../android | ||
LOG_OUTPUT=./tmp/capacitor-android.txt | ||
CAP_VERSION=`grep '"version": ' $DIR/package.json | awk '{print $2}' | tr -d '",'` | ||
echo Attempting to build and publish Capacitor native libraries with version $CAP_VERSION | ||
|
||
# Make log dir if doesnt exist | ||
mkdir -p ./tmp | ||
|
||
# Export ENV variable used by Gradle for Versioning | ||
export CAP_VERSION | ||
|
||
# Get latest com.capacitorjs:core XML version info | ||
CAPACITOR_PUBLISHED_URL="https://repo1.maven.org/maven2/com/capacitorjs/core/maven-metadata.xml" | ||
CAPACITOR_PUBLISHED_DATA=$(curl -s $CAPACITOR_PUBLISHED_URL) | ||
CAPACITOR_PUBLISHED_VERSION="$(perl -ne 'print and last if s/.*<latest>(.*)<\/latest>.*/\1/;' <<< $CAPACITOR_PUBLISHED_DATA)" | ||
|
||
# Check if we need to publish a new native version of the Capacitor Android library | ||
if [[ $CAP_VERSION == $CAPACITOR_PUBLISHED_VERSION ]]; then | ||
printf %"s\n" "Native Capacitor Android library version $CAPACITOR_PUBLISHED_VERSION is already published on MavenCentral, skipping." | ||
else | ||
printf %"s\n" "Latest native Capacitor Android library is version $CAPACITOR_PUBLISHED_VERSION, publishing to MavenCentral staging..." | ||
|
||
# Build and publish | ||
$DIR/gradlew clean build publishReleasePublicationToSonatypeRepository --max-workers 1 -b $DIR/capacitor/build.gradle -Pandroid.useAndroidX=true -Pandroid.enableJetifier=true > $LOG_OUTPUT 2>&1 | ||
|
||
echo $RESULT | ||
|
||
if grep --quiet "BUILD SUCCESSFUL" $LOG_OUTPUT; then | ||
printf %"s\n" "Success: Capacitor Android Library published to MavenCentral Staging. Manually review and release from the Sonatype Repository Manager https://s01.oss.sonatype.org/" | ||
else | ||
printf %"s\n" "Error publishing, check $LOG_OUTPUT for more info!" | ||
cat $LOG_OUTPUT | ||
exit 1 | ||
fi | ||
fi |