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

fix: detect updates for containerd #68

Merged
merged 1 commit into from
Jul 19, 2021
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
32 changes: 18 additions & 14 deletions internal/pkg/update/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func (g *gitHub) Latest(ctx context.Context, source string) (*LatestInfo, error)
}

// findLatestRelease returns information about latest released version.
//
//nolint:gocyclo
func (g *gitHub) findLatestRelease(releases []*github.RepositoryRelease, sourceURL *url.URL, considerPrereleases bool) (*LatestInfo, error) {
parts := strings.Split(sourceURL.Path, "/")
owner, repo := parts[1], parts[2]
Expand Down Expand Up @@ -116,26 +118,28 @@ func (g *gitHub) findLatestRelease(releases []*github.RepositoryRelease, sourceU

source := sourceURL.String()

// treat releases without extra assets as tags
if len(newest.Assets) == 0 {
// update is available if the release doesn't have the same tarball URL
res.LatestURL = g.getTagGZ(owner, repo, newest.GetTagName())
res.HasUpdate = res.LatestURL != source

return res, nil
}

// update is available if the newest release doesn't have source in their assets download URLs
for _, asset := range newest.Assets {
if asset.GetBrowserDownloadURL() == source {
res.HasUpdate = false
res.LatestURL = source

return res, nil
}
}

// we don't know correct asset URL
// check default .tag.gz URL
latestTarGz := g.getTagTarGZ(owner, repo, newest.GetTagName())
if latestTarGz == source {
res.LatestURL = source

return res, nil
}

// we don't know correct asset if there are any
if len(newest.Assets) == 0 {
res.LatestURL = latestTarGz
}

res.HasUpdate = true

return res, nil
Expand Down Expand Up @@ -179,7 +183,7 @@ func (g *gitHub) findLatestTag(ctx context.Context, tags []*github.RepositoryTag

res := &LatestInfo{
BaseURL: fmt.Sprintf("https://github.com/%s/%s/releases/", owner, repo),
LatestURL: g.getTagGZ(owner, repo, newest.GetName()),
LatestURL: g.getTagTarGZ(owner, repo, newest.GetName()),
}

// update is available if the newest tag doesn't have the same tarball URL
Expand Down Expand Up @@ -251,9 +255,9 @@ func (g *gitHub) getCommitTime(ctx context.Context, owner, repo, sha string) (ti
return t, nil
}

// getTagTarball returns .tar.gz URL.
// getTagTarGZ returns .tar.gz URL.
// API's GetTarballURL is not good enough.
func (g *gitHub) getTagGZ(owner, repo, name string) string {
func (g *gitHub) getTagTarGZ(owner, repo, name string) string {
return fmt.Sprintf("https://github.com/%s/%s/archive/refs/tags/%s.tar.gz", owner, repo, name)
}

Expand Down
14 changes: 13 additions & 1 deletion internal/pkg/update/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestLatestGithub(t *testing.T) {
LatestURL: "https://github.com/protocolbuffers/protobuf/releases/download/v3.17.3/protobuf-cpp-3.17.3.tar.gz",
},

// https://github.com/opencontainers/runc/releases has releases with extra assets (and no version in the file name).
// https://github.com/opencontainers/runc/releases has releases with extra assets and no version in the file name.
"https://github.com/opencontainers/runc/releases/download/v1.0.0/runc.tar.xz": {
HasUpdate: true,
BaseURL: "https://github.com/opencontainers/runc/releases/",
Expand All @@ -70,6 +70,18 @@ func TestLatestGithub(t *testing.T) {
BaseURL: "https://github.com/opencontainers/runc/releases/",
LatestURL: "https://github.com/opencontainers/runc/releases/download/v1.0.1/runc.tar.xz",
},

// https://github.com/containerd/containerd/releases has releases with extra assets that we don't use.
"https://github.com/containerd/containerd/archive/refs/tags/v1.5.2.tar.gz": {
HasUpdate: true,
BaseURL: "https://github.com/containerd/containerd/releases/",
LatestURL: "",
},
"https://github.com/containerd/containerd/archive/refs/tags/v1.5.3.tar.gz": {
HasUpdate: false,
BaseURL: "https://github.com/containerd/containerd/releases/",
LatestURL: "https://github.com/containerd/containerd/archive/refs/tags/v1.5.3.tar.gz",
},
} {
source, expected := source, expected

Expand Down