Skip to content

Commit 1c73abb

Browse files
author
Luna Wei
committed
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
1 parent 43eaf3c commit 1c73abb

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

scripts/__tests__/version-utils-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
parseVersion,
1212
getNextVersionFromTags,
1313
isTaggedLatest,
14+
isTaggedVersion,
1415
isReleaseBranch,
1516
} = require('../version-utils');
1617

@@ -24,6 +25,33 @@ jest.mock('shelljs', () => ({
2425
}));
2526

2627
describe('version-utils', () => {
28+
describe('isTaggedVersion', () => {
29+
it('should return true on pre-release versions', () => {
30+
execResult = 'v0.66.0-rc.3\nlatest\n\n';
31+
expect(isTaggedVersion('6c19dc3266b84f47a076b647a1c93b3c3b69d2c5')).toBe(
32+
true,
33+
);
34+
});
35+
it('should return true on release versions', () => {
36+
execResult = 'latest\nv0.66.2\n\n';
37+
expect(isTaggedVersion('6c19dc3266b84f47a076b647a1c93b3c3b69d2c5')).toBe(
38+
true,
39+
);
40+
});
41+
it('should return false when no tags', () => {
42+
execResult = '\n';
43+
expect(isTaggedVersion('6c19dc3266b84f47a076b647a1c93b3c3b69d2c5')).toBe(
44+
false,
45+
);
46+
});
47+
it('should return false on tags that are not versions', () => {
48+
execResult = 'latest\n0.someother-made-up-tag\n\n';
49+
expect(isTaggedVersion('6c19dc3266b84f47a076b647a1c93b3c3b69d2c5')).toBe(
50+
false,
51+
);
52+
});
53+
});
54+
2755
describe('isReleaseBranch', () => {
2856
it('should identify as release branch', () => {
2957
expect(isReleaseBranch('v0.66-stable')).toBe(true);

scripts/prepare-package-for-release.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
/**
1313
* This script prepares a release package to be pushed to npm
14+
* It is run by CircleCI on a push to a release branch
1415
* It will:
1516
* * It updates the version in json/gradle files and makes sure they are consistent between each other (set-rn-version)
1617
* * Updates podfile for RNTester
@@ -22,6 +23,7 @@ const yargs = require('yargs');
2223
const {
2324
isReleaseBranch,
2425
isTaggedLatest,
26+
isTaggedVersion,
2527
getNextVersionFromTags,
2628
} = require('./version-utils');
2729

@@ -33,6 +35,15 @@ const argv = yargs.option('r', {
3335
default: 'origin',
3436
}).argv;
3537

38+
// We do this check to prevent a loop of commit in this script to trigger the job again.
39+
// I haven't figured out a way for CircleCI to filter out commits from CircleCI jobs
40+
if (isTaggedVersion(currentCommit)) {
41+
console.log(
42+
'Skip running prepare-package-for-release as this job was triggered from previous run of this script.',
43+
);
44+
exit(0);
45+
}
46+
3647
if (!isReleaseBranch(branch)) {
3748
console.error('This needs to be on a release branch');
3849
exit(1);

scripts/version-utils.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
const {exec} = require('shelljs');
1111

12+
const VERSION_REGEX = /^v?((\d+)\.(\d+)\.(\d+)(?:-(.+))?)$/;
13+
1214
function parseVersion(versionStr) {
13-
const match = versionStr.match(/^v?((\d+)\.(\d+)\.(\d+)(?:-(.+))?)$/);
15+
const match = versionStr.match(VERSION_REGEX);
1416
if (!match) {
1517
throw new Error(
1618
`You must pass a correctly formatted version; couldn't parse ${versionStr}`,
@@ -72,6 +74,15 @@ function isReleaseBranch(branch) {
7274
return branch.endsWith('-stable');
7375
}
7476

77+
function isTaggedVersion(commitSha) {
78+
const tags = exec(`git tag --points-at ${commitSha}`, {
79+
silent: true,
80+
})
81+
.stdout.trim()
82+
.split('\n');
83+
return tags.some(tag => !!tag.match(VERSION_REGEX));
84+
}
85+
7586
function isTaggedLatest(commitSha) {
7687
return (
7788
exec(`git rev-list -1 latest | grep ${commitSha}`, {
@@ -82,6 +93,7 @@ function isTaggedLatest(commitSha) {
8293

8394
module.exports = {
8495
isTaggedLatest,
96+
isTaggedVersion,
8597
parseVersion,
8698
getNextVersionFromTags,
8799
isReleaseBranch,

0 commit comments

Comments
 (0)