Extract logic from bump-oss-version specific to prod releases
Summary: Changelog: [Internal] - Extract logic from bump-oss-version specific to prod releases This work is part of an effort to automate the release process by using a push to a release branch as a trigger to prepare, package and deploy react-native to npm from CircleCI The following diagram describes the context (what kind of releases we do, relevant scripts and what they do), the pre-existing process for the different types of release and how I've modified the process. {F683387103} This diff creates the `prepare-package-for-release` script referenced by extracting it out of `bump-oss-version` and leveraging `set-rn-version`. It adds some helper functions to `version-utils` with tests Reviewed By: sota000 Differential Revision: D32556610 fbshipit-source-id: eb4ddc787498744156f985ab6d205c5d160e279b
This commit is contained in:
Родитель
ea6e34da77
Коммит
f4314c2b44
|
@ -7,7 +7,12 @@
|
||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const {parseVersion, getNextVersionFromTags} = require('../version-utils');
|
const {
|
||||||
|
parseVersion,
|
||||||
|
getNextVersionFromTags,
|
||||||
|
isTaggedLatest,
|
||||||
|
isReleaseBranch,
|
||||||
|
} = require('../version-utils');
|
||||||
|
|
||||||
let execResult = null;
|
let execResult = null;
|
||||||
jest.mock('shelljs', () => ({
|
jest.mock('shelljs', () => ({
|
||||||
|
@ -19,6 +24,30 @@ jest.mock('shelljs', () => ({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('version-utils', () => {
|
describe('version-utils', () => {
|
||||||
|
describe('isReleaseBranch', () => {
|
||||||
|
it('should identify as release branch', () => {
|
||||||
|
expect(isReleaseBranch('v0.66-stable')).toBe(true);
|
||||||
|
expect(isReleaseBranch('0.66-stable')).toBe(true);
|
||||||
|
expect(isReleaseBranch('made-up-stuff-stable')).toBe(true);
|
||||||
|
});
|
||||||
|
it('should not identify as release branch', () => {
|
||||||
|
expect(isReleaseBranch('main')).toBe(false);
|
||||||
|
expect(isReleaseBranch('pull/32659')).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('isTaggedLatest', () => {
|
||||||
|
it('it should identify commit as tagged `latest`', () => {
|
||||||
|
execResult = '6c19dc3266b84f47a076b647a1c93b3c3b69d2c5\n';
|
||||||
|
expect(isTaggedLatest('6c19dc3266b84f47a076b647a1c93b3c3b69d2c5')).toBe(
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('it should not identify commit as tagged `latest`', () => {
|
||||||
|
execResult = '6c19dc3266b84f47a076b647a1c93b3c3b69d2c5\n';
|
||||||
|
expect(isTaggedLatest('6c19dc3266b8')).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('getNextVersionFromTags', () => {
|
describe('getNextVersionFromTags', () => {
|
||||||
it('should increment last stable tag', () => {
|
it('should increment last stable tag', () => {
|
||||||
execResult =
|
execResult =
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) Facebook, Inc. and its 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 package to be pushed to npm
|
||||||
|
* It will:
|
||||||
|
* * It updates the version in json/gradle files and makes sure they are consistent between each other (set-rn-version)
|
||||||
|
* * Updates podfile for RNTester
|
||||||
|
* * Commits changes and tags with the next version based off of last version tag.
|
||||||
|
* This in turn will trigger another CircleCI job to publish to npm
|
||||||
|
*/
|
||||||
|
const {echo, exec, exit} = require('shelljs');
|
||||||
|
const yargs = require('yargs');
|
||||||
|
const {
|
||||||
|
isReleaseBranch,
|
||||||
|
isTaggedLatest,
|
||||||
|
getNextVersionFromTags,
|
||||||
|
} = require('./version-utils');
|
||||||
|
|
||||||
|
const branch = process.env.CIRCLE_BRANCH;
|
||||||
|
const currentCommit = process.env.CIRCLE_SHA1;
|
||||||
|
|
||||||
|
const argv = yargs.option('r', {
|
||||||
|
alias: 'remote',
|
||||||
|
default: 'origin',
|
||||||
|
}).argv;
|
||||||
|
|
||||||
|
if (!isReleaseBranch(branch)) {
|
||||||
|
console.error('This needs to be on a release branch');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Progress the version by 1 using existing git tags
|
||||||
|
const {version} = getNextVersionFromTags(branch);
|
||||||
|
|
||||||
|
if (exec(`node scripts/set-rn-version.js --to-version ${version}`).code) {
|
||||||
|
echo(`Failed to set React Native version to ${version}`);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release builds should commit the version bumps, and create tags.
|
||||||
|
echo('Updating RNTester Podfile.lock...');
|
||||||
|
if (exec('source scripts/update_podfile_lock.sh && update_pods').code) {
|
||||||
|
echo('Failed to update RNTester Podfile.lock.');
|
||||||
|
echo('Fix the issue, revert and try again.');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if this release has been tagged as latest
|
||||||
|
const isLatest = isTaggedLatest(currentCommit);
|
||||||
|
|
||||||
|
// Make commit [0.21.0-rc] Bump version numbers
|
||||||
|
if (exec(`git commit -a -m "[${version}] Bump version numbers"`).code) {
|
||||||
|
echo('failed to commit');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since we just committed, if `isLatest`, move the tag to commit we just made
|
||||||
|
// This tag will also update npm release as `latest`
|
||||||
|
if (isLatest) {
|
||||||
|
exec('git tag -d latest');
|
||||||
|
exec(`git push ${remote} :latest`);
|
||||||
|
exec('git tag latest');
|
||||||
|
exec(`git push ${remote} latest`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add tag v0.21.0-rc.1
|
||||||
|
if (exec(`git tag v${version}`).code) {
|
||||||
|
echo(
|
||||||
|
`failed to tag the commit with v${version}, are you sure this release wasn't made earlier?`,
|
||||||
|
);
|
||||||
|
echo('You may want to rollback the last commit');
|
||||||
|
echo('git reset --hard HEAD~1');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push newly created tag
|
||||||
|
let remote = argv.remote;
|
||||||
|
exec(`git push ${remote} v${version}`);
|
||||||
|
|
||||||
|
exec(`git push ${remote} ${branch} --follow-tags`);
|
||||||
|
|
||||||
|
exit(0);
|
|
@ -68,7 +68,21 @@ function getNextVersionFromTags(branch) {
|
||||||
return `${major}.${minor}.${parseInt(patch, 10) + 1}`;
|
return `${major}.${minor}.${parseInt(patch, 10) + 1}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isReleaseBranch(branch) {
|
||||||
|
return branch.endsWith('-stable');
|
||||||
|
}
|
||||||
|
|
||||||
|
function isTaggedLatest(commitSha) {
|
||||||
|
return (
|
||||||
|
exec(`git rev-list -1 latest | grep ${commitSha}`, {
|
||||||
|
silent: true,
|
||||||
|
}).stdout.trim() === commitSha
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
isTaggedLatest,
|
||||||
parseVersion,
|
parseVersion,
|
||||||
getNextVersionFromTags,
|
getNextVersionFromTags,
|
||||||
|
isReleaseBranch,
|
||||||
};
|
};
|
||||||
|
|
Загрузка…
Ссылка в новой задаче