Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,3 @@ release:
prerelease: auto
draft: true
name_template: "{{ .Tag }}"

# We deploy a flag to a bucket that will be checked regularly by the CLI in the wild to check whether a new version is available.
blobs:
- provider: s3
endpoint: s3.fr-par.scw.cloud
bucket: scw-devtools
folder: "/"
extra_files:
- glob: scw-cli-v2-version
ids:
- binaries
15 changes: 12 additions & 3 deletions internal/core/build_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (b *BuildInfo) MarshalJSON() ([]byte, error) {

const (
scwDisableCheckVersionEnv = "SCW_DISABLE_CHECK_VERSION"
latestVersionFileURL = "https://scw-devtools.s3.nl-ams.scw.cloud/scw-cli-v2-version"
latestGithubReleaseURL = "https://api.github.com/repos/scaleway/scaleway-cli/releases/latest"
latestVersionUpdateFileLocalName = "latest-cli-version"
latestVersionRequestTimeout = 1 * time.Second
userAgentPrefix = "scaleway-cli"
Expand Down Expand Up @@ -100,7 +100,7 @@ func getLatestVersion(client *http.Client) (*version.Version, error) {
ctx, cancelTimeout := context.WithTimeout(context.Background(), latestVersionRequestTimeout)
defer cancelTimeout()

req, err := http.NewRequestWithContext(ctx, http.MethodGet, latestVersionFileURL, nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, latestGithubReleaseURL, nil)
if err != nil {
return nil, err
}
Expand All @@ -116,7 +116,16 @@ func getLatestVersion(client *http.Client) (*version.Version, error) {
return nil, err
}

return version.NewSemver(strings.Trim(string(body), "\n"))
jsonBody := struct {
TagName string `json:"tag_name"`
}{}

err = json.Unmarshal(body, &jsonBody)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal version from remote: %w", err)
}

return version.NewSemver(strings.TrimPrefix(jsonBody.TagName, "v"))
}

// wasFileModifiedLast24h checks whether the file has been updated during last 24 hours.
Expand Down
4 changes: 2 additions & 2 deletions internal/core/build_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Test_CheckVersion(t *testing.T) {
Cmd: "scw plop",
Check: TestCheckCombine(
func(t *testing.T, ctx *CheckFuncCtx) {
assert.Equal(t, "a new version of scw is available (2.0.0-beta.4), beware that you are currently running 1.20.0\n", ctx.LogBuffer)
assert.Equal(t, "a new version of scw is available (2.5.4), beware that you are currently running 1.20.0\n", ctx.LogBuffer)
},
),
TmpHomeDir: true,
Expand Down Expand Up @@ -85,7 +85,7 @@ func Test_CheckVersion(t *testing.T) {
Cmd: "scw plop",
Check: TestCheckCombine(
func(t *testing.T, ctx *CheckFuncCtx) {
assert.Contains(t, ctx.LogBuffer, "a new version of scw is available (2.0.0-beta.4), beware that you are currently running 1.0.0\n")
assert.Contains(t, ctx.LogBuffer, "a new version of scw is available (2.5.4), beware that you are currently running 1.0.0\n")
},
),
TmpHomeDir: true,
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.