1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-26 04:22:05 +02:00

94 lines
2.1 KiB
Go
Raw Normal View History

2016-12-28 22:23:39 -02:00
package release
2016-12-28 23:21:49 -02:00
import (
"os"
2017-12-17 16:59:54 -02:00
2017-06-22 00:09:14 -03:00
"github.com/apex/log"
2017-12-18 00:53:48 -02:00
"golang.org/x/sync/errgroup"
2017-01-14 20:01:32 -02:00
"github.com/goreleaser/goreleaser/context"
2017-12-18 00:53:48 -02:00
"github.com/goreleaser/goreleaser/internal/artifact"
2017-05-13 18:06:15 -03:00
"github.com/goreleaser/goreleaser/internal/client"
2017-08-20 16:35:46 -03:00
"github.com/goreleaser/goreleaser/pipeline"
2016-12-28 23:21:49 -02:00
)
2016-12-28 22:23:39 -02:00
2016-12-30 12:41:59 -02:00
// Pipe for github release
2016-12-30 09:27:35 -02:00
type Pipe struct{}
func (Pipe) String() string {
return "releasing to GitHub"
2016-12-30 09:27:35 -02:00
}
// Default sets the pipe defaults
func (Pipe) Default(ctx *context.Context) error {
if ctx.Config.Release.NameTemplate == "" {
ctx.Config.Release.NameTemplate = "{{.Tag}}"
}
if ctx.Config.Release.GitHub.Name != "" {
return nil
}
repo, err := remoteRepo()
if err != nil {
return err
}
ctx.Config.Release.GitHub = repo
return nil
}
2017-12-17 16:59:54 -02:00
// 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.Publish {
2018-01-10 19:22:37 -02:00
return pipeline.ErrSkipPublish
}
2017-06-22 00:09:14 -03:00
log.WithField("tag", ctx.Git.CurrentTag).
WithField("repo", ctx.Config.Release.GitHub.String()).
2017-06-22 10:47:34 -03:00
Info("creating or updating release")
2017-04-19 17:12:12 -03:00
body, err := describeBody(ctx)
2017-04-19 16:59:26 -03:00
if err != nil {
return err
}
releaseID, err := c.CreateRelease(ctx, body.String())
2016-12-28 23:21:49 -02:00
if err != nil {
return err
}
2016-12-29 14:17:49 -02:00
var g errgroup.Group
2017-07-15 16:49:52 -03:00
sem := make(chan bool, ctx.Parallelism)
2017-12-17 16:59:54 -02:00
for _, artifact := range ctx.Artifacts.Filter(
artifact.Or(
artifact.ByType(artifact.UploadableArchive),
artifact.ByType(artifact.UploadableBinary),
artifact.ByType(artifact.Checksum),
2017-12-17 19:16:25 -02:00
artifact.ByType(artifact.Signature),
2017-12-17 21:26:03 -02:00
artifact.ByType(artifact.LinuxPackage),
2017-12-17 16:59:54 -02:00
),
).List() {
2017-07-04 22:00:48 -03:00
sem <- true
artifact := artifact
2017-01-14 12:55:52 -02:00
g.Go(func() error {
2017-07-04 22:00:48 -03:00
defer func() {
<-sem
}()
return upload(ctx, c, releaseID, artifact)
2017-01-14 12:55:52 -02:00
})
2016-12-28 23:21:49 -02:00
}
2016-12-29 14:17:49 -02:00
return g.Wait()
2016-12-28 22:23:39 -02:00
}
2016-12-28 23:21:49 -02:00
2017-12-17 16:59:54 -02:00
func upload(ctx *context.Context, c client.Client, releaseID int, artifact artifact.Artifact) error {
file, err := os.Open(artifact.Path)
2016-12-28 23:21:49 -02:00
if err != nil {
return err
}
2017-12-17 23:04:29 -02:00
defer file.Close() // nolint: errcheck
2017-12-17 16:59:54 -02:00
log.WithField("file", file.Name()).WithField("name", artifact.Name).Info("uploading to release")
return c.Upload(ctx, releaseID, artifact.Name, file)
2016-12-28 23:21:49 -02:00
}