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

Use semver sort to determine latest upstream release in getExpectedTargetLatest #220

Merged
merged 9 commits into from
Jan 2, 2024

Conversation

guineveresaenger
Copy link
Contributor

@guineveresaenger guineveresaenger commented Dec 16, 2023

See #218 for details.

Uses the full json repo info payload to determine the latest upstream release.

See pulumi/pulumi-minio#251 for the fix applying to pulumi-minio specifically.

Fixes #218.
Fixes pulumi/pulumi-f5bigip#345
Fixes pulumi/pulumi-venafi#244

Reviewer Note: This functionality overrides the changes in #226. Note that we're returning an empty UpgradeTargetVersion in the case of a non-stable release, so that the nil check on Plan Provider Upgrade reports that we are up to date. A latest version with a beta tag should not fail the upgrade process; we should ignore it.

@guineveresaenger guineveresaenger requested review from iwahbe and a team December 16, 2023 00:15
@guineveresaenger guineveresaenger marked this pull request as draft December 28, 2023 02:37
@VenelinMartinov
Copy link
Contributor

Thanks for fixing the issue here! I'm not sure this is quite the right logic though. It looks to me like this change yields the following logic:
If latest is a beta, do not upgrade.
This is not the correct behaviour in the following example:
1.2-beta latest
1.1
1.0 (current)

We would not upgrade to 1.1 as we should.

Should we instead get the latest version by ordering the list from gh releases?

@guineveresaenger
Copy link
Contributor Author

guineveresaenger commented Dec 28, 2023

I mean, this is all trying to make up for inconsistent human behavior around setting release standards.

Do we think the latest means anything? It sounds like we do not trust upstream to use GitHub latest consistently, as evidenced by a non-stable version being marked as latest on the postgresql provider.

However, I think the case you describe is unlikely:

Likely, what happened here is that a maintainer failed to check "Set as pre-release" when they published their beta version. I would be surprised to see a stable release not setting github latest by default. (It's not impossible).

The reason why I prefer checking things in this way is that there have been several issues in this tool with hand ordering tags, and asking for "what is latest on github" is pretty foolproof from an implementation perspective.

I would argue it is reasonable to assume latest is good, and guard for accidental latest-has-a-prerelease-semver by ignoring it.

edited to add: gh release list does return releases in order...of publish date. This means that the current logic as-is is also potentially broken because it is of course possible to publish a newer-by-date release with an older-by-semver release tag.

@guineveresaenger
Copy link
Contributor Author

Alright I spoke with @iwahbe about this.

Because (github)latest moves and we only check for updates once a day, we may in fact miss "latest" versions due to latest moving on to a newer tag, and if that tag is not stable semver, we do not upgrade.

However, we also cannot use the first release from gh release list because those are ordered by publish date, not by semver.

We will do a best-attempt semver comparison of the default result of gh release list (30 most recent releases).

...I do not like this. But it is the least lossy option we have. :(

@guineveresaenger guineveresaenger marked this pull request as ready for review December 28, 2023 22:52
@guineveresaenger
Copy link
Contributor Author

An upgrade issue with the correct upstream version was opened successfully using this code.

@guineveresaenger guineveresaenger changed the title Use latestRelease func to determine latest upstream release in getExpectedTargetLatest Use semver sort to determine latest upstream release in getExpectedTargetLatest Dec 28, 2023
@guineveresaenger
Copy link
Contributor Author

Hm, the lack of json output is extremely unfortunate. Adjusting to split lines by tab instead to ensure we don't wind up with "Terraform" as our release tag when there is whitespace in release names. This should fix this failure.

gh release list --repo=F5Networks/terraform-provider-bigip --exclude-drafts --exclude-pre-releases
TITLE                              TYPE    TAG NAME  PUBLISHED
Terraform Provider BIG-IP v1.20.1  Latest  v1.20.1   about 1 month ago
Terraform Provider BIG-IP v1.20.0          v1.20.0   about 2 months ago
Terraform Provider BIG-IP v1.19.0          v1.19.0   about 4 months ago
Terraform Provider BIG-IP v1.18.1          v1.18.1   about 5 months ago
Terraform Provider BIG-IP v1.18.0          v1.18.0   about 6 months ago
Terraform Provider BIG-IP v1.17.1          v1.17.1   about 8 months ago
Terraform Provider BIG-IP v1.17.0          v1.17.0   about 9 months ago
Terraform Provider BIG-IP v1.16.2          v1.16.2   about 11 months ago
Terraform Provider BIG-IP v1.16.1          v1.16.1   about 1 year ago
Terraform Provider BIG-IP v1.16.0          v1.16.0   about 1 year ago
Terraform Provider BIG-IP v1.15.2          v1.15.2   about 1 year ago

upstreamOrg, GetContext(ctx).UpstreamProviderName)
// Sort the versions.
// Documentation here: https://pkg.go.dev/github.com/Masterminds/semver/v3#readme-sorting-semantic-versions
sort.Sort(semver.Collection(versions))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@guineveresaenger guineveresaenger merged commit 7625453 into main Jan 2, 2024
1 check passed
@guineveresaenger guineveresaenger deleted the guin/fix-latest-upstream branch January 2, 2024 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants