@@ -6,16 +6,19 @@ const exec = require('shell-utils').exec;
66const cp = require ( 'child_process' ) ;
77
88let IS_SNAPSHOT ;
9+ let IS_HOTFIX ;
910const isReleaseBuild = process . env . BUILDKITE_MESSAGE . match ( / ^ r e l e a s e $ / i) ;
1011const isPRBuild = process . env . BUILDKITE_PULL_REQUEST === 'true' ;
1112
1213if ( isReleaseBuild ) {
1314 IS_SNAPSHOT = cp . execSync ( `buildkite-agent meta-data get is-snapshot` ) . toString ( ) ;
15+ IS_HOTFIX = cp . execSync ( `buildkite-agent meta-data get is-hotfix` ) . toString ( ) ;
1416}
1517const ONLY_ON_BRANCH = 'release' ;
1618const isSnapshotBuild = ( ! isPRBuild && ! isReleaseBuild ) || IS_SNAPSHOT === 'true' ;
1719const VERSION_TAG = isSnapshotBuild ? 'snapshot' : 'latest' ;
18- const VERSION_INC = 'minor' ;
20+ const isHotFixBuild = ! isPRBuild && isReleaseBuild && IS_HOTFIX === 'true' ;
21+ const VERSION_INC = isHotFixBuild ? 'patch' : 'minor' ;
1922
2023function run ( ) {
2124 if ( ! validateEnv ( ) ) {
@@ -72,6 +75,7 @@ function versionTagAndPublish() {
7275 version = semver . gt ( packageVersion , currentPublished ) ? packageVersion : semver . inc ( currentPublished , VERSION_INC ) ;
7376 }
7477
78+ console . log ( `Publishing version: ${ version } ` ) ;
7579 tryPublishAndTag ( version ) ;
7680}
7781
@@ -84,27 +88,29 @@ function tryPublishAndTag(version) {
8488 for ( let retry = 0 ; retry < 5 ; retry ++ ) {
8589 try {
8690 tagAndPublish ( theCandidate ) ;
87- console . log ( `Released ${ theCandidate } ` ) ;
91+ console . log ( `Released version ${ theCandidate } ` ) ;
8892 return ;
8993 } catch ( err ) {
9094 const alreadyPublished = _ . includes ( err . toString ( ) , 'You cannot publish over the previously published version' ) ;
9195 if ( ! alreadyPublished ) {
9296 throw err ;
9397 }
94- console . log ( `previously published. retrying with increased ${ VERSION_INC } ...` ) ;
98+ console . log ( `previous version published. Retrying with increased ${ VERSION_INC } ...` ) ;
9599 theCandidate = semver . inc ( theCandidate , VERSION_INC ) ;
96100 }
97101 }
98102}
99103
100104function tagAndPublish ( newVersion ) {
101105 console . log ( `trying to publish ${ newVersion } ...` ) ;
102- exec . execSync ( `npm --no-git-tag-version --allow-same-version version ${ newVersion } ` ) ;
103- exec . execSyncRead ( `npm publish --tag ${ VERSION_TAG } ` ) ;
104- if ( isReleaseBuild && ! IS_SNAPSHOT ) {
106+ exec . execSync ( `npm --no-git-tag-version version ${ newVersion } ` ) ; // --allow-same-version
107+ exec . execSync ( `npm publish --tag ${ VERSION_TAG } ` ) ; // execSyncRead
108+
109+ if ( isReleaseBuild && ! isSnapshotBuild ) {
105110 exec . execSync ( `git tag -a ${ newVersion } -m "${ newVersion } "` ) ;
106111 console . log ( `tagging git for version ${ newVersion } ...` ) ;
107- exec . execSyncSilent ( `git push origin ${ newVersion } ` ) ;
112+ // exec.execSyncSilent(`git push origin ${newVersion}`);
113+ exec . execSyncSilent ( `git push deploy ${ newVersion } || true` ) ;
108114 }
109115}
110116
0 commit comments