From 835e9d0efb3361748e5cc2550de4ea72794ded23 Mon Sep 17 00:00:00 2001 From: karthiccc23 Date: Fri, 31 May 2024 13:22:19 -0700 Subject: [PATCH] Update maven publishing --- .github/workflows/release-aar.yaml | 31 +++++++++++++++++ build.gradle.kts | 13 +++++--- .../react-native/ReactAndroid/build.gradle | 2 +- .../ReactAndroid/gradle.properties | 21 ++++++++++++ .../ReactAndroid/hermes-engine/build.gradle | 2 +- .../hermes-engine/gradle.properties | 1 + .../react-native/ReactAndroid/publish.gradle | 33 +++++++++++++------ 7 files changed, 87 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/release-aar.yaml diff --git a/.github/workflows/release-aar.yaml b/.github/workflows/release-aar.yaml new file mode 100644 index 00000000000000..d4f48bfd192738 --- /dev/null +++ b/.github/workflows/release-aar.yaml @@ -0,0 +1,31 @@ +name: Release React Native AAR +# This workflow is manually triggered to release a new React Native AAR version +on: + workflow_dispatch: + +jobs: + release-aar: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Publish Maven Artifact + run: | + cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import + gpg --list-secret-keys --keyid-format LONG + yarn install + echo "signing.gnupg.keyName=${OSSRH_GPG_SECRET_KEY_ID}" >> gradle.properties + echo "signing.gnupg.passphrase=${OSSRH_GPG_SECRET_KEY_PASSWORD}" >> gradle.properties + echo "repositoryUsername=${OSSRH_SONATYPE_USERNAME}" >> gradle.properties + echo "repositoryPassword=${OSSRH_SONATYPE_PASSWORD}" >> gradle.properties + echo "signingKey=${OSSRH_GPG_SECRET_KEY}" >> gradle.properties + echo "signingPassword=${OSSRH_GPG_SECRET_KEY_PASSWORD}" >> gradle.properties + sed -i.bu 's/com.facebook.react/com.walmartlabs.ern/g' packages/react-native/ReactAndroid/gradle.properties + sed -i.bu 's/com.facebook.react/com.walmartlabs.ern/g' packages/react-native/ReactAndroid/hermes-engine/gradle.properties + ./gradlew assembleRelease + ./gradlew publishAllPublicationsToErnRepository --stacktrace + env: + OSSRH_GPG_SECRET_KEY_ID: ${{ secrets.OSSRH_GPG_SECRET_KEY_ID }} + OSSRH_GPG_SECRET_KEY: ${{ secrets.OSSRH_GPG_SECRET_KEY }} + OSSRH_GPG_SECRET_KEY_PASSWORD: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} + OSSRH_SONATYPE_USERNAME: ${{ secrets.OSSRH_SONATYPE_USERNAME }} + OSSRH_SONATYPE_PASSWORD: ${{ secrets.OSSRH_SONATYPE_PASSWORD }} diff --git a/build.gradle.kts b/build.gradle.kts index 9ee10211d6141d..fbf646b72b6368 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,8 +31,8 @@ group = "com.facebook.react" val ndkPath by extra(System.getenv("ANDROID_NDK")) val ndkVersion by extra(System.getenv("ANDROID_NDK_VERSION")) -val sonatypeUsername = findProperty("SONATYPE_USERNAME")?.toString() -val sonatypePassword = findProperty("SONATYPE_PASSWORD")?.toString() +val sonatypeUsername = findProperty("repositoryUsername")?.toString() +val sonatypePassword = findProperty("repositoryPassword")?.toString() nexusPublishing { repositories { @@ -99,9 +99,14 @@ tasks.register("publishAllToMavenTempLocal") { ":packages:react-native:ReactAndroid:hermes-engine:publishAllPublicationsToMavenTempLocalRepository") } +tasks.register("publishAllPublicationsToErnRepository") { + description = "Publish all the artifacts to be available inside a Maven Local repository on /tmp." + dependsOn(":packages:react-native:ReactAndroid:publishAllPublicationsToErnRepository") + dependsOn( + ":packages:react-native:ReactAndroid:hermes-engine:publishAllPublicationsToErnRepository") +} + tasks.register("publishAllToSonatype") { description = "Publish all the artifacts to Sonatype (Maven Central or Snapshot repository)" dependsOn(":packages:react-native:ReactAndroid:publishToSonatype") - dependsOn(":packages:react-native:ReactAndroid:external-artifacts:publishToSonatype") - dependsOn(":packages:react-native:ReactAndroid:hermes-engine:publishToSonatype") } diff --git a/packages/react-native/ReactAndroid/build.gradle b/packages/react-native/ReactAndroid/build.gradle index c2b76ed511e027..c7f5d241a75657 100644 --- a/packages/react-native/ReactAndroid/build.gradle +++ b/packages/react-native/ReactAndroid/build.gradle @@ -23,7 +23,7 @@ import kotlin.Pair import de.undercouch.gradle.tasks.download.Download version = VERSION_NAME -group = "com.facebook.react" +group = GROUP // We download various C++ open-source dependencies into downloads. // We then copy both the downloaded code and our custom makefiles and headers into third-party-ndk. diff --git a/packages/react-native/ReactAndroid/gradle.properties b/packages/react-native/ReactAndroid/gradle.properties index ec7d486e5b2f39..45d0ec9a3e9bd4 100644 --- a/packages/react-native/ReactAndroid/gradle.properties +++ b/packages/react-native/ReactAndroid/gradle.properties @@ -30,5 +30,26 @@ FOLLY_VERSION=2021.07.22.00 GLOG_VERSION=0.3.5 LIBEVENT_VERSION=2.1.12 +# Electrode Native Sonatype Publish +POM_URL=https://github.com/facebook/react-native +POM_SCM_URL=https://github.com/facebook/react-native.git +POM_SCM_CONNECTION=scm:git:https://github.com/facebook/react-native.git +POM_SCM_DEV_CONNECTION=scm:git:git@github.com:facebook/react-native.git +POM_DESCRIPTION=A framework for building native apps with React + +POM_LICENCE_NAME=MIT License +POM_LICENCE_URL=https://github.com/facebook/react-native/blob/master/LICENSE +POM_LICENCE_DIST=repo + +POM_DEVELOPER_ID=facebook +POM_DEVELOPER_NAME=Facebook +POM_DEVELOPER_EMAIL=facebook@facebook.com + +SONATYPE_HOST=DEFAULT +RELEASE_SIGNING_ENABLED=true + +REPOSITORY_URL_MAVEN_STAGING_DEFAULT=https://oss.sonatype.org/service/local/staging/deploy/maven2/ +REPOSITORY_URL_MAVEN_SNAPSHOT_DEFAULT=https://oss.sonatype.org/content/repositories/snapshots/ + android.useAndroidX=true android.enableJetifier=true diff --git a/packages/react-native/ReactAndroid/hermes-engine/build.gradle b/packages/react-native/ReactAndroid/hermes-engine/build.gradle index 5ebaf48ce6ed1a..e30c5b574ea573 100644 --- a/packages/react-native/ReactAndroid/hermes-engine/build.gradle +++ b/packages/react-native/ReactAndroid/hermes-engine/build.gradle @@ -14,7 +14,7 @@ plugins { id("signing") } -group = "com.facebook.react" +group = GROUP version = parent.publishing_version def cmakeVersion = parent.cmake_version diff --git a/packages/react-native/ReactAndroid/hermes-engine/gradle.properties b/packages/react-native/ReactAndroid/hermes-engine/gradle.properties index 8b53deb7d709fe..d6e0d2e4dacfb5 100644 --- a/packages/react-native/ReactAndroid/hermes-engine/gradle.properties +++ b/packages/react-native/ReactAndroid/hermes-engine/gradle.properties @@ -1 +1,2 @@ +GROUP=com.facebook.react android.disableAutomaticComponentCreation=true diff --git a/packages/react-native/ReactAndroid/publish.gradle b/packages/react-native/ReactAndroid/publish.gradle index db2c83765c6688..bb37e4f357ade6 100644 --- a/packages/react-native/ReactAndroid/publish.gradle +++ b/packages/react-native/ReactAndroid/publish.gradle @@ -9,13 +9,22 @@ apply plugin: 'maven-publish' apply plugin: 'signing' def isNightly = findProperty("isNightly")?.toBoolean() -def signingKey = findProperty("SIGNING_KEY") -def signingPwd = findProperty("SIGNING_PWD") +def signingKey = findProperty("signingKey") +def signingPwd = findProperty("signingPassword") def reactAndroidProjectDir = project(':packages:react-native:ReactAndroid').projectDir def androidOutputUrl = "file://${reactAndroidProjectDir}/../android" def mavenTempLocalUrl = "file:///tmp/maven-local" +// ERN Publish to Maven Creds +def sonatypeUsername = findProperty("repositoryUsername") +def sonatypePassword = findProperty("repositoryPassword") +def ernMavenCentral = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + +def isReleaseBuild() { + return VERSION_NAME.contains("SNAPSHOT") == false +} + publishing { publications { release(MavenPublication) { @@ -73,15 +82,19 @@ publishing { name = "mavenTempLocal" url = mavenTempLocalUrl } + maven { + name = "ern" + url = ernMavenCentral + credentials { + username = sonatypeUsername + password = sonatypePassword + } + } } - if (signingKey && signingPwd) { - logger.info("PGP Key found - Signing enabled") - signing { - useInMemoryPgpKeys(signingKey, signingPwd) - sign(publishing.publications.release) - } - } else { - logger.info("Signing disabled as the PGP key was not found") + signing { + required { isReleaseBuild() } + useGpgCmd() + sign(publishing.publications.release) } }