Skip to content

Commit 65259d1

Browse files
committed
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.
1 parent 34c0342 commit 65259d1

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

scripts/publish-npm.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,17 @@ if (buildBranch.indexOf(`-stable`) !== -1) {
6060
exit(0);
6161
}
6262

63-
// ['latest', 'v0.33.0', 'v0.33.0-rc', 'v0.33.0-rc1', 'v0.33.0-rc2', 'v0.34.0', '']
64-
const tagsWithVersion = exec(`git tag -l --points-at HEAD`).stdout.split(/\s/)
65-
// ['v0.33.0', 'v0.33.0-rc', 'v0.33.0-rc1', 'v0.33.0-rc2', 'v0.34.0']
66-
.filter(version => !!version && version.indexOf(`v${branchVersion}`) === 0)
63+
// 34c034298dc9cad5a4553964a5a324450fda0385
64+
const currentCommit = exec(`git rev-parse HEAD`, {silent: true}).stdout.trim();
65+
// [34c034298dc9cad5a4553964a5a324450fda0385, refs/heads/0.33-stable, refs/tags/latest, refs/tags/v0.33.1, refs/tags/v0.34.1-rc]
66+
const tagsWithVersion = exec(`git ls-remote origin | grep ${currentCommit}`, {silent: true})
67+
.stdout.split(/\s/)
68+
// ['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']
69+
.filter(version => !!version && version.indexOf(`refs/tags/v${branchVersion}`) === 0)
70+
// ['refs/tags/v0.33.0', 'refs/tags/v0.33.0-rc', 'refs/tags/v0.33.0-rc1', 'refs/tags/v0.33.0-rc2']
71+
.filter(version => version.indexOf(branchVersion) !== -1)
6772
// ['v0.33.0', 'v0.33.0-rc', 'v0.33.0-rc1', 'v0.33.0-rc2']
68-
.filter(version => version.indexOf(branchVersion) !== -1);
73+
.map(version => version.slice(`refs/tags/`.length));
6974

7075
if (tagsWithVersion.length === 0) {
7176
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`);

0 commit comments

Comments
 (0)