mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: This PR backport two fixes we did in 0.71 to unblock the release process: * the change in `publish-npm` is needed because of the introduction of .strict() from https://github.com/facebook/react-native/commit/4f3ca8facfc41f27169c49ad8b3a28d3022d5f0a * the removal of the other script (added originally here https://github.com/facebook/react-native/commit/e4b5d3eec9bae44c46795c4be097b31cb48593ae) is because: 1) that step is not needed anymore (we don't publish/upload hermes artifacts to the GH release) 2) by the time this job gets run the release crew has already setup the GH release 3) the logic for the versioning was broken and even on the 0.71-rc pipeline it was tagging stuff as 1000.0.0 ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [Internal] [Fixed] - Fix release scripts for "release" pipeline scenario Pull Request resolved: https://github.com/facebook/react-native/pull/35258 Test Plan: The fact that 0.71-rc0 was released is the ✅ for this. Reviewed By: jacdebug Differential Revision: D41120888 Pulled By: cipolleschi fbshipit-source-id: 06d108f0659ad1db53c6324fe1d735f52c34a3c5
176 lines
4.8 KiB
JavaScript
Executable File
176 lines
4.8 KiB
JavaScript
Executable File
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
/**
|
|
* This script prepares a release version of react-native and may publish to NPM.
|
|
* It is supposed to run in CI environment, not on a developer's machine.
|
|
*
|
|
* For a dry run (commitly), this script will:
|
|
* * Version the commitly of the form `1000.0.0-<commitSha>`
|
|
* * Create Android artifacts
|
|
* * It will not publish to npm
|
|
*
|
|
* For a nightly run, this script will:
|
|
* * Version the nightly release of the form `0.0.0-<dateIdentifier>-<commitSha>`
|
|
* * Create Android artifacts
|
|
* * Publish to npm using `nightly` tag
|
|
*
|
|
* For a release run, this script will:
|
|
* * Version the release by the tag version that triggered CI
|
|
* * Create Android artifacts
|
|
* * Publish to npm
|
|
* * using `latest` tag if commit is currently tagged `latest`
|
|
* * or otherwise `{major}.{minor}-stable`
|
|
*/
|
|
|
|
const {exec, echo, exit} = require('shelljs');
|
|
const {parseVersion} = require('./version-utils');
|
|
const {
|
|
exitIfNotOnGit,
|
|
getCurrentCommit,
|
|
isTaggedLatest,
|
|
} = require('./scm-utils');
|
|
const {
|
|
generateAndroidArtifacts,
|
|
publishAndroidArtifactsToMaven,
|
|
} = require('./release-utils');
|
|
const fs = require('fs');
|
|
const os = require('os');
|
|
const path = require('path');
|
|
const yargs = require('yargs');
|
|
|
|
const buildTag = process.env.CIRCLE_TAG;
|
|
const otp = process.env.NPM_CONFIG_OTP;
|
|
const tmpPublishingFolder = fs.mkdtempSync(
|
|
path.join(os.tmpdir(), 'rn-publish-'),
|
|
);
|
|
|
|
const argv = yargs
|
|
.option('n', {
|
|
alias: 'nightly',
|
|
type: 'boolean',
|
|
default: false,
|
|
})
|
|
.option('d', {
|
|
alias: 'dry-run',
|
|
type: 'boolean',
|
|
default: false,
|
|
})
|
|
.option('r', {
|
|
alias: 'release', // useless but needed for CI
|
|
type: 'boolean',
|
|
default: false,
|
|
})
|
|
.strict().argv;
|
|
const nightlyBuild = argv.nightly;
|
|
const dryRunBuild = argv.dryRun;
|
|
const isCommitly = nightlyBuild || dryRunBuild;
|
|
|
|
if (!argv.help) {
|
|
echo(`The temp publishing folder is ${tmpPublishingFolder}`);
|
|
}
|
|
|
|
// 34c034298dc9cad5a4553964a5a324450fda0385
|
|
const currentCommit = getCurrentCommit();
|
|
const shortCommit = currentCommit.slice(0, 9);
|
|
|
|
const rawVersion =
|
|
// 0.0.0 triggers issues with cocoapods for codegen when building template project.
|
|
dryRunBuild
|
|
? '1000.0.0'
|
|
: // For nightly we continue to use 0.0.0 for clarity for npm
|
|
nightlyBuild
|
|
? '0.0.0'
|
|
: // For pre-release and stable releases, we use the git tag of the version we're releasing (set in bump-oss-version)
|
|
buildTag;
|
|
|
|
let version,
|
|
major,
|
|
minor,
|
|
prerelease = null;
|
|
try {
|
|
({version, major, minor, prerelease} = parseVersion(rawVersion));
|
|
} catch (e) {
|
|
echo(e.message);
|
|
exit(1);
|
|
}
|
|
|
|
let releaseVersion;
|
|
if (dryRunBuild) {
|
|
releaseVersion = `${version}-${shortCommit}`;
|
|
} else if (nightlyBuild) {
|
|
// 2021-09-28T05:38:40.669Z -> 20210928-0538
|
|
const dateIdentifier = new Date()
|
|
.toISOString()
|
|
.slice(0, -8)
|
|
.replace(/[-:]/g, '')
|
|
.replace(/[T]/g, '-');
|
|
releaseVersion = `${version}-${dateIdentifier}-${shortCommit}`;
|
|
} else {
|
|
releaseVersion = version;
|
|
}
|
|
|
|
// Bump version number in various files (package.json, gradle.properties etc)
|
|
// For stable, pre-release releases, we rely on CircleCI job `prepare_package_for_release` to handle this
|
|
if (isCommitly) {
|
|
if (
|
|
exec(`node scripts/set-rn-version.js --to-version ${releaseVersion}`).code
|
|
) {
|
|
echo(`Failed to set version number to ${releaseVersion}`);
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
generateAndroidArtifacts(releaseVersion, tmpPublishingFolder);
|
|
|
|
// Write version number to the build folder
|
|
const releaseVersionFile = path.join('build', '.version');
|
|
fs.writeFileSync(releaseVersionFile, releaseVersion);
|
|
|
|
if (dryRunBuild) {
|
|
echo('Skipping `npm publish` because --dry-run is set.');
|
|
exit(0);
|
|
}
|
|
|
|
// Running to see if this commit has been git tagged as `latest`
|
|
const isLatest = exitIfNotOnGit(
|
|
() => isTaggedLatest(currentCommit),
|
|
'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(releaseVersion, nightlyBuild);
|
|
|
|
const releaseBranch = `${major}.${minor}-stable`;
|
|
|
|
// Set the right tag for nightly and prerelease builds
|
|
// If a release is not git-tagged as `latest` we use `releaseBranch` to prevent
|
|
// npm from overriding the current `latest` version tag, which it will do if no tag is set.
|
|
const tagFlag = nightlyBuild
|
|
? '--tag nightly'
|
|
: prerelease != null
|
|
? '--tag next'
|
|
: isLatest
|
|
? '--tag latest'
|
|
: `--tag ${releaseBranch}`;
|
|
|
|
// use otp from envvars if available
|
|
const otpFlag = otp ? `--otp ${otp}` : '';
|
|
|
|
if (exec(`npm publish ${tagFlag} ${otpFlag}`).code) {
|
|
echo('Failed to publish package to npm');
|
|
exit(1);
|
|
} else {
|
|
echo(`Published to npm ${releaseVersion}`);
|
|
exit(0);
|
|
}
|