mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
a52f5514ed
Summary: One of the steps we perform when doing a release is to run `npm view react-native` to verify that the release has been published and it is available with the right tag. As of today, we check this manually. This change aims at automating this check so that we don't have to do it manually ourselves. ## Changelog: [Internal] - Releases: automate the npm view check Pull Request resolved: https://github.com/facebook/react-native/pull/49164 Test Plan: Created a veriftyReleaseOnNPM-tests.js jest test to verify that the script works fine. <img width="667" alt="Screenshot 2025-02-04 at 15 18 24" src="https://github.com/user-attachments/assets/cf08155f-80da-4e15-a922-5c16f3fd806e" /> Reviewed By: cortinico Differential Revision: D69118622 Pulled By: cipolleschi fbshipit-source-id: a8d40cd2fcb164d8f7174de680b340510f3e8551
82 lines
2.0 KiB
JavaScript
82 lines
2.0 KiB
JavaScript
/**
|
|
* 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
|
|
*/
|
|
|
|
const {run, sleep, log, verifyPublishedPackage} = require('./utils.js');
|
|
|
|
const TAG_AS_LATEST_REGEX = /#publish-packages-to-npm&latest/;
|
|
|
|
/**
|
|
* Should this commit be `latest` on npm?
|
|
*/
|
|
function isLatest() {
|
|
const commitMessage = run('git log -n1 --pretty=%B');
|
|
return TAG_AS_LATEST_REGEX.test(commitMessage);
|
|
}
|
|
module.exports.isLatest = isLatest;
|
|
|
|
/**
|
|
* Create a Github Action to publish the community template matching the released version
|
|
* of React Native.
|
|
*/
|
|
module.exports.publishTemplate = async (github, version, dryRun = true) => {
|
|
log(`📤 Get the ${TEMPLATE_NPM_PKG} repo to publish ${version}`);
|
|
|
|
const is_latest_on_npm = isLatest();
|
|
|
|
const majorMinor = /^v?(\d+\.\d+)/.exec(version);
|
|
|
|
if (!majorMinor) {
|
|
log(`🔥 can't capture MAJOR.MINOR from '${version}', giving up.`);
|
|
process.exit(1);
|
|
}
|
|
|
|
// MAJOR.MINOR-stable
|
|
const ref = `${majorMinor[1]}-stable`;
|
|
|
|
await github.rest.actions.createWorkflowDispatch({
|
|
owner: 'react-native-community',
|
|
repo: 'template',
|
|
workflow_id: 'release.yaml',
|
|
ref,
|
|
inputs: {
|
|
dry_run: dryRun,
|
|
is_latest_on_npm,
|
|
// 0.75.0-rc.0, note no 'v' prefix
|
|
version: version.replace(/^v/, ''),
|
|
},
|
|
});
|
|
};
|
|
|
|
const MAX_RETRIES = 3 * 6; // 18 attempts. Waiting between attempt: 10 s. Total time: 3 mins.
|
|
const TEMPLATE_NPM_PKG = '@react-native-community/template';
|
|
|
|
/**
|
|
* Will verify that @latest and the @<version> have been published.
|
|
*
|
|
* NOTE: This will infinitely query each step until successful, make sure the
|
|
* calling job has a timeout.
|
|
*/
|
|
module.exports.verifyPublishedTemplate = async (
|
|
version,
|
|
latest = false,
|
|
retries = MAX_RETRIES,
|
|
) => {
|
|
try {
|
|
await verifyPublishedPackage(
|
|
TEMPLATE_NPM_PKG,
|
|
version,
|
|
latest ? 'latest' : null,
|
|
retries,
|
|
);
|
|
} catch (e) {
|
|
console.error(e.message);
|
|
process.exit(1);
|
|
}
|
|
};
|