From 910a51bf5f976334a0814d5b05a1f9978e95ff94 Mon Sep 17 00:00:00 2001 From: Futago-za Ryuu Date: Wed, 20 Mar 2019 21:57:26 +0000 Subject: [PATCH] Dont auto-publish on PR's --- azure-pipelines.yml | 3 ++- tools/publish-dev/index.js | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) 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 );