diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index f7e62a7017..e501692a22 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -33,6 +33,11 @@ jobs: # cribbed from https://gist.github.com/Syeberman/39d81b1e17d091be5657ecd6fbff0753 eval $(go env | sed -r 's/^(set )?(\w+)=("?)(.*)\3$/\2="\4"/gm') + # Check that building without push prints the tag (and sha) + KO_DOCKER_REPO="" go run ./ build --push=false ./test | grep ":latest@sha256:" + KO_DOCKER_REPO="" go run ./ build --push=false -t test ./test | grep ":test@sha256:" + KO_DOCKER_REPO="" go run ./ build --push=false -t test --tag-only ./test | grep ":test$" + export PLATFORM=${GOOS}/${GOARCH} if [[ "${{ matrix.platform }}" == "windows-latest" ]]; then diff --git a/pkg/commands/resolver.go b/pkg/commands/resolver.go index 3c233f29d9..451857fadf 100644 --- a/pkg/commands/resolver.go +++ b/pkg/commands/resolver.go @@ -224,9 +224,16 @@ func makePublisher(po *options.PublishOptions) (publish.Interface, error) { // If not publishing, at least generate a digest to simulate // publishing. if len(publishers) == 0 { + // If one or more tags are specified, use the first tag in the list + var tag string + if len(po.Tags) >= 1 { + tag = po.Tags[0] + } publishers = append(publishers, nopPublisher{ repoName: repoName, namer: namer, + tag: tag, + tagOnly: po.TagOnly, }) } @@ -256,15 +263,27 @@ func makePublisher(po *options.PublishOptions) (publish.Interface, error) { type nopPublisher struct { repoName string namer publish.Namer + tag string + tagOnly bool } func (n nopPublisher) Publish(_ context.Context, br build.Result, s string) (name.Reference, error) { s = strings.TrimPrefix(s, build.StrictScheme) + nm := n.namer(n.repoName, s) + if n.tagOnly { + if n.tag == "" { + return nil, errors.New("must specify tag if requesting tag only") + } + return name.NewTag(fmt.Sprintf("%s:%s", nm, n.tag)) + } h, err := br.Digest() if err != nil { return nil, err } - return name.NewDigest(fmt.Sprintf("%s@%s", n.namer(n.repoName, s), h)) + if n.tag == "" { + return name.NewDigest(fmt.Sprintf("%s@%s", nm, h)) + } + return name.NewDigest(fmt.Sprintf("%s:%s@%s", nm, n.tag, h)) } func (n nopPublisher) Close() error { return nil }