minamijoyo / tfupdate

Update version constraints in your Terraform configurations
MIT License
542 stars 23 forks source link

The latest release in GitHub just means the most recent release, not the latest stable release #36

Closed minamijoyo closed 3 years ago

minamijoyo commented 3 years ago

I noticed that the tfupdate suggested downgrading to v0.11.15 a few days ago. That's a funny joke. I live in 2021. 😂

https://github.com/minamijoyo/tfupdate-circleci-example/pull/158

The latest release should be v0.15.1, but the v0.11.15 is marked as the latest.

$ tfupdate -v
0.4.3

$ tfupdate release latest hashicorp/terraform
0.11.15

$ curl -s -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/hashicorp/terraform/releases/latest | jq -r .tag_name
v0.11.15

I found an upstream issue: https://github.com/hashicorp/terraform/issues/28530

Apparently I misunderstood the meaning of the latest release in GitHub. The latest release just means the most recent release, not the latest stable release.

We should not use the GetLatestRelease API in GitHub. We need to get all releases, sort them in the semver order and find the latest stable release.

As a workaround, we can use the git command, which allows us to sort the tags in the semver order.

$ git -c 'versionsort.suffix=-' ls-remote --refs --tags --sort='v:refname' https://github.com/hashicorp/terraform | tail -n 1 | cut -d'/' -f3 | sed s/^v//
0.15.1
minamijoyo commented 3 years ago

I fixed an example using git as the workaround. https://github.com/minamijoyo/tfupdate-circleci-example/pull/159

minamijoyo commented 3 years ago

Fixed in v0.5.0