Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI=
Comment thread
pkwarren marked this conversation as resolved.
Outdated
golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
34 changes: 32 additions & 2 deletions internal/cmd/release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io/fs"
"log/slog"
"net/http"
"os"
"os/exec"
"path/filepath"
Expand All @@ -22,6 +23,7 @@ import (
githubkeychain "github.com/google/go-containerregistry/pkg/authn/github"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/remote/transport"
"github.com/google/go-github/v72/github"
"github.com/spf13/pflag"
"golang.org/x/mod/semver"
Expand Down Expand Up @@ -590,12 +592,32 @@ func (c *command) pluginReleasesURL(releaseName string) string {

func fetchRegistryImageAndImageID(plugin *plugin.Plugin) (string, string, error) {
identity := plugin.Identity
imageName := fmt.Sprintf("ghcr.io/%s/plugins-%s-%s:%s", release.GithubOwnerBufbuild, identity.Owner(), identity.Plugin(), plugin.PluginVersion)
imageName := fmt.Sprintf(
"ghcr.io/%s/plugins-%s-%s:%s",
release.GithubOwnerBufbuild,
identity.Owner(),
identity.Plugin(),
plugin.PluginVersion,
)
registryImage, imageID, err := fetchImageAndImageIDFromRegistry(
imageName,
remote.WithAuthFromKeychain(githubkeychain.Keychain),
)
if err != nil {
if isImageNotFoundError(err) {
return "", "", nil
}
return "", "", err
}
return registryImage, imageID, nil
}

func fetchImageAndImageIDFromRegistry(imageName string, options ...remote.Option) (string, string, error) {
parsedName, err := name.ParseReference(imageName)
if err != nil {
return "", "", err
}
remoteImage, err := remote.Image(parsedName, remote.WithAuthFromKeychain(githubkeychain.Keychain))
remoteImage, err := remote.Image(parsedName, options...)
if err != nil {
return "", "", err
}
Expand All @@ -609,3 +631,11 @@ func fetchRegistryImageAndImageID(plugin *plugin.Plugin) (string, string, error)
}
return fmt.Sprintf("%s@%s", imageName, remoteDigest.String()), manifest.Config.Digest.String(), nil
}

func isImageNotFoundError(err error) bool {
var transportErr *transport.Error
if !errors.As(err, &transportErr) {
return false
}
return transportErr.StatusCode == http.StatusNotFound
}
Loading