mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
64b1f14a86
* refactor: merging archive in the same repo * refactor: merging archive in the same repo * refactor: better organizing packages * refactor: fixing renames * fix: new dep version * fix: makefile * fix: zip/tar tests * fix: gitigonore * fix: s3 tests * fix: archive test
95 lines
2.3 KiB
Go
95 lines
2.3 KiB
Go
package release
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/apex/log"
|
|
|
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
|
"github.com/goreleaser/goreleaser/internal/client"
|
|
"github.com/goreleaser/goreleaser/internal/pipeline"
|
|
"github.com/goreleaser/goreleaser/internal/semerrgroup"
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
)
|
|
|
|
// Pipe for github release
|
|
type Pipe struct{}
|
|
|
|
func (Pipe) String() string {
|
|
return "releasing to GitHub"
|
|
}
|
|
|
|
// Default sets the pipe defaults
|
|
func (Pipe) Default(ctx *context.Context) error {
|
|
if ctx.Config.Release.Disable {
|
|
return nil
|
|
}
|
|
if ctx.Config.Release.NameTemplate == "" {
|
|
ctx.Config.Release.NameTemplate = "{{.Tag}}"
|
|
}
|
|
if ctx.Config.Release.GitHub.Name != "" {
|
|
return nil
|
|
}
|
|
repo, err := remoteRepo()
|
|
if err != nil && !ctx.Snapshot {
|
|
return err
|
|
}
|
|
ctx.Config.Release.GitHub = repo
|
|
return nil
|
|
}
|
|
|
|
// Run the pipe
|
|
func (Pipe) Run(ctx *context.Context) error {
|
|
c, err := client.NewGitHub(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return doRun(ctx, c)
|
|
}
|
|
|
|
func doRun(ctx *context.Context, c client.Client) error {
|
|
if ctx.Config.Release.Disable {
|
|
return pipeline.Skip("release pipe is disabled")
|
|
}
|
|
if ctx.SkipPublish {
|
|
return pipeline.ErrSkipPublishEnabled
|
|
}
|
|
log.WithField("tag", ctx.Git.CurrentTag).
|
|
WithField("repo", ctx.Config.Release.GitHub.String()).
|
|
Info("creating or updating release")
|
|
body, err := describeBody(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
releaseID, err := c.CreateRelease(ctx, body.String())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var g = semerrgroup.New(ctx.Parallelism)
|
|
for _, artifact := range ctx.Artifacts.Filter(
|
|
artifact.Or(
|
|
artifact.ByType(artifact.UploadableArchive),
|
|
artifact.ByType(artifact.UploadableBinary),
|
|
artifact.ByType(artifact.Checksum),
|
|
artifact.ByType(artifact.Signature),
|
|
artifact.ByType(artifact.LinuxPackage),
|
|
),
|
|
).List() {
|
|
artifact := artifact
|
|
g.Go(func() error {
|
|
return upload(ctx, c, releaseID, artifact)
|
|
})
|
|
}
|
|
return g.Wait()
|
|
}
|
|
|
|
func upload(ctx *context.Context, c client.Client, releaseID int64, artifact artifact.Artifact) error {
|
|
file, err := os.Open(artifact.Path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer file.Close() // nolint: errcheck
|
|
log.WithField("file", file.Name()).WithField("name", artifact.Name).Info("uploading to release")
|
|
return c.Upload(ctx, releaseID, artifact.Name, file)
|
|
}
|