@@ -3,9 +3,14 @@ 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+ if ( process . env . BUILDKITE_MESSAGE . match ( / ^ r e l e a s e $ / i) ) {
10+ IS_SNAPSHOT = cp . execSync ( `buildkite-agent meta-data get is-snapshot` ) . toString ( ) ;
11+ }
712const ONLY_ON_BRANCH = 'origin/release' ;
8- const isSnapshotBuild = process . env . RELEASE_SNAPSHOT_VERSION === 'true' ;
13+ const isSnapshotBuild = IS_SNAPSHOT === 'true' ;
914const VERSION_TAG = isSnapshotBuild ? 'snapshot' : 'latest' ;
1015const VERSION_INC = 'minor' ;
1116
@@ -20,17 +25,12 @@ function run() {
2025}
2126
2227function validateEnv ( ) {
23- if ( ! process . env . JENKINS_CI ) {
28+ if ( ! process . env . CI ) {
2429 throw new Error ( 'releasing is only available from CI' ) ;
2530 }
2631
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- console . log ( `not publishing on branch ${ process . env . GIT_BRANCH } ` ) ;
32+ if ( process . env . BUILDKITE_BRANCH !== ONLY_ON_BRANCH && ! isSnapshotBuild ) {
33+ console . log ( `not publishing on branch ${ process . env . BUILDKITE_BRANCH } ` ) ;
3434 return false ;
3535 }
3636
@@ -43,7 +43,7 @@ function setupGit() {
4343 exec . execSyncSilent ( `git config --global user.name "${ process . env . GIT_USER } "` ) ;
4444 const remoteUrl = new RegExp ( 'https?://(\\S+)' ) . exec ( exec . execSyncRead ( 'git remote -v' ) ) [ 1 ] ;
4545 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 } ` ) ;
46+ exec . execSync ( `git checkout ${ process . env . BUILDKITE_BRANCH } ` ) ;
4747}
4848
4949function createNpmRc ( ) {
@@ -64,7 +64,7 @@ function versionTagAndPublish() {
6464
6565 let version ;
6666 if ( isSnapshotBuild ) {
67- version = `${ currentPublished } -snapshot.${ process . env . BUILD_ID } ` ;
67+ version = `${ currentPublished } -snapshot.${ process . env . BUILDKITE_BUILD_NUMBER } ` ;
6868 } else {
6969 version = semver . gt ( packageVersion , currentPublished ) ? packageVersion : semver . inc ( currentPublished , VERSION_INC ) ;
7070 }
0 commit comments