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
Increment version by semver keyword with --cd-version flag #607
Conversation
test/PublishCommand.js
Outdated
@@ -204,6 +204,85 @@ describe("PublishCommand", () => { | |||
} | |||
})); | |||
}); | |||
|
|||
it("should use semver increments when passed to repoVersion flag", (done) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
src/commands/PublishCommand.js
Outdated
}); | ||
|
||
return callback(null, { versions }); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got a little too excited when I first saw this. 😁
A few requests (more detail here):
- I'm not sure this should re-use
--repo-version
. - I'd like to be able to use it in non-independent repos.
- It would be nice to have some mention of it in the README!
I made all the changes requested and made the corresponding tests match more closely with your current pattern. Unfortunately, I can't figure out why Appveyor is upset. I changed the
What's interesting, is that there are 182 tests currently, so the mysterious fail doesn't seem to exist at all? |
…b.com/cif/lerna into feature/repo-version-semver-increment
package.json
Outdated
"test": "mocha -t 5000", | ||
"ci": "npm run lint && cross-env DEBUG_CALLS=true npm run test", | ||
"test": "mocha -t 20000", | ||
"ci": "npm run lint && cross-env npm run test", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to increase timeout for appveyor tests to pass (see main conversation thread for error there). Also removed DEBUG_CALLS to make test output readable. If you want it restored, happy to do as part of this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine to me. We removed it in Asini, too.
We could actually also remove the cross-env
, too, since that was just for getting the environment variable set consistently across environments. Then we could drop the dep, I think.
@hzoo @evocateur @doug-wade Any objection to dropping this?
src/commands/PublishCommand.js
Outdated
// Use the cdVersion flag to bump the global version as well | ||
const version = this.flags.cdVersion === "current" ? | ||
this.globalVersion : semver.inc(this.globalVersion, this.flags.cdVersion); | ||
return callback(null, { versions, version }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the caller again I think in independent mode version
(singular) is expected not to be set. So this should either set versions
(independent) or set version
(not). Kind of a weird interface. 😖
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hesitant to send both to callback in the deconstructed object, however in independent mode updateVersionInLernaJson
method isn't called due to execute:
if (!this.repository.isIndependent() && !this.flags.canary) {
this.updateVersionInLernaJson();
}
I did local tests switching between both and publishing to our local npm repo. I also added both normal and independent modes to the test suite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's more clear, we can use another !this.repository.isIndependent()
check here and send either-or to callback. Just let me know and consider it done if that's the call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and made the change to getVersionsForUpdates()
so the object passed is explicitly version
or versions
src/NpmUtilities.js
Outdated
@@ -76,21 +76,21 @@ export default class NpmUtilities { | |||
} | |||
|
|||
@logger.logifySync() | |||
static addDistTag(packageName, version, tag, registry) { | |||
static addDistTag(directory, packageName, version, tag, registry) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was getting odd NPM ERR on the final publish step in my build and realized because our modules are all @scoped/module in the package.json but simply module
in the directory that tagging would only work if you cd into the module before tagging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about specifying the cwd
option for execSync
rather than the manual cd
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed getTagOpts
signature to accept directory in addition to registry. publishTaggedInDir
was already using the same cd ... && npm ...
method. I updated this so that all methods are now using your suggestion
src/NpmUtilities.js
Outdated
@@ -76,21 +76,21 @@ export default class NpmUtilities { | |||
} | |||
|
|||
@logger.logifySync() | |||
static addDistTag(packageName, version, tag, registry) { | |||
static addDistTag(directory, packageName, version, tag, registry) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about specifying the cwd
option for execSync
rather than the manual cd
?
src/commands/PublishCommand.js
Outdated
const versions = {}; | ||
this.updates.forEach((update) => { | ||
versions[update.package.name] = this.flags.cdVersion === "current" ? | ||
update.package.version : semver.inc(update.package.version, this.flags.cdVersion); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put the ternary operators first, please? It is much easier to read, in my experience.
versions[update.package.name] = (this.flags.cdVersion === "current")
? update.package.version
: semver.inc(update.package.version, this.flags.cdVersion);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ternaries no longer needed due to current version removed
src/commands/PublishCommand.js
Outdated
this.flags.cdVersion === "major" || | ||
this.flags.cdVersion === "current" | ||
) { | ||
// Warn about possible problems with git and current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use-case for --cd-version current
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of a long story having to do with our deployment pipeline but we came to the conclusion it was a better strategy to always version. Removing the option in latest changes
Is there anything stopping this from getting merged at this point? Anything I can help with? |
There's a bit of talk in #567 about how to support the other semvers e.g. |
Hey @cif / @evocateur, Thank you guys for the hard work! |
@gigabo Are you satisfied with this now? I'll look into the conflicts today. |
Yep, looks good. Thanks @cif! |
@evocateur Just took a swing at resolving them, waiting on tests will update if they fail master was still assuming that call exec were using |
@cif thanks, I appreciate it. I'm also in the process of rebasing, and so far I've found that upstream changes make it really tricksy... |
in |
Wow! You guys are awesome... Thank you for this! |
@evocateur sounds like we may have overlapped, but I just pushed up some quick fixes for those tests. Feel free to clean up, could probably have used a helper instead of the copy/paste |
Thanks @cif ! |
I'd love to better understand how this is used in your CD process @cif If I understand, you'd have to run Is that the behaviour? What happens if in a single CI build I want one package to be published in a major increment and one in a minor? |
@bradbarrow We only increment the same value for each package. In our case we only use independent versioning because our starting points were already different which is why I created the PR. To handle the use case you describe it would require code changes as well as a specification for each increment on a package level (perhaps in each On a higher/philosophical level, it's worth asking the question - if your packages are versioning semantically independent of each other, are they really fit to be contained in a mono-repo project or are they better as independently maintained projects at that point? Generally, most of the teams I see who have the choice of lockstep vs independent (i.e. Babel https://github.com/babel/babel/blob/7.0/lerna.json) will choose lockstep if possible. Hope that helps! |
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
We do automated code analysis in our deploy pipelines and have a new Lerna repo which needs to operate in independent version mode. Currently the only way to automate publish (no prompts) from build server CL is to specify
--repo-version=x.x.x --yes
(or canary), however this forces all modules into that version.This PR allows setting up any changed "next" version(s) appropriately via root package.json / publish script
--cd-version=[patch|minor|major]
and pre setting the next value(s) in each module.When code is approved and subsequently merged, our build pipelines can use the right versions and deploy to our private npm repository.