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

Add -latest flag to specify latest release or not #152

Merged
merged 4 commits into from
Oct 14, 2024

Conversation

danudey
Copy link
Contributor

@danudey danudey commented Sep 8, 2023

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

@Songmu
Copy link
Collaborator

Songmu commented Oct 12, 2023

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.

@danudey
Copy link
Contributor Author

danudey commented Oct 20, 2023

Rebased from current master

@danudey
Copy link
Contributor Author

danudey commented Nov 22, 2023

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.

@schneiderl
Copy link

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

@Songmu
Copy link
Collaborator

Songmu commented Oct 1, 2024

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

@Songmu Songmu merged commit 2c84f8d into tcnksm:master Oct 14, 2024
@github-actions github-actions bot mentioned this pull request Oct 14, 2024
@Songmu
Copy link
Collaborator

Songmu commented Oct 14, 2024

Good! Thank you.

@Songmu Songmu added the minor label Oct 14, 2024
@Songmu
Copy link
Collaborator

Songmu commented Oct 14, 2024

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

@schneiderl
Copy link

thanks @Songmu @danudey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants