Skip to content

Commit

Permalink
FLUID-5799: Fixing bug with tagging dev releases
Browse files Browse the repository at this point in the history
  • Loading branch information
jobara committed Dec 20, 2016
1 parent 74478a1 commit 66d5a98
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 116 deletions.
35 changes: 10 additions & 25 deletions README.md
Expand Up @@ -199,45 +199,30 @@ publish.standard();
</tr>
<tr>
<td>
<code>versionCmd</code>
<code>publishDevCmd</code>
</td>
<td>
The CLI to execute which sets the dev version to release under.
<ul>
<li>
<code>${version}</code> will be substituted with the generated dev build version.
</li>
</ul>
The CLI to execute which publishes a development release to NPM.
Uses the value specified by the `devTag` option.
</td>
<td>
"npm version --no-git-tag-version ${version}"
<br>
<br>
<p>
<em><strong>NOTE</strong>: This command will update the version in the package.json file, but will not commit the change.</em>
</p>
"npm publish --tag ${devTag}"
</td>
</tr>
<tr>
<td>
<code>distTagCmd</code>
<code>versionCmd</code>
</td>
<td>
The CLI to execute which tags an NPM release.
The CLI to execute which sets the dev version to release under.
<ul>
<li>
<code>${packageName}</code> will be substituted with executing module's name.
</li>
<li>
<code>${version}</code> will be substituted with the generated dev build version.
</li>
<li>
<code>${tag}</code>will be substituted with the value from the <code>devTag</code> option.
</li>
</ul>
</td>
<td>
"npm dist-tag add ${packageName}@${version} ${tag}"
"npm version --no-git-tag-version ${version}"
<br>
<br>
<p>
Expand Down Expand Up @@ -372,13 +357,13 @@ publish.standard();
</tr>
<tr>
<td>
<code>distTagHint</code>
<code>publishDevHint</code>
</td>
<td>
A hint for addressing an issue where applying a distribution tag fails.
A hint for addressing an issue where publishing to the registry fails.
</td>
<td>
"If the tag already exists use a new tag name or run \"npm dist-tag rm ${packageName} ${tag}\" to remove the existing one.\nAlso ensure that the tag name is valid (i.e. doesn't conform to a valid semver range like v1.4 or 1.4).\n"
"Ensure that you have access to publish to the registry and that the current version does not already exist.\nIf the tag already exists use a new tag name or run \"npm dist-tag rm ${packageName} ${tag}\" to remove the existing one.\nAlso ensure that the tag name is valid (i.e. doesn't conform to a valid semver range like v1.4 or 1.4).\n"
</td>
</tr>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -46,8 +46,8 @@
"revisionCmd": "git rev-parse --verify --short HEAD",
"packCmd": "npm pack",
"publishCmd": "npm publish",
"publishDevCmd": "npm publish --tag ${devTag}",
"versionCmd": "npm version --no-git-tag-version ${version}",
"distTagCmd": "npm dist-tag add ${packageName}@${version} ${tag}",
"cleanCmd": "git checkout -- package.json",
"vcTagCmd": "git tag -a v${version} -m 'Tagging the ${version} release'",
"pushVCTagCmd": "git push ${remote} v${version}",
Expand All @@ -58,7 +58,7 @@
"changesHint": "Address uncommitted changes: Commit \"git commit -a\", Stash \"git stash\" or Clean \"git reset --hard\"\n",
"checkRemoteHint": "Run \"git remote -v\" for a list of available remote repositories.\n",
"publishHint": "Ensure that you have access to publish to the registry and that the current version does not already exist.\n",
"distTagHint": "If the tag already exists use a new tag name or run \"npm dist-tag rm ${packageName} ${tag}\" to remove the existing one.\nAlso ensure that the tag name is valid (i.e. doesn't conform to a valid semver range like v1.4 or 1.4).\n",
"publishDevHint": "Ensure that you have access to publish to the registry and that the current version does not already exist.\nIf the tag already exists use a new tag name or run \"npm dist-tag rm ${packageName} ${tag}\" to remove the existing one.\nAlso ensure that the tag name is valid (i.e. doesn't conform to a valid semver range like v1.4 or 1.4).\n",
"vcTagHint": "If the tag already exists, run \"git tag -d v${version}\" to remove the existing tag.\n",
"pushVCTagHint": "If the tag already exists, run \"git push ${remote} :refs/tags/v${version} to remove the existing tag.\n"
}
Expand Down
30 changes: 7 additions & 23 deletions publish.js
Expand Up @@ -223,35 +223,20 @@ publish.getDevVersion = function (moduleVersion, options) {
* If isTest is specified, it will instead create a tarball in the local directory.
*
* @param isTest {Boolean} - indicates if this is a test run or not
* @param options {Object} - e.g. {"packCmd": "npm pack", "publishCmd": "npm publish", "publishHint": "publish hint"}
* @param isDev {Boolean} - indicates if this is a development (true) or standard (false) release
* @param options {Object} - e.g. {"packCmd": "npm pack", "publishCmd": "npm publish", "publishDevCmd": "npm publish --tag", "publishHint": "publish hint", "publishDevHint": "publish dev hint", devTag: "dev"}
*/
publish.pubImpl = function (isTest, options) {
publish.pubImpl = function (isTest, isDev, options) {
if (isTest) {
// create a local tarball
publish.execSyncFromTemplate(options.packCmd);
} else {
// publish to npm
publish.execSyncFromTemplate(options.publishCmd, {}, options.publishHint);
var pubCmd = isDev ? options.publishDevCmd : options.publishCmd;
publish.execSyncFromTemplate(pubCmd, options, options.publishHint);
}
};

/**
* Tags the specified version with the specified dist-tag
* If it is a test run, the tag command will be output to the console.
*
* @param isTest {Boolean} - indicates if this is a test run or not
* @param version {String} - a string indicating which version to tag
* @param tag {String} - the dist-tag to apply
* @param options {Object} - e.g. {"distTagCmd": "npm dist-tag add ${packageName}@${version} ${tag}", "distTagHint": "dist tag hint"}
*/
publish.tag = function (isTest, packageName, version, tag, options) {
publish.execSyncFromTemplate(options.distTagCmd, {
packageName: packageName,
version: version,
tag: tag
}, options.distTagHint, isTest);
};

/**
* Applies a version control tag to the latest commit
*
Expand Down Expand Up @@ -328,8 +313,7 @@ publish.dev = function (isTest, options) {

try {
// publish
publish.pubImpl(isTest, opts);
publish.tag(isTest, modulePkg.name, devVersion, opts.devTag, opts);
publish.pubImpl(isTest, true, opts);
} finally {
// cleanup changes
publish.clean(opts.moduleRoot, opts);
Expand Down Expand Up @@ -365,7 +349,7 @@ publish.standard = function (isTest, options) {
publish.tagVC (isTest, modulePkg.version, opts);

// publish
publish.pubImpl(isTest, opts);
publish.pubImpl(isTest, false, opts);
};

module.exports = publish;
Expand Down
117 changes: 51 additions & 66 deletions tests/publishTests.js
Expand Up @@ -318,81 +318,68 @@ console.log("\n*** publish.pubImpl ***");

var pubImplFixture = [{
isTest: true,
isDev: false,
packCmd: "pack",
publishCmd: "shouldn't publish"
publishCmd: "shouldn't publish",
publishDevCmd: "shouldn't publish dev"
}, {
isTest: false,
isDev: false,
packCmd: "shouldn't pack",
publishCmd: "publish"
publishCmd: "publish",
publishDevCmd: "shouldn't publish dev"
}, {
isDev: false,
packCmd: "shouldn't pack",
publishCmd: "publish"
publishCmd: "publish",
publishDevCmd: "shouldn't publish dev"
}, {
isDev: true,
packCmd: "shouldn't pack",
publishCmd: "shouldn't publish",
publishDevCmd: "publish dev"
}, {
isTest: false,
isDev: true,
packCmd: "pack",
publishCmd: "shouldn't publish",
publishDevCmd: "publish dev"
}, {
isTest: true,
isDev: true,
packCmd: "pack",
publishCmd: "shouldn't publish",
publishDevCmd: "shouldn't publish dev"
}, {
isTest: false,
packCmd: "shouldn't pack",
publishCmd: "publish",
publishDevCmd: "shouldn't publish dev"
}, {
isTest: true,
packCmd: "pack",
publishCmd: "shouldn't publish",
publishDevCmd: "shouldn't publish dev"
}, {
packCmd: "shouldn't pack",
publishCmd: "publish",
publishDevCmd: "shouldn't publish dev"
}];

pubImplFixture.forEach(function (fixture) {
console.log("pubImpl test - isTest: " + fixture.isTest + " packCmd: " + fixture.packCmd + " publishCmd: " + fixture.publishCmd);
console.log("pubImpl test - isTest: " + fixture.isTest + "isDev: " + fixture.isDev + " packCmd: " + fixture.packCmd + " publishCmd: " + fixture.publishCmd + " publishDevCmd: " + fixture.publishDevCmd);

var exec = sinon.stub(publish, "execSync");
var expected = fixture[fixture.isTest ? "packCmd" : "publishCmd"];
var expected = fixture.isTest ? fixture.packCmd : fixture[fixture.isDev ? "publishDevCmd" : "publishCmd"];

publish.pubImpl(fixture.isTest, fixture);
publish.pubImpl(fixture.isTest, fixture.isDev, fixture);
assert(exec.calledOnce, "execSync should have been called");
assert(exec.calledWith(expected), "execSync should have been called with: " + expected);

// remove execSync stub
publish.execSync.restore();
});

/***************
* publish.tag *
***************/
console.log("\n*** publish.tag ***");

var tagFixture = [{
isTest: true,
packageName: "test1",
version: "1.0.0",
tag: "tag",
distTagCmd: "add tag ${tag} to ${packageName} at ${version}",
expected: "add tag tag to test1 at 1.0.0"
}, {
isTest: false,
packageName: "test2",
version: "2.0.0",
tag: "tag2",
distTagCmd: "add tag ${tag} to ${packageName} at ${version}",
expected: "add tag tag2 to test2 at 2.0.0"
}, {
version: "3.0.0",
packageName: "test3",
tag: "tag3",
distTagCmd: "add tag ${tag} to ${packageName} at ${version}",
expected: "add tag tag3 to test3 at 3.0.0"
}];

tagFixture.forEach(function (fixture) {
console.log("tag test - isTest: " + fixture.isTest + " packageName: " + fixture.packageName + " version: " + fixture.version + " tag: " + fixture.tag + " distTagCmd: " + fixture.distTagCmd);

var toStub = ["execSync", "log"];
var stub = createStubs(publish, toStub);
var expectedLog = "Executing Command: " + fixture.expected;

publish.tag(fixture.isTest, fixture.packageName, fixture.version, fixture.tag, fixture);

assert(stub.log.calledOnce, "console.log should have been called");
assert(stub.log.calledWith(expectedLog), "console.log should have been called with: " + expectedLog);

if (fixture.isTest) {
assert(!stub.execSync.called, "execSync should not have been called");
} else {
assert(stub.execSync.calledOnce, "execSync should have been called");
assert(stub.execSync.calledWith(fixture.expected), "execSync should have been called with: " + fixture.expected);
}

// remove stubs
removeStubs(publish, toStub);
});

/*****************
* publish.clean *
*****************/
Expand Down Expand Up @@ -461,8 +448,8 @@ var publishFixture = [{
"revisionCmd": "dry run get revision",
"packCmd": "dry run pack",
"publishCmd": "dry run publish",
"publishDevCmd": "dry run npm publish dev",
"versionCmd": "dry run version",
"distTagCmd": "dry run set tag",
"cleanCmd": "dry run clean",
"vcTagCmd": "dry run vc tag",
"pushVCTagCmd": "dry run push vc tag",
Expand All @@ -473,7 +460,7 @@ var publishFixture = [{
"changesHint": "dry run changes hint\n",
"checkRemoteHint": "dry run check remote hint\n",
"publishHint": "dry run publish hint\n",
"distTagHint": "dry run dist tag hint\n",
"publishDevHint": "dry run publish dev hint\n",
"vcTagHint": "dry run vc tag hint\n",
"pushVCTagHint": "dry run push vc tag hint\n"
}
Expand All @@ -486,8 +473,8 @@ var publishFixture = [{
"revisionCmd": "get revision",
"packCmd": "pack",
"publishCmd": "publish",
"publishDevCmd": "publish dev",
"versionCmd": "version",
"distTagCmd": "set tag",
"cleanCmd": "clean",
"vcTagCmd": "vc tag",
"pushVCTagCmd": "push vc tag",
Expand All @@ -498,7 +485,7 @@ var publishFixture = [{
"changesHint": "changes hint\n",
"checkRemoteHint": "check remote hint\n",
"publishHint": "publish hint\n",
"distTagHint": "dist tag hint\n",
"publishDevHint": "publish dev hint\n",
"vcTagHint": "vc tag hint\n",
"pushVCTagHint": "push vc tag hint\n"
}
Expand All @@ -515,7 +502,7 @@ publishFixture.forEach(function (fixture) {
var optsString = JSON.stringify(fixture.options || {});
console.log("dev test - isTest: " + fixture.isTest, " options: " + optsString + "\n");

var toStub = ["checkChanges", "getDevVersion", "setVersion", "pubImpl", "tag", "clean"];
var toStub = ["checkChanges", "getDevVersion", "setVersion", "pubImpl", "clean"];
var stub = createStubs(publish, toStub);
var moduleVersion = modulePackage.version;
var devVersion = moduleVersion + "-testVersion";
Expand All @@ -530,11 +517,9 @@ publishFixture.forEach(function (fixture) {
assert(stub.setVersion.calledOnce, "setVersion should have been called");
assert(stub.setVersion.calledWith(devVersion, fixture.options), "setVersion should have been called with: " + devVersion + ", " + optsString);
assert(stub.pubImpl.calledOnce, "pubImpl should have been called");
assert(stub.pubImpl.calledWith(fixture.isTest, fixture.options), modulePackage);
assert(stub.tag.calledOnce, "tag should have been called");
assert(stub.tag.calledWith(fixture.isTest, modulePackage.name, devVersion, fixture.options.devTag, fixture.options), "tag should have been called with: " + fixture.isTest + ", " + modulePackage.name + ", " + devVersion + ", " + fixture.options.devTag + ", " + optsString);
assert(stub.pubImpl.calledWith(fixture.isTest, true, fixture.options), modulePackage);
assert(stub.clean.calledOnce, "clean should have been called");
assert(stub.clean.calledWith(fixture.options.moduleRoot, fixture.options), "clean should have been called with: " + fixture.options.moduleRoot + ", " + optsString);
assert(stub.clean.calledWith(fixture.options.moduleRoot, fixture.options), "clean should have been called with: " + fixture.options.moduleRoot + ", true, " + optsString);

removeStubs(publish, toStub);
});
Expand All @@ -561,7 +546,7 @@ publishFixture.forEach(function (fixture) {
assert(stub.tagVC.calledOnce, "tagVC should have been called");
assert(stub.tagVC.calledWith(fixture.isTest, modulePackage.version, fixture.options), "tagVC should have been called with: " + fixture.isTest + " ," + modulePackage.version + " ," + optsString);
assert(stub.pubImpl.calledOnce, "pubImpl should have been called");
assert(stub.pubImpl.calledWith(fixture.isTest, fixture.options), "pubImpl should have been called with: " + fixture.isTest + ", " + optsString);
assert(stub.pubImpl.calledWith(fixture.isTest, false, fixture.options), "pubImpl should have been called with: " + fixture.isTest + ", false, " + optsString);

removeStubs(publish, toStub);
});

0 comments on commit 66d5a98

Please sign in to comment.