From 65259d1c4fa395beb1b57b52d3e202966bb5bda0 Mon Sep 17 00:00:00 2001 From: Konstantin Raev Date: Wed, 18 May 2016 23:09:23 +0100 Subject: [PATCH] Made npm deployment to be independent of git tags cache Current implementation of publish-npm script is not flexible in CircleCI because it does not update local tags. This script fetches tags from origin allowing to republish tags e.g. v0.26.0 even if Circle cached it from another build. --- scripts/publish-npm.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/publish-npm.js b/scripts/publish-npm.js index ba5efc2d394..3986a9924d9 100644 --- a/scripts/publish-npm.js +++ b/scripts/publish-npm.js @@ -60,12 +60,17 @@ if (buildBranch.indexOf(`-stable`) !== -1) { exit(0); } -// ['latest', 'v0.33.0', 'v0.33.0-rc', 'v0.33.0-rc1', 'v0.33.0-rc2', 'v0.34.0', ''] -const tagsWithVersion = exec(`git tag -l --points-at HEAD`).stdout.split(/\s/) - // ['v0.33.0', 'v0.33.0-rc', 'v0.33.0-rc1', 'v0.33.0-rc2', 'v0.34.0'] - .filter(version => !!version && version.indexOf(`v${branchVersion}`) === 0) +// 34c034298dc9cad5a4553964a5a324450fda0385 +const currentCommit = exec(`git rev-parse HEAD`, {silent: true}).stdout.trim(); +// [34c034298dc9cad5a4553964a5a324450fda0385, refs/heads/0.33-stable, refs/tags/latest, refs/tags/v0.33.1, refs/tags/v0.34.1-rc] +const tagsWithVersion = exec(`git ls-remote origin | grep ${currentCommit}`, {silent: true}) + .stdout.split(/\s/) + // ['refs/tags/v0.33.0', 'refs/tags/v0.33.0-rc', 'refs/tags/v0.33.0-rc1', 'refs/tags/v0.33.0-rc2', 'refs/tags/v0.34.0'] + .filter(version => !!version && version.indexOf(`refs/tags/v${branchVersion}`) === 0) + // ['refs/tags/v0.33.0', 'refs/tags/v0.33.0-rc', 'refs/tags/v0.33.0-rc1', 'refs/tags/v0.33.0-rc2'] + .filter(version => version.indexOf(branchVersion) !== -1) // ['v0.33.0', 'v0.33.0-rc', 'v0.33.0-rc1', 'v0.33.0-rc2'] - .filter(version => version.indexOf(branchVersion) !== -1); + .map(version => version.slice(`refs/tags/`.length)); if (tagsWithVersion.length === 0) { echo(`Error: Can't find version tag in current commit. To deploy to NPM you must add tag v0.XY.Z[-rc] to your commit`);