mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
organized config and renamed compress package
This commit is contained in:
parent
a7c9f000d8
commit
62141803e5
@ -6,8 +6,8 @@ import (
|
||||
yaml "gopkg.in/yaml.v1"
|
||||
)
|
||||
|
||||
// Homebrew contains the brew section
|
||||
type Homebrew struct {
|
||||
// HomebrewConfig contains the brew section
|
||||
type HomebrewConfig struct {
|
||||
Repo string
|
||||
Folder string
|
||||
Caveats string
|
||||
@ -15,10 +15,11 @@ type Homebrew struct {
|
||||
|
||||
// BuildConfig contains the build configuration section
|
||||
type BuildConfig struct {
|
||||
Oses []string
|
||||
Arches []string
|
||||
Main string
|
||||
Ldflags string
|
||||
Goos []string
|
||||
Goarch []string
|
||||
Main string
|
||||
Ldflags string
|
||||
BinaryName string `yaml:"binary_name"`
|
||||
}
|
||||
|
||||
// ArchiveConfig config used for the archive
|
||||
@ -26,16 +27,20 @@ type ArchiveConfig struct {
|
||||
Format string
|
||||
NameTemplate string `yaml:"name_template"`
|
||||
Replacements map[string]string
|
||||
Files []string
|
||||
}
|
||||
|
||||
// ReleaseConfig config used for the GitHub release
|
||||
type ReleaseConfig struct {
|
||||
Repo string
|
||||
}
|
||||
|
||||
// ProjectConfig includes all project configuration
|
||||
type ProjectConfig struct {
|
||||
Repo string
|
||||
BinaryName string `yaml:"binary_name"`
|
||||
Files []string
|
||||
Brew Homebrew
|
||||
Build BuildConfig
|
||||
Archive ArchiveConfig
|
||||
Release ReleaseConfig
|
||||
Brew HomebrewConfig
|
||||
Build BuildConfig
|
||||
Archive ArchiveConfig
|
||||
}
|
||||
|
||||
// Load config file
|
||||
|
@ -14,12 +14,12 @@ type Repo struct {
|
||||
}
|
||||
|
||||
type Context struct {
|
||||
Config *config.ProjectConfig
|
||||
Token *string
|
||||
Git *GitInfo
|
||||
Repo *Repo
|
||||
BrewRepo *Repo
|
||||
Archives map[string]string
|
||||
Config *config.ProjectConfig
|
||||
Token *string
|
||||
Git *GitInfo
|
||||
ReleaseRepo *Repo
|
||||
BrewRepo *Repo
|
||||
Archives map[string]string
|
||||
}
|
||||
|
||||
func New(config config.ProjectConfig) *Context {
|
||||
|
4
main.go
4
main.go
@ -7,9 +7,9 @@ import (
|
||||
"github.com/goreleaser/releaser/config"
|
||||
"github.com/goreleaser/releaser/context"
|
||||
"github.com/goreleaser/releaser/pipeline"
|
||||
"github.com/goreleaser/releaser/pipeline/archive"
|
||||
"github.com/goreleaser/releaser/pipeline/brew"
|
||||
"github.com/goreleaser/releaser/pipeline/build"
|
||||
"github.com/goreleaser/releaser/pipeline/compress"
|
||||
"github.com/goreleaser/releaser/pipeline/defaults"
|
||||
"github.com/goreleaser/releaser/pipeline/env"
|
||||
"github.com/goreleaser/releaser/pipeline/git"
|
||||
@ -29,7 +29,7 @@ var pipes = []pipeline.Pipe{
|
||||
|
||||
// real work
|
||||
build.Pipe{},
|
||||
compress.Pipe{},
|
||||
archive.Pipe{},
|
||||
release.Pipe{},
|
||||
brew.Pipe{},
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package compress
|
||||
package archive
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
@ -7,12 +7,12 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/goreleaser/releaser/context"
|
||||
"github.com/goreleaser/releaser/pipeline/compress/tar"
|
||||
"github.com/goreleaser/releaser/pipeline/compress/zip"
|
||||
"github.com/goreleaser/releaser/pipeline/archive/tar"
|
||||
"github.com/goreleaser/releaser/pipeline/archive/zip"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
// Pipe for compress
|
||||
// Pipe for archive
|
||||
type Pipe struct{}
|
||||
|
||||
// Description of the pipe
|
||||
@ -48,7 +48,7 @@ func create(name string, ctx *context.Context) error {
|
||||
defer func() { _ = file.Close() }()
|
||||
var archive = archiveFor(file, ctx.Config.Archive.Format)
|
||||
defer func() { _ = archive.Close() }()
|
||||
for _, f := range ctx.Config.Files {
|
||||
for _, f := range ctx.Config.Archive.Files {
|
||||
if err = archive.Add(f, f); err != nil {
|
||||
return err
|
||||
}
|
@ -51,7 +51,9 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
return nil
|
||||
}
|
||||
client := clients.GitHub(*ctx.Token)
|
||||
path := filepath.Join(ctx.Config.Brew.Folder, ctx.Config.BinaryName+".rb")
|
||||
path := filepath.Join(
|
||||
ctx.Config.Brew.Folder, ctx.Config.Build.BinaryName+".rb",
|
||||
)
|
||||
|
||||
log.Println("Updating", path, "on", ctx.Config.Brew.Repo, "...")
|
||||
out, err := buildFormulae(ctx, client)
|
||||
@ -66,7 +68,7 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
},
|
||||
Content: out.Bytes(),
|
||||
Message: github.String(
|
||||
ctx.Config.BinaryName + " version " + ctx.Git.CurrentTag,
|
||||
ctx.Config.Build.BinaryName + " version " + ctx.Git.CurrentTag,
|
||||
),
|
||||
}
|
||||
|
||||
@ -105,7 +107,7 @@ func doBuildFormulae(data templateData) (bytes.Buffer, error) {
|
||||
func dataFor(ctx *context.Context, client *github.Client) (result templateData, err error) {
|
||||
var homepage string
|
||||
var description string
|
||||
rep, _, err := client.Repositories.Get(ctx.Repo.Owner, ctx.Repo.Name)
|
||||
rep, _, err := client.Repositories.Get(ctx.ReleaseRepo.Owner, ctx.ReleaseRepo.Name)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -125,12 +127,12 @@ func dataFor(ctx *context.Context, client *github.Client) (result templateData,
|
||||
description = *rep.Description
|
||||
}
|
||||
return templateData{
|
||||
Name: formulaNameFor(ctx.Config.BinaryName),
|
||||
Name: formulaNameFor(ctx.Config.Build.BinaryName),
|
||||
Desc: description,
|
||||
Homepage: homepage,
|
||||
Repo: ctx.Config.Repo,
|
||||
Repo: ctx.Config.Release.Repo,
|
||||
Tag: ctx.Git.CurrentTag,
|
||||
BinaryName: ctx.Config.BinaryName,
|
||||
BinaryName: ctx.Config.Build.BinaryName,
|
||||
Caveats: ctx.Config.Brew.Caveats,
|
||||
File: file,
|
||||
Format: ctx.Config.Archive.Format,
|
||||
|
@ -22,8 +22,8 @@ func (Pipe) Description() string {
|
||||
// Run the pipe
|
||||
func (Pipe) Run(ctx *context.Context) error {
|
||||
var g errgroup.Group
|
||||
for _, goos := range ctx.Config.Build.Oses {
|
||||
for _, goarch := range ctx.Config.Build.Arches {
|
||||
for _, goos := range ctx.Config.Build.Goos {
|
||||
for _, goarch := range ctx.Config.Build.Goarch {
|
||||
goos := goos
|
||||
goarch := goarch
|
||||
name, err := nameFor(ctx, goos, goarch)
|
||||
@ -41,7 +41,7 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
|
||||
func build(name, goos, goarch string, ctx *context.Context) error {
|
||||
ldflags := ctx.Config.Build.Ldflags + " -X main.version=" + ctx.Git.CurrentTag
|
||||
output := "dist/" + name + "/" + ctx.Config.BinaryName + extFor(goos)
|
||||
output := "dist/" + name + "/" + ctx.Config.Build.BinaryName + extFor(goos)
|
||||
log.Println("Building", output, "...")
|
||||
cmd := exec.Command(
|
||||
"go",
|
||||
|
@ -19,7 +19,7 @@ func nameFor(ctx *context.Context, goos, goarch string) (string, error) {
|
||||
Os: replace(ctx.Config.Archive.Replacements, goos),
|
||||
Arch: replace(ctx.Config.Archive.Replacements, goarch),
|
||||
Version: ctx.Git.CurrentTag,
|
||||
BinaryName: ctx.Config.BinaryName,
|
||||
BinaryName: ctx.Config.Build.BinaryName,
|
||||
}
|
||||
var out bytes.Buffer
|
||||
t, err := template.New(data.BinaryName).Parse(ctx.Config.Archive.NameTemplate)
|
||||
|
@ -20,28 +20,30 @@ func (Pipe) Description() string {
|
||||
|
||||
// Run the pipe
|
||||
func (Pipe) Run(ctx *context.Context) error {
|
||||
if ctx.Config.Repo == "" {
|
||||
if ctx.Config.Release.Repo == "" {
|
||||
repo, err := remoteRepo()
|
||||
ctx.Config.Repo = repo
|
||||
ctx.Config.Release.Repo = repo
|
||||
if err != nil {
|
||||
return errors.New("failed reading repo from Git: " + err.Error())
|
||||
return errors.New("failed reading repo from git: " + err.Error())
|
||||
}
|
||||
}
|
||||
if ctx.Config.BinaryName == "" {
|
||||
ctx.Config.BinaryName = strings.Split(ctx.Config.Repo, "/")[1]
|
||||
|
||||
if ctx.Config.Build.BinaryName == "" {
|
||||
ctx.Config.Build.BinaryName = strings.Split(ctx.Config.Release.Repo, "/")[1]
|
||||
}
|
||||
if ctx.Config.Build.Main == "" {
|
||||
ctx.Config.Build.Main = "main.go"
|
||||
}
|
||||
if len(ctx.Config.Build.Oses) == 0 {
|
||||
ctx.Config.Build.Oses = []string{"linux", "darwin"}
|
||||
if len(ctx.Config.Build.Goos) == 0 {
|
||||
ctx.Config.Build.Goos = []string{"linux", "darwin"}
|
||||
}
|
||||
if len(ctx.Config.Build.Arches) == 0 {
|
||||
ctx.Config.Build.Arches = []string{"amd64", "386"}
|
||||
if len(ctx.Config.Build.Goarch) == 0 {
|
||||
ctx.Config.Build.Goarch = []string{"amd64", "386"}
|
||||
}
|
||||
if ctx.Config.Build.Ldflags == "" {
|
||||
ctx.Config.Build.Ldflags = "-s -w"
|
||||
}
|
||||
|
||||
if ctx.Config.Archive.NameTemplate == "" {
|
||||
ctx.Config.Archive.NameTemplate = "{{.BinaryName}}_{{.Os}}_{{.Arch}}"
|
||||
}
|
||||
@ -60,14 +62,13 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
"amd64": "x86_64",
|
||||
}
|
||||
}
|
||||
if len(ctx.Config.Files) != 0 {
|
||||
return nil
|
||||
if len(ctx.Config.Archive.Files) == 0 {
|
||||
files, err := findFiles()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx.Config.Archive.Files = files
|
||||
}
|
||||
files, err := findFiles()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx.Config.Files = files
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -39,8 +39,8 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
}
|
||||
|
||||
func getOrCreateRelease(client *github.Client, ctx *context.Context) (*github.RepositoryRelease, error) {
|
||||
owner := ctx.Repo.Owner
|
||||
repo := ctx.Repo.Name
|
||||
owner := ctx.ReleaseRepo.Owner
|
||||
repo := ctx.ReleaseRepo.Name
|
||||
data := &github.RepositoryRelease{
|
||||
Name: github.String(ctx.Git.CurrentTag),
|
||||
TagName: github.String(ctx.Git.CurrentTag),
|
||||
@ -48,11 +48,11 @@ func getOrCreateRelease(client *github.Client, ctx *context.Context) (*github.Re
|
||||
}
|
||||
r, _, err := client.Repositories.GetReleaseByTag(owner, repo, ctx.Git.CurrentTag)
|
||||
if err != nil {
|
||||
log.Println("Creating release", ctx.Git.CurrentTag, "on", ctx.Config.Repo, "...")
|
||||
log.Println("Creating release", ctx.Git.CurrentTag, "on", ctx.Config.Release.Repo, "...")
|
||||
r, _, err = client.Repositories.CreateRelease(owner, repo, data)
|
||||
return r, err
|
||||
}
|
||||
log.Println("Updating existing release", ctx.Git.CurrentTag, "on", ctx.Config.Repo, "...")
|
||||
log.Println("Updating existing release", ctx.Git.CurrentTag, "on", ctx.Config.Release.Repo, "...")
|
||||
r, _, err = client.Repositories.EditRelease(owner, repo, *r.ID, data)
|
||||
return r, err
|
||||
}
|
||||
@ -76,8 +76,8 @@ func upload(client *github.Client, releaseID int, archive string, ctx *context.C
|
||||
defer func() { _ = file.Close() }()
|
||||
log.Println("Uploading", file.Name(), "...")
|
||||
_, _, err = client.Repositories.UploadReleaseAsset(
|
||||
ctx.Repo.Owner,
|
||||
ctx.Repo.Name,
|
||||
ctx.ReleaseRepo.Owner,
|
||||
ctx.ReleaseRepo.Name,
|
||||
releaseID,
|
||||
&github.UploadOptions{Name: archive},
|
||||
file,
|
||||
|
@ -16,8 +16,8 @@ func (Pipe) Description() string {
|
||||
|
||||
// Run the pipe
|
||||
func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
owner, name := split(ctx.Config.Repo)
|
||||
ctx.Repo = &context.Repo{
|
||||
owner, name := split(ctx.Config.Release.Repo)
|
||||
ctx.ReleaseRepo = &context.Repo{
|
||||
Owner: owner,
|
||||
Name: name,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user