From 934acd809df9871272731ee70ce6e97e2168f9c1 Mon Sep 17 00:00:00 2001 From: Konstantin Raev Date: Mon, 23 May 2016 06:44:37 -0700 Subject: [PATCH] Made npm deployment to be independent of git tags cache Summary: Fixes npm deployment script as in https://circleci.com/gh/facebook/react-native/6745. Example situation: - admin is ready to release 0.26.0 - admin adds tag v0.26.0 and pushes to origin - Circle CI build fails because of code error - admin cherry-picks a fix and tags v0.26.0 again and pushes to origin - Circle does not update local tag v0.26.0 because it already has it cached, compiles the code but fails to deploy to npm because v0.26.0 is not on branch HEAD from Circle point of view The previous version of the script was checking the tags on current commit as well but it used the local branch tags. This change fetches tags from `origin` fresh and allows us to redeploy the same version multiple times. Closes https://github.com/facebook/react-native/pull/7619 Differential Revision: D3334469 fbshipit-source-id: b423fc19516dc4f5f7f2605224e62b8a378c8a7d --- 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`);