@@ -3,9 +3,15 @@ const _ = require('lodash');
33const fs = require ( 'fs' ) ;
44const semver = require ( 'semver' ) ;
55const exec = require ( 'shell-utils' ) . exec ;
6+ const cp = require ( 'child_process' ) ;
67
8+ let IS_SNAPSHOT ;
9+ const isRelease = process . env . BUILDKITE_MESSAGE . match ( / ^ r e l e a s e $ / i) ;
10+ if ( isRelease ) {
11+ IS_SNAPSHOT = cp . execSync ( `buildkite-agent meta-data get is-snapshot` ) . toString ( ) ;
12+ }
713const ONLY_ON_BRANCH = 'origin/release' ;
8- const isSnapshotBuild = process . env . RELEASE_SNAPSHOT_VERSION === 'true' ;
14+ const isSnapshotBuild = IS_SNAPSHOT === 'true' ;
915const VERSION_TAG = isSnapshotBuild ? 'snapshot' : 'latest' ;
1016const VERSION_INC = 'minor' ;
1117
@@ -20,16 +26,11 @@ function run() {
2026}
2127
2228function validateEnv ( ) {
23- if ( ! process . env . JENKINS_CI ) {
29+ if ( ! process . env . CI ) {
2430 throw new Error ( 'releasing is only available from CI' ) ;
2531 }
2632
27- if ( ! process . env . JENKINS_MASTER ) {
28- console . log ( 'not publishing on a different build' ) ;
29- return false ;
30- }
31-
32- if ( process . env . GIT_BRANCH !== ONLY_ON_BRANCH && ! isSnapshotBuild ) {
33+ if ( process . env . BUILDKITE_BRANCH !== ONLY_ON_BRANCH && ! isSnapshotBuild ) {
3334 console . log ( `not publishing on branch ${ process . env . GIT_BRANCH } ` ) ;
3435 return false ;
3536 }
@@ -43,7 +44,7 @@ function setupGit() {
4344 exec . execSyncSilent ( `git config --global user.name "${ process . env . GIT_USER } "` ) ;
4445 const remoteUrl = new RegExp ( 'https?://(\\S+)' ) . exec ( exec . execSyncRead ( 'git remote -v' ) ) [ 1 ] ;
4546 exec . execSyncSilent ( `git remote add deploy "https://${ process . env . GIT_USER } :${ process . env . GIT_TOKEN } @${ remoteUrl } "` ) ;
46- exec . execSync ( `git checkout ${ process . env . GIT_BRANCH } ` ) ;
47+ exec . execSync ( `git checkout ${ process . env . BUILDKITE_BRANCH } ` ) ;
4748}
4849
4950function createNpmRc ( ) {
@@ -64,7 +65,7 @@ function versionTagAndPublish() {
6465
6566 let version ;
6667 if ( isSnapshotBuild ) {
67- version = `${ currentPublished } -snapshot.${ process . env . BUILD_ID } ` ;
68+ version = `${ currentPublished } -snapshot.${ process . env . BUILDKITE_BUILD_NUMBER } ` ;
6869 } else {
6970 version = semver . gt ( packageVersion , currentPublished ) ? packageVersion : semver . inc ( currentPublished , VERSION_INC ) ;
7071 }
@@ -97,7 +98,7 @@ function tryPublishAndTag(version) {
9798function tagAndPublish ( newVersion ) {
9899 console . log ( `trying to publish ${ newVersion } ...` ) ;
99100 exec . execSync ( `npm --no-git-tag-version --allow-same-version version ${ newVersion } ` ) ;
100- exec . execSyncRead ( `npm publish --tag ${ VERSION_TAG } ` ) ;
101+ // exec.execSyncRead(`npm publish --tag ${VERSION_TAG}`);
101102 exec . execSync ( `git tag -a ${ newVersion } -m "${ newVersion } "` ) ;
102103 exec . execSyncSilent ( `git push deploy ${ newVersion } || true` ) ;
103104}
0 commit comments