mirror of
https://github.com/goreleaser/goreleaser.git
synced 2026-06-19 23:24:39 +02:00
feat: output checksums to artifacts info (#3548)
Following #3540, output artifacts' checksums to the artifact info. This addition makes it easier to consume the checksums, especially when running from e.g. GitHub Actions. New tests: 1. Add a check for the checksum in the extra field. 2. Add a test for every checksum algorithm (to see that it doesn't break for any algo's output). 3. Add a case of a binary and an extra file (to see that the logic doesn't break when there's a mix). p.s. While working on that, I noticed that the convention for extra fields is actually to use UpperCamelCase rather than lower. I was mistaken because I looked at the subfields of the "DockerConfig" extra field. I think it's a good idea to fix it quickly, before the next release rolls and it becomes a compatibility issue. I took the liberty to fix it here as an extra commit. Please let me know if you want it to be in a separate PR. --- Tests: ``` go test • refreshing checksums file=binary_bar_checksums.txt • refreshing checksums file=binary_bar_checksums.txt • refreshing checksums file=binary_bar_checksums.txt PASS ok github.com/goreleaser/goreleaser/internal/pipe/checksums 0.184s ``` Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
co-authored by
Carlos Alexandro Becker
parent
6df90e578a
commit
76dc0b559e
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
|
||||
const (
|
||||
dockerConfigExtra = "DockerConfig"
|
||||
dockerDigestExtra = "digest"
|
||||
dockerDigestExtra = "Digest"
|
||||
|
||||
useBuildx = "buildx"
|
||||
useDocker = "docker"
|
||||
|
||||
Reference in New Issue
Block a user