File tree Expand file tree Collapse file tree 3 files changed +52
-1
lines changed Expand file tree Collapse file tree 3 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const {
11
11
parseVersion,
12
12
getNextVersionFromTags,
13
13
isTaggedLatest,
14
+ isTaggedVersion,
14
15
isReleaseBranch,
15
16
} = require ( '../version-utils' ) ;
16
17
@@ -24,6 +25,33 @@ jest.mock('shelljs', () => ({
24
25
} ) ) ;
25
26
26
27
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
+
27
55
describe ( 'isReleaseBranch' , ( ) => {
28
56
it ( 'should identify as release branch' , ( ) => {
29
57
expect ( isReleaseBranch ( 'v0.66-stable' ) ) . toBe ( true ) ;
Original file line number Diff line number Diff line change 11
11
12
12
/**
13
13
* This script prepares a release package to be pushed to npm
14
+ * It is run by CircleCI on a push to a release branch
14
15
* It will:
15
16
* * It updates the version in json/gradle files and makes sure they are consistent between each other (set-rn-version)
16
17
* * Updates podfile for RNTester
@@ -22,6 +23,7 @@ const yargs = require('yargs');
22
23
const {
23
24
isReleaseBranch,
24
25
isTaggedLatest,
26
+ isTaggedVersion,
25
27
getNextVersionFromTags,
26
28
} = require ( './version-utils' ) ;
27
29
@@ -33,6 +35,15 @@ const argv = yargs.option('r', {
33
35
default : 'origin' ,
34
36
} ) . argv ;
35
37
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
+
36
47
if ( ! isReleaseBranch ( branch ) ) {
37
48
console . error ( 'This needs to be on a release branch' ) ;
38
49
exit ( 1 ) ;
Original file line number Diff line number Diff line change 9
9
10
10
const { exec} = require ( 'shelljs' ) ;
11
11
12
+ const VERSION_REGEX = / ^ v ? ( ( \d + ) \. ( \d + ) \. ( \d + ) (?: - ( .+ ) ) ? ) $ / ;
13
+
12
14
function parseVersion ( versionStr ) {
13
- const match = versionStr . match ( / ^ v ? ( ( \d + ) \. ( \d + ) \. ( \d + ) (?: - ( . + ) ) ? ) $ / ) ;
15
+ const match = versionStr . match ( VERSION_REGEX ) ;
14
16
if ( ! match ) {
15
17
throw new Error (
16
18
`You must pass a correctly formatted version; couldn't parse ${ versionStr } ` ,
@@ -72,6 +74,15 @@ function isReleaseBranch(branch) {
72
74
return branch . endsWith ( '-stable' ) ;
73
75
}
74
76
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
+
75
86
function isTaggedLatest ( commitSha ) {
76
87
return (
77
88
exec ( `git rev-list -1 latest | grep ${ commitSha } ` , {
@@ -82,6 +93,7 @@ function isTaggedLatest(commitSha) {
82
93
83
94
module . exports = {
84
95
isTaggedLatest,
96
+ isTaggedVersion,
85
97
parseVersion,
86
98
getNextVersionFromTags,
87
99
isReleaseBranch,
You can’t perform that action at this time.
0 commit comments