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
feat: support custom release tag in GitHub #431
Conversation
src/post.js
Outdated
var tag = { | ||
owner: ghRepo[0], | ||
repo: ghRepo[1], | ||
ref: 'refs/tags/v' + pkg.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.
You are replacing creating the v1.2.3
tags. We will not remove that feature. But we could additionally create a tag if a custom tag is set in publishConfig
.
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.
Not sure I understand the first part. Shouldn't it match with release.tag_name and release.name?
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.
instead of creating a single tag, we know would create 2 tags at once:
- the version tag in the form of
v1.2.3
- the release tag which matches the name of the tag used to publish the package on npm
Does that make sense?
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.
ah, so this line would be kept in v1.2.3 format and only the release one changes if publishConfig is present?
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.
nothing changes, if we release a new version 1.2.3
to npm, we will still create a git tag v1.2.3
. But if publishConfig.tag
is to set "next"
then we can create an additional git tag called next
.
What I’m not exactly sure about is what happens if a git tag next
already exists from an earlier release. We would probably check if it does, if yes delete it, then create it again.
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.
So I just need to create an additional reference (github.gitdata.createReference) when publishConfig.tag is present, and the release (github.repos.createRelease) shouldn't be changed, right?
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.
yes :)
test/specs/post.js
Outdated
@@ -9,6 +9,9 @@ var post = proxyquire('../../src/post', { | |||
|
|||
var pkg = { | |||
version: '1.0.0', | |||
publishConfig: { | |||
tag: 'beta' | |||
}, |
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.
Don’t change an existing test, please create a new on
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 about to, but it raises the error I mentioned even without the changes. What do you recommend to fix that?
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.
the tests should pass, they just did about 19h ago on travis:
https://travis-ci.org/semantic-release/semantic-release/builds/275739048
The tests that currently fail are related to your changes.
Before the changes, what errors do you see?
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.
Hmmm that's weird. I forked and just ran npm install and npm test. Do I need anything else?
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.
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've installed it, and it's running in http://localhost:5984/_utils/ but I'm not sure what else I need to set it up for the tests. couchdb doesn't work in the terminal despite being added (manually) to the path environment variable (windows).
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.
The whole setup is not ideal right now, I don’t even know if it’s working on Windows :(
as a workaround, can you try to adapt these lines for local testing:
semantic-release/test/registry/start.sh
Lines 22 to 23 in 88b5895
COUCH=http://admin:password@127.0.0.1:15986 | |
couchdb -b -a local.ini -p couch/pid -o couch/stdout.log -e couch/stderr.log |
Change the port number in L22 to to 5984
and comment out the second. Make sure you created an admin account with username "admin" and password "password" at http://localhost:5984/_utils/
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.
Still doesn't seem to work. I will try with a different couchdb version tomorrow, as running couchdb is producing some weird output (kernel-poll not supported). Probably some windows black magic going on here 💃
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’m sorry for the trouble, thanks for your patience! If it doesn’t work, you can still push and have travis run the integration tests.
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.
It seems to be a problem with privileges in Windows... Still trying to figure out a solution.
Either way please check my other comment, related to the tags 👍
d8733e6
to
3d1e5af
Compare
Please check the changes 👍 I'm still not sure how to test it thoroughly though. |
I also don’t know yet, but I’ll have a look. I’ll be busy with work until Saturday, I'll have a look then. What you can do until then is to setup a test repository for a test npm package, set |
After some struggle, I think I got it. It's deleting and creating a new one when it already exists. Please also give it a try and let me know what you think. |
6525197
to
3dea014
Compare
3dea014
to
a8e0090
Compare
@Apidcloud thanks for the contribution! We now use the git tags as a fallback to determine the commit that was used to make the last release. And we expect the tag associated with the release to be named according npm recommendation (or at to the way In addition, it's not possible to have a version released multiple time on different tags. That means that when you release What would be the objective of your proposal? Could you describe which scenario you'd like to achieve? Thanks ! |
}, function (err, published, release) { | ||
tt.error(err) | ||
tt.is(published, true) | ||
tt.match(release, defaultRelease) |
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.
Should you test that the custom tag has been created ?
Because defaultReleasetag_name
is: 'v1.0.0' which is not the custom tag. So if the code works and actuallt create a custom tag, this test would fail.
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.
Yeah, I wasn't sure how to test it. Can give it another try though.
} | ||
}) | ||
} | ||
}) |
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 purpose of this section of code?
It seems outside of the scope of this PR (which is to customize git tag based on release tag)?
It might be a good candidate for another PR. Even though we would have to think about the consequences of deleting tags. Maybe the user has other tags, maybe there is other things relying on this tag etc...So it's probably safer to log the error and explain the user what to do rather than taking the risk of deleting something the user might care about.
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.
This part makes sure the reference (tag) doesn't exist when we create it, otherwise, it throws an error. But on a first glance, I believe I forgot to check whether the custom tag was defined in the first place.
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.
Isn't the github API would already throw an error when you create a tag that already exist?
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.
Exactly, and thus deleting it when that's the case. There might be better ways to do so, though.
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 I mean is:
- We probably don't want to delete tags. We have no way to check if the original tag is intentional or not. We don't want to take any destructive action without user consent.
- If the objective is to test if the tag exist before creating it, the "create tag" API call is already doing that.
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 agree with you. Originally I thought the same tag could have multiple versions within, but I believe that's not possible and thus the need of replacing it.
Would next/v2.0.0
as you mentioned earlier make more sense?
The first idea was to mirror what happens over npm when releasing under a custom tag (say alpha). But as the GitHub behaviour is rather different, the purpose of this PR is to create a 2nd tag (when defined) that points to the same release. Doesn't have to be Let me know your thoughts! |
I might be wrong but I think npm create a tag like
It didn't occur to me that the code was creating a second tag, but I checked fairly quickly :) |
TLDR: Ok. I'll try to explain it based on what I wanted (and still want) to accomplish. In GitHub the behaviour is different. There's just a numerical version (e.g., v0.4.0) as explained in the issue #97 by @gr2m:
What I originally wanted was to mirror what happens in npm, so I suggested mixing the GitHub tag with the custom tag (e.g., v1.0.0-alpha) and make the release with that. But I think that's not acceptable for you, is it? Then the idea was to create a 2nd tag (custom tag, only when defined) reference that points to the same numerical release. Does that make sense? I'm not sure myself anymore. |
I understand. But as I was trying to explain in this comment the notion of git tag and npm dist-tag are quite different. A git tag mark a commit as a milestone in the history and is not meant to be changed.
In that scenario there is no version So it doesn't make much sense to have a git tag, meant to represent a milestone in the evolution of the package, to be named after it's temporary distribution channel. The way github handle that is with pre-release. See creating-releases, especially:
What would make more sense would be to create github release flagged as In terms of semantic-release you would configure your "publishConfig": {
"tag": "next"
},
"release": {
"pre-release": true //New option we would have to add
} Each time
If the version is never deemed good enough for general availability, it would stay like that. But if it is deemed good enough for general availability you can move it to the npm Does that make sense? Would that work for you? |
Here is a good blog post on the subject: https://blog.greenkeeper.io/one-simple-trick-for-javascript-package-maintainers-to-avoid-breaking-their-user-s-software-and-to-6edf06dc5617 |
In addition, it's worth noting that npm does support the prereleases but as mentioned here |
Thank you for the wonderful explanation and link. I think I understand it better now. Would the migration to latest dist channel be done manually though? And should this PR focus on creating a pre release in GitHub when the dist tag is next and the pre release is set to true? (Is this flag even needed? Shouldn’t it happen by default as the tag is next?) Thanks again! I’ll try to take a look tomorrow. |
I think so, because
If that fit your need and you would like to make a PR for this feature, yes. But maybe it would be better to start a new PR (referencing this on in the comment). Also it's probably better to do that independently of the release branch configured in
Some users might name their beta/unstable/preview/notProdReadyYet branch other than @gr2m do you have some feedback / concerns on this ? |
The only problem I see with this is that when you set the
I’m undecided. I’d be okay flagging a GitHub release as "pre-release" if the dist tag is set to anything else than |
Yes indeed. I'm fiddling with what we can do regarding the refactoring of the cli (the main
We also have to handle situations where folks publish on a |
That’d be super nice! I’m also thinking about the GitHub app that could do such things, but that’s out of scope and would only work for GitHub. Love the idea to make it work with the CLI! |
Good point ... we could also add another option the package.json publishConfig ... or be smart about it and see if the released version is higher than the currently |
I was thinking the same :) But that would require a user action (as the decision to make a release available on the |
Yes, but we are touching a complex subject. I've been thinking about that and hoe deal with or prevent situations of "non consistent" release across dist-tag. For example if folks have a I have a few ideas on how to handle those cases but the deeper I dig the more edges case I find and the more unlikely they get. My best shot so far would be to have the Anyway that's not really the subject of this PR. But maybe it's safer to keep it configurable, and try later to improve the algorithm to automatically determine the appropriate config? |
It might be better to create another PR then. And just to make sure, it would address the following:
Does that sound ok? |
The idea is to mark the github release as a pre-release if the dist-tag in Maybe an option with that can accept a string or an array of string that defines the branches the branches on which we don't do a non pre-release. If this config is not present, then we consider it's Keep in mind that in order to accept the PR we would ask to have unit tests that cover all the cases introduced by the change. I refactored all the unit test recently so they should be easier to understand, but feel free to ask any questions :) |
Ok. Where would that branch config be placed? Inside |
I'd say in |
Well you don’t, this would be like an LTS version, you keep maintaining it, but you can’t do breaking changes. We had discussion on this somewhere else. The idea is that when I release 3.0.0 I’d create a branch 2.x.x and in that branch I could set a base version to "2" so releases from that version would release as the next version within 2.x.x, but it would not allow breaking changes at all. Not sure what the npm tag would be, we could default to |
Yep. Enforcing this kind of things is not something we do currently. But we probably should. We would need to know the precedence of dist tags though ( |
Shouldn't it be |
My mistake, I said branch but I meant dist-tag. We are checking the dist-tag not the branch to determine if we do a github pre-release or not. So the default should be Ok for |
I've just created another PR. I believe this one might be closed. |
Thanks so much ! I'll review shortly |
It's just a simple change, but as mentioned in #97, this PR should make GitHub releases use a custom tag whenever defined - just as it happens with npm release.
Does it need anything else? @gr2m said something about resetting the tag. I wonder if that's really needed.
I have noticed the tests (even before the changes) fail though. Seems to be an issue in plugins?