Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment version by semver keyword with --cd-version flag #607

Merged
merged 41 commits into from Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f05e704
Flag —-repo-version can be passed semver increment
Feb 17, 2017
b0abdb4
Option for current version, pra/merge pipelines
Feb 17, 2017
f1f031f
Fixed test using EOL for NT environment appveyor
Feb 18, 2017
916f329
Update to use —-cd-version, README, tests
Feb 20, 2017
b8f2ef3
Removed necessary check due to git warning
Feb 20, 2017
4906409
Quick change to README for appveyor build retry
Feb 20, 2017
6f73862
Removed debug from ci script
Feb 20, 2017
cef1634
Removing new cd version tests for appveyor
Feb 21, 2017
1aec9b8
Full revert to master /test dir
Feb 21, 2017
fb6d2cb
Revert publish command to master appveyor test
Feb 21, 2017
762a33b
Increasing timeout on mocha per appveyor forum
Feb 21, 2017
bac6568
Merge branch 'feature/repo-version-semver-increment' of https://githu…
Feb 21, 2017
88cf53b
Restored changes
Feb 21, 2017
9f678d2
Change callback argument to explicit version mode
Feb 22, 2017
0919778
Remove additinoal line break
Feb 22, 2017
41f5d9d
Have to cd into directories to add / rm tags
Feb 23, 2017
addbf8d
Merge branch 'master' into feature/repo-version-semver-increment
cif Feb 23, 2017
254e679
Fixed tests from changes to master
Feb 23, 2017
29def98
Rebasing forked master to fix tests
Feb 27, 2017
bdd03e5
Removing new cd version tests for appveyor
Feb 21, 2017
fb1dd8f
Full revert to master /test dir
Feb 21, 2017
dcff07d
Revert publish command to master appveyor test
Feb 21, 2017
57c6a3e
Increasing timeout on mocha per appveyor forum
Feb 21, 2017
9c655af
Restored changes
Feb 21, 2017
b56b14c
Change callback argument to explicit version mode
Feb 22, 2017
a76dbcf
Remove additinoal line break
Feb 22, 2017
7278490
Have to cd into directories to add / rm tags
Feb 23, 2017
88cc4bc
Fixed tests from changes to master
Feb 23, 2017
24cbcde
Rebasing forked master to fix tests
Feb 27, 2017
a545ef3
Removed current option value, NPM utils feedback
Feb 27, 2017
664f1b6
Strange gramatical error from rebase fix
Feb 27, 2017
8ff033b
Removed escapeArgs from cwd assertions for appveyor
Feb 27, 2017
109356c
Merge branch 'master' into feature/repo-version-semver-increment
cif Mar 1, 2017
33f555d
Fix broken test from master merge conflict
cif Mar 1, 2017
f564d43
Merge branch 'master' into feature/repo-version-semver-increment
cif Mar 9, 2017
403a326
Fixed up tests for cwd option
Mar 10, 2017
0a8d213
Oops lint didnt work in editor
Mar 10, 2017
1ed379f
cleanups
Mar 10, 2017
dda2c02
don't tweak env before magic hidden async operations complete :P
Mar 10, 2017
6b33324
remove unused cross-env
Mar 10, 2017
f385531
remove references to DEBUG_CALLS env var
Mar 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/commands/PublishCommand.js
Expand Up @@ -151,6 +151,20 @@ export default class PublishCommand extends Command {

getVersionsForUpdates(callback) {
if (this.flags.repoVersion) {
// Allows automatic bumping to next semver via repoVersion flag
if (this.flags.repoVersion === "patch" ||
this.flags.repoVersion === "minor" ||
this.flags.repoVersion === "major" ||
this.flags.repoVersion === "current"
) {
const versions = {};
this.updates.forEach((update) => {
versions[update.package.name] = this.flags.repoVersion === "current" ?
update.package.version : semver.inc(update.package.version, this.flags.repoVersion);
});

return callback(null, { versions });
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... actually I wonder if --repo-version is the right option for this. That's really meant specifically for non-independent versioning. And actually looking at this again it will only work correctly for independently versioned repos. It won't update the version in lerna.json unless the return value from getVersionsForUpdates includes a version (singular) value.

It might actually be better to add a new option that works for both independent and non-independent repos.

Copy link
Contributor Author

@cif cif Feb 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same thoughts :) This was the easiest point of interception to get this working locally without introducing much new functionality. Stoked maintainers are willing to help guide this one, we really need it. Any suggestions on flag name? I feel it should be fairly straight forward within the same method to intercept and alter the test. I'll get back to you with more suggestions on that first thing next week. As I stated in the comment, definitely tough to get all paths (especially the inverse coverage) when you have many options

return callback(null, {
version: this.flags.repoVersion
});
Expand Down
81 changes: 80 additions & 1 deletion test/PublishCommand.js
Expand Up @@ -204,6 +204,85 @@ describe("PublishCommand", () => {
}
}));
});

