mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-01 13:07:49 +02:00
checksumming wip
This commit is contained in:
parent
779a01d0dd
commit
a38ebfcc81
6
main.go
6
main.go
@ -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
|
||||
|
41
pipeline/checksums/checksums.go
Normal file
41
pipeline/checksums/checksums.go
Normal 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
|
||||
}
|
21
pipeline/checksums/checksums_test.go
Normal file
21
pipeline/checksums/checksums_test.go
Normal 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))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user