ghr icon indicating copy to clipboard operation
ghr copied to clipboard

Add -latest flag to specify latest release or not

Open danudey opened this issue 1 year ago • 3 comments

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:
    1. Fetches the current 'latest' release from Github
    2. Compares the tagName from the latest release to the tagName from the release we're about to try to create
    3. 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:

  1. It is the current behavior, and some users may rely on it
  2. 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:

  1. 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
  2. IsNewerSemverRelease() was added, which accepts two github.RepositoryRelease objects and returns whether the first is 'newer' than the second, based on semver comparisons of their TagName fields

Testing

Testing was run, including adding a new test, TestGHR_GetLatestRelease, for GetLatestRelease().

Dependencies

Two changes were made to dependencies:

  1. The dependency on github.com/google/go-github was bumped from v47 to v55 (the latest) in order to get the MakeLatest field on github.RepositoryRelease, which was necessary for this feature
  2. 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 the go-github entry just as a reminder to myself, but if there's a specific way to update this file please let me know

danudey avatar Sep 08 '23 20:09 danudey

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 avatar Oct 12 '23 01:10 Songmu

Rebased from current master

danudey avatar Oct 20 '23 17:10 danudey

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.

danudey avatar Nov 22 '23 19:11 danudey

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

schneiderl avatar Oct 01 '24 13:10 schneiderl

Sorry for my slow response. I'll review it this weekend ant try to merge.

Songmu avatar Oct 01 '24 16:10 Songmu

Good! Thank you.

Songmu avatar Oct 14 '24 13:10 Songmu

Merged and released as v0.17.0. Thank you! @danudey @schneiderl

Songmu avatar Oct 14 '24 14:10 Songmu

thanks @Songmu @danudey

schneiderl avatar Oct 14 '24 17:10 schneiderl