it("should use semver increments when passed to repoVersion flag", (done) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion, but feel it would be worth refactoring these tests to smaller assertion blocks / calls rather than the larger fixture > result chunks. CLI tools with lots of arg permutations is hard to test all paths

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds interesting, but not sure I understand clearly. Can you give an example of how you'd like to see it organized?

const publishCommand = new PublishCommand([], {
independent: true,
repoVersion: "patch"
});

publishCommand.runValidations();
publishCommand.runPreparations();

assertStubbedCalls([
[ChildProcessUtilities, "execSync", {}, [
{ args: ["git tag"] }
]],
[PromptUtilities, "confirm", { valueCallback: true }, [
{ args: ["Are you sure you want to publish the above changes?"], returns: true }
]],
[ChildProcessUtilities, "execSync", {}, [
{ args: ["git add " + escapeArgs(path.join(testDir, "packages/package-1/package.json"))] },
{ args: ["git add " + escapeArgs(path.join(testDir, "packages/package-2/package.json"))] },
{ args: ["git add " + escapeArgs(path.join(testDir, "packages/package-3/package.json"))] },
{ args: ["git add " + escapeArgs(path.join(testDir, "packages/package-4/package.json"))] },
{ args: ["git commit -m \"$(echo \"Publish" + EOL + EOL + " - package-1@1.0.1" + EOL + " - package-2@2.0.1" + EOL + " - package-3@3.0.1" + EOL + " - package-4@4.0.1\")\""] },
{ args: ["git tag package-1@1.0.1"] },
{ args: ["git tag package-2@2.0.1"] },
{ args: ["git tag package-3@3.0.1"] },
{ args: ["git tag package-4@4.0.1"] }
]],
[ChildProcessUtilities, "exec", { nodeCallback: true }, [
{ args: ["cd " + escapeArgs(path.join(testDir, "packages/package-1")) + " && npm publish --tag lerna-temp"] },
{ args: ["cd " + escapeArgs(path.join(testDir, "packages/package-3")) + " && npm publish --tag lerna-temp"] },
{ args: ["cd " + escapeArgs(path.join(testDir, "packages/package-4")) + " && npm publish --tag lerna-temp"] },
{ args: ["cd " + escapeArgs(path.join(testDir, "packages/package-2")) + " && npm publish --tag lerna-temp"] }
], true],
[ChildProcessUtilities, "execSync", {}, [
{ args: ["npm dist-tag ls package-1"], returns: "lerna-temp: 1.0.1\nstable: 1.0.0" },
{ args: ["npm dist-tag rm package-1 lerna-temp"] },
{ args: ["npm dist-tag add package-1@1.0.1 latest"] },

{ args: ["npm dist-tag ls package-3"], returns: "lerna-temp: 1.0.1\nstable: 1.0.0" },
{ args: ["npm dist-tag rm package-3 lerna-temp"] },
{ args: ["npm dist-tag add package-3@3.0.1 latest"] },

{ args: ["npm dist-tag ls package-4"], returns: "lerna-temp: 1.0.1\nstable: 1.0.0" },
{ args: ["npm dist-tag rm package-4 lerna-temp"] },
{ args: ["npm dist-tag add package-4@4.0.1 latest"] },

{ args: ["npm dist-tag ls package-2"], returns: "lerna-temp: 1.0.1\nstable: 1.0.0" },
{ args: ["npm dist-tag rm package-2 lerna-temp"] },
{ args: ["npm dist-tag add package-2@2.0.1 latest"] },

{ args: ["git symbolic-ref --short HEAD"], returns: "master" },
{ args: ["git push origin master"] },
{ args: ["git push origin package-1@1.0.1 package-2@2.0.1 package-3@3.0.1 package-4@4.0.1"] }
]],
]);

publishCommand.runCommand(exitWithCode(0, (err) => {
if (err) return done(err);

try {
assert.ok(!pathExists.sync(path.join(testDir, "lerna-debug.log")));
assert.equal(normalizeNewline(fs.readFileSync(path.join(testDir, "lerna.json"), "utf-8")), "{\n \"lerna\": \"__TEST_VERSION__\",\n \"version\": \"independent\"\n}\n");

assert.equal(require(path.join(testDir, "packages/package-1/package.json")).version, "1.0.1");
assert.equal(require(path.join(testDir, "packages/package-2/package.json")).version, "2.0.1");
assert.equal(require(path.join(testDir, "packages/package-3/package.json")).version, "3.0.1");
assert.equal(require(path.join(testDir, "packages/package-4/package.json")).version, "4.0.1");

assert.equal(require(path.join(testDir, "packages/package-2/package.json")).dependencies["package-1"], "^1.0.1");
assert.equal(require(path.join(testDir, "packages/package-3/package.json")).devDependencies["package-2"], "^2.0.1");
assert.equal(require(path.join(testDir, "packages/package-4/package.json")).dependencies["package-1"], "^0.0.0");

done();
} catch (err) {
done(err);
}
}));
});
});

/** =========================================================================
Expand Down Expand Up @@ -746,7 +825,7 @@ describe("PublishCommand", () => {
{ args: ["npm dist-tag ls package-4", {env: {"npm_config_registry":"https://my-private-registry"}}], returns: "lerna-temp: 1.0.1\nstable: 1.0.0" },
{ args: ["npm dist-tag rm package-4 lerna-temp", {env: {"npm_config_registry":"https://my-private-registry"}}] },
{ args: ["npm dist-tag add package-4@1.0.1 latest", {env: {"npm_config_registry":"https://my-private-registry"}}] },

{ args: ["npm dist-tag ls package-2", {env: {"npm_config_registry":"https://my-private-registry"}}], returns: "lerna-temp: 1.0.1\nstable: 1.0.0" },
{ args: ["npm dist-tag rm package-2 lerna-temp", {env: {"npm_config_registry":"https://my-private-registry"}}] },
{ args: ["npm dist-tag add package-2@1.0.1 latest", {env: {"npm_config_registry":"https://my-private-registry"}}] },
Expand Down