ghr
ghr copied to clipboard
Add -latest flag to specify latest release or not
By default, creating a new release automatically sets the new release as the 'latest'. For repositories which maintain multiple version streams (e.g. v3.25.x and v3.26.x), this can result in setting the 'latest' version to the latest version of an older release stream.
Functionality
This PR adds the -latest flag, which accepts three options:
-
true
, the default, which always marks the release as the 'latest' -
false
, which never does -
auto
, which does the following:- Fetches the current 'latest' release from Github
- Compares the
tagName
from the latest release to thetagName
from the release we're about to try to create - If the new
tagName
is higher, set this release as the latest; otherwise, do not.
Even though I feel that auto
is the 'correct' (or, at least, more sensible) behavior, and probably should be the default, I made true
the default for two main reasons:
- It is the current behavior, and some users may rely on it
- If a user is not using semver tags, then it will fail with an error, and it won't be immediately obvious why.
New stuff
This PR has added some other internal functionality to the tool in order to support the auto
workflow:
-
GetLatestRelease()
was added, which simply fetches and returns the release marked as 'latest' from the project. Note that this is whichever release is marked as 'latest', and not the most recent release chronologically -
IsNewerSemverRelease()
was added, which accepts twogithub.RepositoryRelease
objects and returns whether the first is 'newer' than the second, based on semver comparisons of theirTagName
fields
Testing
Testing was run, including adding a new test, TestGHR_GetLatestRelease
, for GetLatestRelease()
.
Dependencies
Two changes were made to dependencies:
- The dependency on
github.com/google/go-github
was bumped from v47 to v55 (the latest) in order to get theMakeLatest
field ongithub.RepositoryRelease
, which was necessary for this feature - A new dependency on
github.com/thediveo/enumflag
was added, which provides functionality to set a command-line flag which is limited to the values in an enum (in this case, 'true', 'false', and 'auto')
Other notes
- This is my first contribution to a Golang project, and my first time using Golang, so if I've missed anything or if any of my code is non-idiomatic, please let me know. I'm happy to learn more about how to write good Golang and to collaborate effectively on Golang projects
- The
CREDITS
file seems to contain the licenses for every library this project uses, but I wasn't sure if this was generated automatically or not. I changed the version on thego-github
entry just as a reminder to myself, but if there's a specific way to update this file please let me know
Sorry for the delay; thanks for the pull request.
I understand the issue. It is reasonable. I will check the contents and let you know.
Rebased from current master
Sorry for the delay; thanks for the pull request.
I understand the issue. It is reasonable. I will check the contents and let you know.
@Songmu thanks for the update. Have you had a chance to take a look at the contents? I'm open to any feedback you may have.
hey @danudey @Songmu @tcnksm
any updates on this? it is a really cool feature and I'd love to see it getting merged 🥹
I have a use case where a new release containing assets is generated based on the original release, I'd like to see the original release being set as latest, not the assets one and I think this would solve that problem
Sorry for my slow response. I'll review it this weekend ant try to merge.
Good! Thank you.
Merged and released as v0.17.0. Thank you! @danudey @schneiderl
thanks @Songmu @danudey