diff --git a/azure-pipelines.yml b/azure-pipelines.yml index cf32c7d..62a11b9 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -53,5 +53,6 @@ jobs: displayName: 'Build "pegjs/dist/*.js" files' - script: node tools/publish-dev displayName: 'Publish to NPM' - env: + variables: NPM_TOKEN: $(NPM_CI_TOKEN) + PR_BRANCH: $[ coalesce(variables['System.PullRequest.SourceBranch'], 'not-found') ] diff --git a/tools/publish-dev/index.js b/tools/publish-dev/index.js index 699352b..aef33f9 100644 --- a/tools/publish-dev/index.js +++ b/tools/publish-dev/index.js @@ -14,9 +14,17 @@ const npmrc = path.join( pegjs, ".npmrc" ); // variabes const APP = require( "./package.json" ).name; -const { GIT_BRANCH, GIT_COMMIT_SHA, NPM_TOKEN } = process.env; const VERSION = require( packagejson ).version; +const { + + GIT_BRANCH, + GIT_COMMIT_SHA, + NPM_TOKEN, + PR_BRANCH, + +} = process.env; + // local helpers function die( err ) { @@ -39,6 +47,13 @@ function exec( command, print = true ) { // assertions +if ( PR_BRANCH !== "not-found" ) { + + console.log( "Skipping publish, PR's are not published." ); + process.exit( 0 ); + +} + if ( ! GIT_BRANCH ) die( "`process.env.GIT_BRANCH` is required by " + APP ); if ( ! NPM_TOKEN ) die( "`process.env.NPM_TOKEN` is required by " + APP );