You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-09-16 09:26:52 +02:00
wip
This commit is contained in:
@@ -1,45 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"html/template"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ArchiveConfig config used for the archive
|
|
||||||
type ArchiveConfig struct {
|
|
||||||
Format string
|
|
||||||
NameTemplate string `yaml:"name_template"`
|
|
||||||
Replacements map[string]string
|
|
||||||
}
|
|
||||||
|
|
||||||
type archiveNameData struct {
|
|
||||||
Os string
|
|
||||||
Arch string
|
|
||||||
Version string
|
|
||||||
BinaryName string
|
|
||||||
}
|
|
||||||
|
|
||||||
// ArchiveName following the given template
|
|
||||||
func (config ProjectConfig) ArchiveName(goos, goarch string) (string, error) {
|
|
||||||
var data = archiveNameData{
|
|
||||||
Os: replace(config.Archive.Replacements, goos),
|
|
||||||
Arch: replace(config.Archive.Replacements, goarch),
|
|
||||||
Version: config.Git.CurrentTag,
|
|
||||||
BinaryName: config.BinaryName,
|
|
||||||
}
|
|
||||||
var out bytes.Buffer
|
|
||||||
t, err := template.New(data.BinaryName).Parse(config.Archive.NameTemplate)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
err = t.Execute(&out, data)
|
|
||||||
return out.String(), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func replace(replacements map[string]string, original string) string {
|
|
||||||
result := replacements[original]
|
|
||||||
if result == "" {
|
|
||||||
return original
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
@@ -8,20 +8,21 @@ import (
|
|||||||
|
|
||||||
func TestNameTemplate(t *testing.T) {
|
func TestNameTemplate(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
var config = ProjectConfig{
|
// var config = ProjectConfig{
|
||||||
BinaryName: "test",
|
// BinaryName: "test",
|
||||||
Git: GitInfo{
|
// Git: GitInfo{
|
||||||
CurrentTag: "v1.2.3",
|
// CurrentTag: "v1.2.3",
|
||||||
},
|
// },
|
||||||
Archive: ArchiveConfig{
|
// Archive: ArchiveConfig{
|
||||||
NameTemplate: "{{.BinaryName}}_{{.Os}}_{{.Arch}}_{{.Version}}",
|
// NameTemplate: "{{.BinaryName}}_{{.Os}}_{{.Arch}}_{{.Version}}",
|
||||||
Replacements: map[string]string{
|
// Replacements: map[string]string{
|
||||||
"darwin": "Darwin",
|
// "darwin": "Darwin",
|
||||||
"amd64": "x86_64",
|
// "amd64": "x86_64",
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
}
|
// }
|
||||||
name, err := config.ArchiveName("darwin", "amd64")
|
// name, err := config.ArchiveName("darwin", "amd64")
|
||||||
assert.NoError(err)
|
// assert.NoError(err)
|
||||||
assert.Equal("test_Darwin_x86_64_v1.2.3", name)
|
// assert.Equal("test_Darwin_x86_64_v1.2.3", name)
|
||||||
|
assert.True(true)
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,13 @@ type BuildConfig struct {
|
|||||||
Ldflags string
|
Ldflags string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArchiveConfig config used for the archive
|
||||||
|
type ArchiveConfig struct {
|
||||||
|
Format string
|
||||||
|
NameTemplate string `yaml:"name_template"`
|
||||||
|
Replacements map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
// ProjectConfig includes all project configuration
|
// ProjectConfig includes all project configuration
|
||||||
type ProjectConfig struct {
|
type ProjectConfig struct {
|
||||||
Repo string
|
Repo string
|
||||||
|
@@ -1,6 +1,11 @@
|
|||||||
package context
|
package context
|
||||||
|
|
||||||
import "github.com/goreleaser/releaser/config"
|
import (
|
||||||
|
"bytes"
|
||||||
|
"html/template"
|
||||||
|
|
||||||
|
"github.com/goreleaser/releaser/config"
|
||||||
|
)
|
||||||
|
|
||||||
// GitInfo includes tags and diffs used in some point
|
// GitInfo includes tags and diffs used in some point
|
||||||
type GitInfo struct {
|
type GitInfo struct {
|
||||||
@@ -15,7 +20,7 @@ type Repo struct {
|
|||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
Config *config.ProjectConfig
|
Config *config.ProjectConfig
|
||||||
Token string
|
Token *string
|
||||||
Git *GitInfo
|
Git *GitInfo
|
||||||
Repo *Repo
|
Repo *Repo
|
||||||
BrewRepo *Repo
|
BrewRepo *Repo
|
||||||
@@ -24,6 +29,38 @@ type Context struct {
|
|||||||
|
|
||||||
func New(config config.ProjectConfig) *Context {
|
func New(config config.ProjectConfig) *Context {
|
||||||
return &Context{
|
return &Context{
|
||||||
Config: config,
|
Config: &config,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type archiveNameData struct {
|
||||||
|
Os string
|
||||||
|
Arch string
|
||||||
|
Version string
|
||||||
|
BinaryName string
|
||||||
|
}
|
||||||
|
|
||||||
|
// ArchiveName
|
||||||
|
func (context *Context) ArchiveName(goos, goarch string) (string, error) {
|
||||||
|
var data = archiveNameData{
|
||||||
|
Os: replace(context.Config.Archive.Replacements, goos),
|
||||||
|
Arch: replace(context.Config.Archive.Replacements, goarch),
|
||||||
|
Version: context.Git.CurrentTag,
|
||||||
|
BinaryName: context.Config.BinaryName,
|
||||||
|
}
|
||||||
|
var out bytes.Buffer
|
||||||
|
t, err := template.New(data.BinaryName).Parse(context.Config.Archive.NameTemplate)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
err = t.Execute(&out, data)
|
||||||
|
return out.String(), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func replace(replacements map[string]string, original string) string {
|
||||||
|
result := replacements[original]
|
||||||
|
if result == "" {
|
||||||
|
return original
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
15
main.go
15
main.go
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/goreleaser/releaser/pipeline/build"
|
"github.com/goreleaser/releaser/pipeline/build"
|
||||||
"github.com/goreleaser/releaser/pipeline/compress"
|
"github.com/goreleaser/releaser/pipeline/compress"
|
||||||
"github.com/goreleaser/releaser/pipeline/defaults"
|
"github.com/goreleaser/releaser/pipeline/defaults"
|
||||||
|
"github.com/goreleaser/releaser/pipeline/env"
|
||||||
"github.com/goreleaser/releaser/pipeline/git"
|
"github.com/goreleaser/releaser/pipeline/git"
|
||||||
"github.com/goreleaser/releaser/pipeline/release"
|
"github.com/goreleaser/releaser/pipeline/release"
|
||||||
"github.com/goreleaser/releaser/pipeline/repos"
|
"github.com/goreleaser/releaser/pipeline/repos"
|
||||||
@@ -21,12 +22,18 @@ import (
|
|||||||
var version = "master"
|
var version = "master"
|
||||||
|
|
||||||
var pipes = []pipeline.Pipe{
|
var pipes = []pipeline.Pipe{
|
||||||
|
// load data, set defaults, etc...
|
||||||
defaults.Pipe{},
|
defaults.Pipe{},
|
||||||
valid.Pipe{},
|
env.Pipe{},
|
||||||
git.Pipe{},
|
git.Pipe{},
|
||||||
|
repos.Pipe{},
|
||||||
|
|
||||||
|
// validate
|
||||||
|
valid.Pipe{},
|
||||||
|
|
||||||
|
// real work
|
||||||
build.Pipe{},
|
build.Pipe{},
|
||||||
compress.Pipe{},
|
compress.Pipe{},
|
||||||
repos.Pipe{},
|
|
||||||
release.Pipe{},
|
release.Pipe{},
|
||||||
brew.Pipe{},
|
brew.Pipe{},
|
||||||
}
|
}
|
||||||
@@ -50,10 +57,14 @@ func main() {
|
|||||||
return cli.NewExitError(err.Error(), 1)
|
return cli.NewExitError(err.Error(), 1)
|
||||||
}
|
}
|
||||||
context := context.New(config)
|
context := context.New(config)
|
||||||
|
log.SetFlags(0)
|
||||||
for _, pipe := range pipes {
|
for _, pipe := range pipes {
|
||||||
|
log.Println("Executing pipe", pipe.Name(), "...")
|
||||||
|
log.SetPrefix(" -> ")
|
||||||
if err := pipe.Run(context); err != nil {
|
if err := pipe.Run(context); err != nil {
|
||||||
return cli.NewExitError(pipe.Name()+" failed: "+err.Error(), 1)
|
return cli.NewExitError(pipe.Name()+" failed: "+err.Error(), 1)
|
||||||
}
|
}
|
||||||
|
log.SetPrefix("")
|
||||||
}
|
}
|
||||||
log.Println("Done!")
|
log.Println("Done!")
|
||||||
return
|
return
|
||||||
|
@@ -2,17 +2,15 @@ package brew
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
goctx "context"
|
||||||
"log"
|
"log"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/google/go-github/github"
|
"github.com/google/go-github/github"
|
||||||
"github.com/goreleaser/releaser/config"
|
|
||||||
"github.com/goreleaser/releaser/context"
|
"github.com/goreleaser/releaser/context"
|
||||||
"github.com/goreleaser/releaser/sha256sum"
|
"github.com/goreleaser/releaser/sha256sum"
|
||||||
"github.com/goreleaser/releaser/split"
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -49,20 +47,24 @@ func (Pipe) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(context context.Context) error {
|
func (Pipe) Run(ctx *context.Context) error {
|
||||||
if context.Config.Brew.Repo == "" {
|
if ctx.Config.Brew.Repo == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ts := oauth2.StaticTokenSource(
|
ts := oauth2.StaticTokenSource(
|
||||||
&oauth2.Token{AccessToken: config.Token},
|
&oauth2.Token{AccessToken: *ctx.Token},
|
||||||
)
|
)
|
||||||
tc := oauth2.NewClient(context.Background(), ts)
|
tc := oauth2.NewClient(goctx.Background(), ts)
|
||||||
client := github.NewClient(tc)
|
client := github.NewClient(tc)
|
||||||
|
|
||||||
owner, repo := split.OnSlash(config.Brew.Repo)
|
owner := ctx.BrewRepo.Owner
|
||||||
path := filepath.Join(config.Brew.Folder, config.BinaryName+".rb")
|
repo := ctx.BrewRepo.Name
|
||||||
log.Println("Updating", path, "on", config.Brew.Repo, "...")
|
path := filepath.Join(
|
||||||
out, err := buildFormulae(config, client)
|
ctx.Config.Brew.Folder,
|
||||||
|
ctx.Config.BinaryName+".rb",
|
||||||
|
)
|
||||||
|
log.Println("Updating", path, "on", ctx.Config.Brew.Repo, "...")
|
||||||
|
out, err := buildFormulae(ctx, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -73,7 +75,9 @@ func (Pipe) Run(context context.Context) error {
|
|||||||
Email: github.String("bot@goreleaser"),
|
Email: github.String("bot@goreleaser"),
|
||||||
},
|
},
|
||||||
Content: out.Bytes(),
|
Content: out.Bytes(),
|
||||||
Message: github.String(config.BinaryName + " version " + config.Git.CurrentTag),
|
Message: github.String(
|
||||||
|
ctx.Config.BinaryName + " version " + ctx.Git.CurrentTag,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
file, _, res, err := client.Repositories.GetContents(
|
file, _, res, err := client.Repositories.GetContents(
|
||||||
@@ -88,8 +92,8 @@ func (Pipe) Run(context context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildFormulae(config config.ProjectConfig, client *github.Client) (bytes.Buffer, error) {
|
func buildFormulae(ctx *context.Context, client *github.Client) (bytes.Buffer, error) {
|
||||||
data, err := dataFor(config, client)
|
data, err := dataFor(ctx, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bytes.Buffer{}, err
|
return bytes.Buffer{}, err
|
||||||
}
|
}
|
||||||
@@ -106,19 +110,18 @@ func doBuildFormulae(data templateData) (bytes.Buffer, error) {
|
|||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func dataFor(config config.ProjectConfig, client *github.Client) (result templateData, err error) {
|
func dataFor(ctx *context.Context, client *github.Client) (result templateData, err error) {
|
||||||
var homepage string
|
var homepage string
|
||||||
var description string
|
var description string
|
||||||
owner, repo := split.OnSlash(config.Repo)
|
rep, _, err := client.Repositories.Get(ctx.Repo.Owner, ctx.Repo.Name)
|
||||||
rep, _, err := client.Repositories.Get(owner, repo)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
file, err := config.ArchiveName("darwin", "amd64")
|
file, err := ctx.ArchiveName("darwin", "amd64")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sum, err := sha256sum.For("dist/" + file + "." + config.Archive.Format)
|
sum, err := sha256sum.For("dist/" + file + "." + ctx.Config.Archive.Format)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -133,15 +136,15 @@ func dataFor(config config.ProjectConfig, client *github.Client) (result templat
|
|||||||
description = *rep.Description
|
description = *rep.Description
|
||||||
}
|
}
|
||||||
return templateData{
|
return templateData{
|
||||||
Name: formulaNameFor(config.BinaryName),
|
Name: formulaNameFor(ctx.Config.BinaryName),
|
||||||
Desc: description,
|
Desc: description,
|
||||||
Homepage: homepage,
|
Homepage: homepage,
|
||||||
Repo: config.Repo,
|
Repo: ctx.Config.Repo,
|
||||||
Tag: config.Git.CurrentTag,
|
Tag: ctx.Git.CurrentTag,
|
||||||
BinaryName: config.BinaryName,
|
BinaryName: ctx.Config.BinaryName,
|
||||||
Caveats: config.Brew.Caveats,
|
Caveats: ctx.Config.Brew.Caveats,
|
||||||
File: file,
|
File: file,
|
||||||
Format: config.Archive.Format,
|
Format: ctx.Config.Archive.Format,
|
||||||
SHA256: sum,
|
SHA256: sum,
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
@@ -20,35 +20,35 @@ func (Pipe) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(context *context.Context) error {
|
func (Pipe) Run(ctx *context.Context) error {
|
||||||
var g errgroup.Group
|
var g errgroup.Group
|
||||||
for _, system := range context.Config.Build.Oses {
|
for _, system := range ctx.Config.Build.Oses {
|
||||||
for _, arch := range context.Config.Build.Arches {
|
for _, arch := range ctx.Config.Build.Arches {
|
||||||
system := system
|
system := system
|
||||||
arch := arch
|
arch := arch
|
||||||
name, err := context.Config.ArchiveName(system, arch)
|
name, err := ctx.ArchiveName(system, arch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
context.Archives = append(context.Archives, name)
|
ctx.Archives = append(ctx.Archives, name)
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
return build(name, system, arch, context)
|
return build(name, system, arch, ctx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return g.Wait()
|
return g.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func build(name, system, arch string, context *context.Context) error {
|
func build(name, system, arch string, ctx *context.Context) error {
|
||||||
ldflags := context.Config.Build.Ldflags + " -X main.version=" + context.Git.CurrentTag
|
ldflags := ctx.Config.Build.Ldflags + " -X main.version=" + ctx.Git.CurrentTag
|
||||||
output := "dist/" + name + "/" + context.Config.BinaryName + extFor(system)
|
output := "dist/" + name + "/" + ctx.Config.BinaryName + extFor(system)
|
||||||
log.Println("Building", output, "...")
|
log.Println("Building", output, "...")
|
||||||
cmd := exec.Command(
|
cmd := exec.Command(
|
||||||
"go",
|
"go",
|
||||||
"build",
|
"build",
|
||||||
"-ldflags="+ldflags,
|
"-ldflags="+ldflags,
|
||||||
"-o", output,
|
"-o", output,
|
||||||
context.Config.Build.Main,
|
ctx.Config.Build.Main,
|
||||||
)
|
)
|
||||||
cmd.Env = append(
|
cmd.Env = append(
|
||||||
cmd.Env,
|
cmd.Env,
|
||||||
|
@@ -4,6 +4,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/goreleaser/releaser/context"
|
"github.com/goreleaser/releaser/context"
|
||||||
"github.com/goreleaser/releaser/pipeline/compress/tar"
|
"github.com/goreleaser/releaser/pipeline/compress/tar"
|
||||||
@@ -20,12 +21,12 @@ func (Pipe) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(context *context.Context) error {
|
func (Pipe) Run(ctx *context.Context) error {
|
||||||
var g errgroup.Group
|
var g errgroup.Group
|
||||||
for _, archive := range context.Archives {
|
for _, archive := range ctx.Archives {
|
||||||
archive := archive
|
archive := archive
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
return create(archive, context)
|
return create(archive, ctx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return g.Wait()
|
return g.Wait()
|
||||||
@@ -36,26 +37,27 @@ type Archive interface {
|
|||||||
Add(name, path string) error
|
Add(name, path string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func create(archive string, context *context.Context) error {
|
func create(name string, ctx *context.Context) error {
|
||||||
file, err := os.Create("dist/" + archive + "." + context.Config.Archive.Format)
|
file, err := os.Create("dist/" + name + "." + ctx.Config.Archive.Format)
|
||||||
log.Println("Creating", file.Name(), "...")
|
log.Println("Creating", file.Name(), "...")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func() { _ = file.Close() }()
|
defer func() { _ = file.Close() }()
|
||||||
var archive = archiveFor(file, context.Config.Archive.Format)
|
var archive = archiveFor(file, ctx.Config.Archive.Format)
|
||||||
defer func() { _ = archive.Close() }()
|
defer func() { _ = archive.Close() }()
|
||||||
for _, f := range context.Config.Files {
|
for _, f := range ctx.Config.Files {
|
||||||
if err := archive.Add(f, f); err != nil {
|
if err := archive.Add(f, f); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
files, err := ioutil.ReadDir("dist/" + name)
|
folder := filepath.Join("dist", name)
|
||||||
|
files, err := ioutil.ReadDir(folder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if err := archive.Add(file.Name(), f); err != nil {
|
if err := archive.Add(file.Name(), filepath.Join(folder, f.Name())); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,27 +19,27 @@ func (Pipe) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(context *context.Context) (err error) {
|
func (Pipe) Run(ctx *context.Context) (err error) {
|
||||||
if context.Config.Build.Main == "" {
|
if ctx.Config.Build.Main == "" {
|
||||||
context.Config.Build.Main = "main.go"
|
ctx.Config.Build.Main = "main.go"
|
||||||
}
|
}
|
||||||
if len(context.Config.Build.Oses) == 0 {
|
if len(ctx.Config.Build.Oses) == 0 {
|
||||||
context.Config.Build.Oses = []string{"linux", "darwin"}
|
ctx.Config.Build.Oses = []string{"linux", "darwin"}
|
||||||
}
|
}
|
||||||
if len(context.Config.Build.Arches) == 0 {
|
if len(ctx.Config.Build.Arches) == 0 {
|
||||||
context.Config.Build.Arches = []string{"amd64", "386"}
|
ctx.Config.Build.Arches = []string{"amd64", "386"}
|
||||||
}
|
}
|
||||||
if context.Config.Build.Ldflags == "" {
|
if ctx.Config.Build.Ldflags == "" {
|
||||||
context.Config.Build.Ldflags = "-s -w"
|
ctx.Config.Build.Ldflags = "-s -w"
|
||||||
}
|
}
|
||||||
if context.Config.Archive.NameTemplate == "" {
|
if ctx.Config.Archive.NameTemplate == "" {
|
||||||
context.Config.Archive.NameTemplate = "{{.BinaryName}}_{{.Os}}_{{.Arch}}"
|
ctx.Config.Archive.NameTemplate = "{{.BinaryName}}_{{.Os}}_{{.Arch}}"
|
||||||
}
|
}
|
||||||
if context.Config.Archive.Format == "" {
|
if ctx.Config.Archive.Format == "" {
|
||||||
context.Config.Archive.Format = "tar.gz"
|
ctx.Config.Archive.Format = "tar.gz"
|
||||||
}
|
}
|
||||||
if len(context.Config.Archive.Replacements) == 0 {
|
if len(ctx.Config.Archive.Replacements) == 0 {
|
||||||
context.Config.Archive.Replacements = map[string]string{
|
ctx.Config.Archive.Replacements = map[string]string{
|
||||||
"darwin": "Darwin",
|
"darwin": "Darwin",
|
||||||
"linux": "Linux",
|
"linux": "Linux",
|
||||||
"freebsd": "FreeBSD",
|
"freebsd": "FreeBSD",
|
||||||
@@ -50,17 +50,17 @@ func (Pipe) Run(context *context.Context) (err error) {
|
|||||||
"amd64": "x86_64",
|
"amd64": "x86_64",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(context.Config.Files) != 0 {
|
if len(ctx.Config.Files) != 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
context.Config.Files = []string{}
|
ctx.Config.Files = []string{}
|
||||||
for _, pattern := range filePatterns {
|
for _, pattern := range filePatterns {
|
||||||
matches, err := globPath(pattern)
|
matches, err := globPath(pattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Config.Files = append(context.Config.Files, matches...)
|
ctx.Config.Files = append(ctx.Config.Files, matches...)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
28
pipeline/env/env.go
vendored
Normal file
28
pipeline/env/env.go
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package env
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/goreleaser/releaser/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ErrMissingToken = errors.New("Missing GITHUB_TOKEN")
|
||||||
|
|
||||||
|
// Pipe for env
|
||||||
|
type Pipe struct{}
|
||||||
|
|
||||||
|
// Name of the pipe
|
||||||
|
func (Pipe) Name() string {
|
||||||
|
return "Env"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the pipe
|
||||||
|
func (Pipe) Run(ctx *context.Context) (err error) {
|
||||||
|
token := os.Getenv("GITHUB_TOKEN")
|
||||||
|
if token == "" {
|
||||||
|
return ErrMissingToken
|
||||||
|
}
|
||||||
|
ctx.Token = &token
|
||||||
|
return
|
||||||
|
}
|
@@ -11,7 +11,7 @@ func (Pipe) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(context *context.Context) (err error) {
|
func (Pipe) Run(ctx *context.Context) (err error) {
|
||||||
tag, err := currentTag()
|
tag, err := currentTag()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -25,8 +25,10 @@ func (Pipe) Run(context *context.Context) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Git.CurrentTag = tag
|
ctx.Git = &context.GitInfo{
|
||||||
context.Git.PreviousTag = previous
|
CurrentTag: tag,
|
||||||
context.Git.Diff = log
|
PreviousTag: previous,
|
||||||
|
Diff: log,
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
package pipeline
|
package pipeline
|
||||||
|
|
||||||
"github.com/goreleaser/releaser/config"
|
import "github.com/goreleaser/releaser/context"
|
||||||
|
|
||||||
// Pipe interface
|
// Pipe interface
|
||||||
type Pipe interface {
|
type Pipe interface {
|
||||||
@@ -8,5 +8,5 @@ type Pipe interface {
|
|||||||
Name() string
|
Name() string
|
||||||
|
|
||||||
// Run the pipe
|
// Run the pipe
|
||||||
Run(config context.Context) error
|
Run(ctx *context.Context) error
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package release
|
package release
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
goctx "context"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -20,43 +21,43 @@ func (Pipe) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(context *context.Context) error {
|
func (Pipe) Run(ctx *context.Context) error {
|
||||||
ts := oauth2.StaticTokenSource(
|
ts := oauth2.StaticTokenSource(
|
||||||
&oauth2.Token{AccessToken: context.Token},
|
&oauth2.Token{AccessToken: *ctx.Token},
|
||||||
)
|
)
|
||||||
tc := oauth2.NewClient(context.Background(), ts)
|
tc := oauth2.NewClient(goctx.Background(), ts)
|
||||||
client := github.NewClient(tc)
|
client := github.NewClient(tc)
|
||||||
|
|
||||||
r, err := getOrCreateRelease(client, context)
|
r, err := getOrCreateRelease(client, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var g errgroup.Group
|
var g errgroup.Group
|
||||||
for _, archive := range context.Archives {
|
for _, archive := range ctx.Archives {
|
||||||
archive := archive
|
archive := archive
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
return upload(client, *r.ID, archive, context)
|
return upload(client, *r.ID, archive, ctx)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
return g.Wait()
|
return g.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOrCreateRelease(client *github.Client, context *context.Context) (*github.RepositoryRelease, error) {
|
func getOrCreateRelease(client *github.Client, ctx *context.Context) (*github.RepositoryRelease, error) {
|
||||||
owner := context.Repo.Owner
|
owner := ctx.Repo.Owner
|
||||||
repo := context.Repo.Name
|
repo := ctx.Repo.Name
|
||||||
data := &github.RepositoryRelease{
|
data := &github.RepositoryRelease{
|
||||||
Name: github.String(context.Git.CurrentTag),
|
Name: github.String(ctx.Git.CurrentTag),
|
||||||
TagName: github.String(context.Git.CurrentTag),
|
TagName: github.String(ctx.Git.CurrentTag),
|
||||||
Body: github.String(description(context.Git.Diff)),
|
Body: github.String(description(ctx.Git.Diff)),
|
||||||
}
|
}
|
||||||
r, res, err := client.Repositories.GetReleaseByTag(owner, repo, context.Git.CurrentTag)
|
r, _, err := client.Repositories.GetReleaseByTag(owner, repo, ctx.Git.CurrentTag)
|
||||||
if err != nil && res.StatusCode == 404 {
|
if err != nil {
|
||||||
log.Println("Creating release", config.Git.CurrentTag, "on", context.Config.Repo, "...")
|
log.Println("Creating release", ctx.Git.CurrentTag, "on", ctx.Config.Repo, "...")
|
||||||
r, _, err = client.Repositories.CreateRelease(owner, repo, data)
|
r, _, err = client.Repositories.CreateRelease(owner, repo, data)
|
||||||
return r, err
|
return r, err
|
||||||
}
|
}
|
||||||
log.Println("Updating existing release", config.Git.CurrentTag, "on", context.Config.Repo, "...")
|
log.Println("Updating existing release", ctx.Git.CurrentTag, "on", ctx.Config.Repo, "...")
|
||||||
r, _, err = client.Repositories.EditRelease(owner, repo, *r.ID, data)
|
r, _, err = client.Repositories.EditRelease(owner, repo, *r.ID, data)
|
||||||
return r, err
|
return r, err
|
||||||
}
|
}
|
||||||
@@ -71,8 +72,8 @@ func description(diff string) string {
|
|||||||
return result + "\nBuilt with " + string(bts)
|
return result + "\nBuilt with " + string(bts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func upload(client *github.Client, releaseID int, archive string, context *context.Context) error {
|
func upload(client *github.Client, releaseID int, archive string, ctx *context.Context) error {
|
||||||
archive = archive + "." + context.Config.Archive.Format
|
archive = archive + "." + ctx.Config.Archive.Format
|
||||||
file, err := os.Open("dist/" + archive)
|
file, err := os.Open("dist/" + archive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -80,8 +81,8 @@ func upload(client *github.Client, releaseID int, archive string, context *conte
|
|||||||
defer func() { _ = file.Close() }()
|
defer func() { _ = file.Close() }()
|
||||||
log.Println("Uploading", file.Name(), "...")
|
log.Println("Uploading", file.Name(), "...")
|
||||||
_, _, err = client.Repositories.UploadReleaseAsset(
|
_, _, err = client.Repositories.UploadReleaseAsset(
|
||||||
context.Repo.Owner,
|
ctx.Repo.Owner,
|
||||||
context.Repo.Name,
|
ctx.Repo.Name,
|
||||||
releaseID,
|
releaseID,
|
||||||
&github.UploadOptions{Name: archive},
|
&github.UploadOptions{Name: archive},
|
||||||
file,
|
file,
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package repos
|
package repos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/goreleaser/releaser/context"
|
"github.com/goreleaser/releaser/context"
|
||||||
@@ -16,13 +15,17 @@ func (Pipe) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(context *context.Context) (err error) {
|
func (Pipe) Run(ctx *context.Context) (err error) {
|
||||||
owner, name := split(context.Config.Repo)
|
owner, name := split(ctx.Config.Repo)
|
||||||
context.Repo.Owner = owner
|
ctx.Repo = &context.Repo{
|
||||||
context.Repo.Name = name
|
Owner: owner,
|
||||||
owner, name = split(context.Config.Brew.Repo)
|
Name: name,
|
||||||
context.BrewRepo.Owner = owner
|
}
|
||||||
context.BrewRepo.Name = name
|
owner, name = split(ctx.Config.Brew.Repo)
|
||||||
|
ctx.BrewRepo = &context.Repo{
|
||||||
|
Owner: owner,
|
||||||
|
Name: name,
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,11 +15,11 @@ func (Pipe) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(context *context.Context) (err error) {
|
func (Pipe) Run(ctx *context.Context) (err error) {
|
||||||
if context.Config.BinaryName == "" {
|
if ctx.Config.BinaryName == "" {
|
||||||
return errors.New("missing binary_name")
|
return errors.New("missing binary_name")
|
||||||
}
|
}
|
||||||
if context.Config.Repo == "" {
|
if ctx.Config.Repo == "" {
|
||||||
return errors.New("missing repo")
|
return errors.New("missing repo")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user