1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/release/release.go

70 lines
1.6 KiB
Go
Raw Normal View History

2017-04-14 20:39:32 +02:00
// Package release implements Pipe and manages github releases and its
// artifacts.
2016-12-29 02:23:39 +02:00
package release
2016-12-29 03:21:49 +02:00
import (
"os"
2017-01-30 02:33:08 +02:00
"path/filepath"
2016-12-29 03:21:49 +02:00
2017-06-22 05:09:14 +02:00
"github.com/apex/log"
2017-01-15 00:01:32 +02:00
"github.com/goreleaser/goreleaser/context"
2017-05-13 23:06:15 +02:00
"github.com/goreleaser/goreleaser/internal/client"
2016-12-29 18:17:49 +02:00
"golang.org/x/sync/errgroup"
2016-12-29 03:21:49 +02:00
)
2016-12-29 02:23:39 +02:00
2016-12-30 16:41:59 +02:00
// Pipe for github release
2016-12-30 13:27:35 +02:00
type Pipe struct{}
2017-01-14 20:41:32 +02:00
// Description of the pipe
2017-01-14 19:14:35 +02:00
func (Pipe) Description() string {
2017-01-19 11:04:41 +02:00
return "Releasing to GitHub"
2016-12-30 13:27:35 +02:00
}
2016-12-30 16:41:59 +02:00
// Run the pipe
2017-01-14 18:06:57 +02:00
func (Pipe) Run(ctx *context.Context) error {
2017-04-14 21:07:27 +02:00
return doRun(ctx, client.NewGitHub(ctx))
2017-03-26 20:56:35 +02:00
}
2017-04-14 21:07:27 +02:00
func doRun(ctx *context.Context, client client.Client) error {
if !ctx.Publish {
2017-06-22 15:47:34 +02:00
log.Warn("skipped because --skip-publish is set")
return nil
}
2017-06-22 05:09:14 +02:00
log.WithField("tag", ctx.Git.CurrentTag).
WithField("repo", ctx.Config.Release.GitHub.String()).
2017-06-22 15:47:34 +02:00
Info("creating or updating release")
2017-04-19 22:12:12 +02:00
body, err := describeBody(ctx)
2017-04-19 21:59:26 +02:00
if err != nil {
return err
}
releaseID, err := client.CreateRelease(ctx, body.String())
2016-12-29 03:21:49 +02:00
if err != nil {
return err
}
2016-12-29 18:17:49 +02:00
var g errgroup.Group
2017-07-15 21:49:52 +02:00
sem := make(chan bool, ctx.Parallelism)
for _, artifact := range ctx.Artifacts {
2017-07-05 03:00:48 +02:00
sem <- true
artifact := artifact
2017-01-14 16:55:52 +02:00
g.Go(func() error {
2017-07-05 03:00:48 +02:00
defer func() {
<-sem
}()
return upload(ctx, client, releaseID, artifact)
2017-01-14 16:55:52 +02:00
})
2016-12-29 03:21:49 +02:00
}
2016-12-29 18:17:49 +02:00
return g.Wait()
2016-12-29 02:23:39 +02:00
}
2016-12-29 03:21:49 +02:00
2017-04-14 21:07:27 +02:00
func upload(ctx *context.Context, client client.Client, releaseID int, artifact string) error {
var path = filepath.Join(ctx.Config.Dist, artifact)
2017-01-30 02:33:08 +02:00
file, err := os.Open(path)
2016-12-29 03:21:49 +02:00
if err != nil {
return err
}
2017-01-14 16:55:52 +02:00
defer func() { _ = file.Close() }()
2017-07-05 02:28:21 +02:00
_, name := filepath.Split(path)
log.WithField("file", file.Name()).WithField("name", name).Info("uploading to release")
return client.Upload(ctx, releaseID, name, file)
2016-12-29 03:21:49 +02:00
}