isTaggedVersion checks if the commit has a version tag on it

Summary: Changelog: [Internal] Add a `isTaggedVersion` function to filter out commits from release automation.

Reviewed By: sota000

Differential Revision: D32842035

fbshipit-source-id: 14bb262a1d2a96ffda87c759a3202c4f9a356141
This commit is contained in:
Luna Wei 2021-12-03 13:15:38 -08:00 коммит произвёл Facebook GitHub Bot
Родитель badd30885f
Коммит 8cc80a843a
3 изменённых файлов: 52 добавлений и 1 удалений

Просмотреть файл

@ -11,6 +11,7 @@ const {
parseVersion,
getNextVersionFromTags,
isTaggedLatest,
isTaggedVersion,
isReleaseBranch,
} = require('../version-utils');
@ -24,6 +25,33 @@ jest.mock('shelljs', () => ({
}));
describe('version-utils', () => {
describe('isTaggedVersion', () => {
it('should return true on pre-release versions', () => {
execResult = 'v0.66.0-rc.3\nlatest\n\n';
expect(isTaggedVersion('6c19dc3266b84f47a076b647a1c93b3c3b69d2c5')).toBe(
true,
);
});
it('should return true on release versions', () => {
execResult = 'latest\nv0.66.2\n\n';
expect(isTaggedVersion('6c19dc3266b84f47a076b647a1c93b3c3b69d2c5')).toBe(
true,
);
});
it('should return false when no tags', () => {
execResult = '\n';
expect(isTaggedVersion('6c19dc3266b84f47a076b647a1c93b3c3b69d2c5')).toBe(
false,
);
});
it('should return false on tags that are not versions', () => {
execResult = 'latest\n0.someother-made-up-tag\n\n';
expect(isTaggedVersion('6c19dc3266b84f47a076b647a1c93b3c3b69d2c5')).toBe(
false,
);
});
});
describe('isReleaseBranch', () => {
it('should identify as release branch', () => {
expect(isReleaseBranch('v0.66-stable')).toBe(true);

Просмотреть файл

@ -11,6 +11,7 @@
/**
* This script prepares a release package to be pushed to npm
* It is run by CircleCI on a push to a release branch
* 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
@ -22,6 +23,7 @@ const yargs = require('yargs');
const {
isReleaseBranch,
isTaggedLatest,
isTaggedVersion,
getNextVersionFromTags,
} = require('./version-utils');
@ -33,6 +35,15 @@ const argv = yargs.option('r', {
default: 'origin',
}).argv;
// We do this check to prevent a loop of commit in this script to trigger the job again.
// I haven't figured out a way for CircleCI to filter out commits from CircleCI jobs
if (isTaggedVersion(currentCommit)) {
console.log(
'Skip running prepare-package-for-release as this job was triggered from previous run of this script.',
);
exit(0);
}
if (!isReleaseBranch(branch)) {
console.error('This needs to be on a release branch');
exit(1);

Просмотреть файл

@ -9,8 +9,10 @@
const {exec} = require('shelljs');
const VERSION_REGEX = /^v?((\d+)\.(\d+)\.(\d+)(?:-(.+))?)$/;
function parseVersion(versionStr) {
const match = versionStr.match(/^v?((\d+)\.(\d+)\.(\d+)(?:-(.+))?)$/);
const match = versionStr.match(VERSION_REGEX);
if (!match) {
throw new Error(
`You must pass a correctly formatted version; couldn't parse ${versionStr}`,
@ -72,6 +74,15 @@ function isReleaseBranch(branch) {
return branch.endsWith('-stable');
}
function isTaggedVersion(commitSha) {
const tags = exec(`git tag --points-at ${commitSha}`, {
silent: true,
})
.stdout.trim()
.split('\n');
return tags.some(tag => !!tag.match(VERSION_REGEX));
}
function isTaggedLatest(commitSha) {
return (
exec(`git rev-list -1 latest | grep ${commitSha}`, {
@ -82,6 +93,7 @@ function isTaggedLatest(commitSha) {
module.exports = {
isTaggedLatest,
isTaggedVersion,
parseVersion,
getNextVersionFromTags,
isReleaseBranch,