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

feat: output checksums to artifacts info #3548

Merged
merged 6 commits into from Nov 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions internal/pipe/checksums/checksums.go
Expand Up @@ -19,6 +19,10 @@ import (
"github.com/goreleaser/goreleaser/pkg/context"
)

const (
artifactChecksumExtra = "Checksum"
)

var (
errNoArtifacts = errors.New("there are no artifacts to sign")
lock sync.Mutex
Expand Down Expand Up @@ -137,11 +141,17 @@ func refresh(ctx *context.Context, filepath string) error {
return err
}

func checksums(algorithm string, artifact *artifact.Artifact) (string, error) {
log.WithField("file", artifact.Name).Debug("checksumming")
sha, err := artifact.Checksum(algorithm)
func checksums(algorithm string, a *artifact.Artifact) (string, error) {
log.WithField("file", a.Name).Debug("checksumming")
sha, err := a.Checksum(algorithm)
if err != nil {
return "", err
}
return fmt.Sprintf("%v %v\n", sha, artifact.Name), nil

if a.Extra == nil {
a.Extra = make(artifact.Extras)
}
a.Extra[artifactChecksumExtra] = fmt.Sprintf("%s:%s", algorithm, sha)

return fmt.Sprintf("%v %v\n", sha, a.Name), nil
}
13 changes: 13 additions & 0 deletions internal/pipe/checksums/checksums_test.go
Expand Up @@ -344,6 +344,19 @@ func TestPipeCheckSumsWithExtraFiles(t *testing.T) {
require.Contains(t, string(bts), "3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 "+want)
}
}

_ = ctx.Artifacts.Visit(func(a *artifact.Artifact) error {
if a.Path != file {
return nil
}
if len(tt.ids) > 0 {
return nil
}
checkSum, err := artifact.Extra[string](*a, artifactChecksumExtra)
require.Nil(t, err)
require.NotEmptyf(t, checkSum, "failed: %v", a.Path)
return nil
})
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pipe/docker/docker.go
Expand Up @@ -20,7 +20,7 @@ import (

const (
dockerConfigExtra = "DockerConfig"
dockerDigestExtra = "digest"
dockerDigestExtra = "Digest"

useBuildx = "buildx"
useDocker = "docker"
Expand Down