1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-01 13:07:49 +02:00

checksumming wip

This commit is contained in:
Carlos Alexandro Becker 2017-04-14 13:31:47 -03:00
parent 779a01d0dd
commit a38ebfcc81
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
3 changed files with 66 additions and 2 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/goreleaser/goreleaser/pipeline/archive"
"github.com/goreleaser/goreleaser/pipeline/brew"
"github.com/goreleaser/goreleaser/pipeline/build"
"github.com/goreleaser/goreleaser/pipeline/checksums"
"github.com/goreleaser/goreleaser/pipeline/defaults"
"github.com/goreleaser/goreleaser/pipeline/env"
"github.com/goreleaser/goreleaser/pipeline/fpm"
@ -87,8 +88,9 @@ func pipes(buildOnly bool) []pipeline.Pipe {
if !buildOnly {
pipes = append(
pipes,
release.Pipe{}, // release to github
brew.Pipe{}, // push to brew tap
checksums.Pipe{}, // checksums of the files
release.Pipe{}, // release to github
brew.Pipe{}, // push to brew tap
)
}
return pipes

View File

@ -0,0 +1,41 @@
package checksums
import (
"os"
"path/filepath"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/sha256sum"
)
// Pipe for checksums
type Pipe struct{}
// Description of the pipe
func (Pipe) Description() string {
return "Calculating checksums"
}
// Run the pipe
func (Pipe) Run(ctx *context.Context) (err error) {
file, err := os.OpenFile(
filepath.Join(ctx.Config.Dist, "CHECKSUMS.txt"),
os.O_APPEND|os.O_WRONLY|os.O_CREATE,
0600,
)
if err != nil {
return
}
defer func() { _ = file.Close() }()
for _, artifact := range ctx.Artifacts {
sha, err := sha256sum.For(filepath.Join(ctx.Config.Dist, artifact))
if err != nil {
return err
}
if _, err = file.WriteString(artifact + " sha256sum: " + sha + "\n"); err != nil {
return err
}
}
ctx.AddArtifact(file.Name())
return
}

View File

@ -0,0 +1,21 @@
package checksums
import (
"testing"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/stretchr/testify/assert"
)
func TestDescription(t *testing.T) {
assert.NotEmpty(t, Pipe{}.Description())
}
func TestBlah(t *testing.T) {
var assert = assert.New(t)
var ctx = &context.Context{
Config: config.Project{},
}
assert.NoError(Pipe{}.Run(ctx))
}