From 5d8a712fd55a63b6d8778aad32af1583d5c5201a Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Fri, 14 Oct 2022 07:30:29 -0700 Subject: [PATCH] Configure CircleCI to publish artifacts to Maven Central (#34983) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/34983 This sets up our CircleCI logic to publish artifacts to Maven Central. I will check if tomorrow's nightly successfully landed on Maven Central Snapshot repository. I've added a --dry-run to the the close and release step of the publishing to avoid accidentally publishing to Maven Central. We'll remove this if we decide to go with the Maven Central publishing. Changelog: [Internal] [Changed] - Configure CircleCI to publish artifacts to Maven Central Reviewed By: jacdebug, huntie Differential Revision: D40377691 fbshipit-source-id: 36a74074ea95097bb7268352e40f4d2670f3cd65 --- .circleci/config.yml | 4 +++- scripts/publish-npm.js | 5 +++++ scripts/release-utils.js | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 150bf233f54..d54413cdf2d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1378,12 +1378,14 @@ jobs: - checkout - *attach_hermes_workspace - run: - name: Copy HermesC binaries + name: Copy Hermes binaries command: | mkdir -p ./sdks/hermesc ./sdks/hermesc/osx-bin ./sdks/hermesc/win64-bin ./sdks/hermesc/linux64-bin cp -r $HERMES_WS_DIR/osx-bin/* ./sdks/hermesc/osx-bin/. cp -r $HERMES_WS_DIR/win64-bin/* ./sdks/hermesc/win64-bin/. cp -r $HERMES_WS_DIR/linux64-bin/* ./sdks/hermesc/linux64-bin/. + mkdir -p ./ReactAndroid/external-artifacts/artifacts/ + cp $HERMES_WS_DIR/hermes-runtime-darwin/hermes-runtime-darwin-debug-*.tar.gz ./ReactAndroid/external-artifacts/artifacts/hermes-ios.tar.gz - run_yarn - download_gradle_dependencies diff --git a/scripts/publish-npm.js b/scripts/publish-npm.js index e57321dea70..5de46b96e16 100755 --- a/scripts/publish-npm.js +++ b/scripts/publish-npm.js @@ -40,6 +40,7 @@ const { } = require('./scm-utils'); const { generateAndroidArtifacts, + publishAndroidArtifactsToMaven, saveFilesToRestore, } = require('./release-utils'); const fs = require('fs'); @@ -196,6 +197,10 @@ const isLatest = exitIfNotOnGit( 'Not in git. We do not want to publish anything', ); +// We first publish on Maven Central all the necessary artifacts. +// NPM publishing is done just after. +publishAndroidArtifactsToMaven(nightlyBuild); + const releaseBranch = `${major}.${minor}-stable`; // Set the right tag for nightly and prerelease builds diff --git a/scripts/release-utils.js b/scripts/release-utils.js index e3ddd78dc94..879c05e1e80 100644 --- a/scripts/release-utils.js +++ b/scripts/release-utils.js @@ -76,7 +76,31 @@ function generateAndroidArtifacts(releaseVersion, tmpPublishingFolder) { }); } +function publishAndroidArtifactsToMaven(isNightly) { + // -------- Publish every artifact to Maven Central + if (exec('./gradlew publishAllToSonatype -PisNightly=' + isNightly).code) { + echo('Failed to publish artifacts to Sonatype (Maven Central)'); + exit(1); + } + + if (!isNightly) { + // -------- For stable releases, we also need to close and release the staging repository. + // TODO(ncor): Remove the --dry-run before RC0 + if ( + exec('./gradlew closeAndReleaseSonatypeStagingRepository --dry-run').code + ) { + echo( + 'Failed to close and release the staging repository on Sonatype (Maven Central)', + ); + exit(1); + } + } + + echo('Published artifacts to Maven Central'); +} + module.exports = { generateAndroidArtifacts, + publishAndroidArtifactsToMaven, saveFilesToRestore, };