From e6618bf00badbc6253b0f34a6a1e7a68281c2bd5 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Fri, 14 Oct 2022 04:42:43 -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 Differential Revision: D40377691 fbshipit-source-id: 0dacfc44f02ef5e973675fc4bba079fe4f3fa596 --- .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 150bf233f541..d54413cdf2d5 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 e57321dea70d..5de46b96e165 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 e3ddd78dc949..879c05e1e809 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, };