You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-11-06 09:09:29 +02:00
@@ -43,12 +43,24 @@ type Release struct {
|
|||||||
Repo string
|
Repo string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FPMFormat defines a FPM format and how it should be built
|
||||||
|
type FPMFormat struct {
|
||||||
|
Name string
|
||||||
|
Dependencies []string
|
||||||
|
}
|
||||||
|
|
||||||
|
// FPM config
|
||||||
|
type FPM struct {
|
||||||
|
Formats []FPMFormat
|
||||||
|
}
|
||||||
|
|
||||||
// Project includes all project configuration
|
// Project includes all project configuration
|
||||||
type Project struct {
|
type Project struct {
|
||||||
Release Release
|
Release Release
|
||||||
Brew Homebrew
|
Brew Homebrew
|
||||||
Build Build
|
Build Build
|
||||||
Archive Archive
|
Archive Archive
|
||||||
|
FPM FPM `yaml:"fpm"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load config file
|
// Load config file
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ type Context struct {
|
|||||||
ReleaseRepo Repo
|
ReleaseRepo Repo
|
||||||
BrewRepo Repo
|
BrewRepo Repo
|
||||||
Archives map[string]string
|
Archives map[string]string
|
||||||
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New context
|
// New context
|
||||||
|
|||||||
@@ -3,3 +3,13 @@ brew:
|
|||||||
folder: Formula
|
folder: Formula
|
||||||
dependencies:
|
dependencies:
|
||||||
- git
|
- git
|
||||||
|
fpm:
|
||||||
|
formats:
|
||||||
|
-
|
||||||
|
name: deb
|
||||||
|
dependencies:
|
||||||
|
- git
|
||||||
|
-
|
||||||
|
name: rpm
|
||||||
|
dependencies:
|
||||||
|
- git
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/pipeline/build"
|
"github.com/goreleaser/goreleaser/pipeline/build"
|
||||||
"github.com/goreleaser/goreleaser/pipeline/defaults"
|
"github.com/goreleaser/goreleaser/pipeline/defaults"
|
||||||
"github.com/goreleaser/goreleaser/pipeline/env"
|
"github.com/goreleaser/goreleaser/pipeline/env"
|
||||||
|
"github.com/goreleaser/goreleaser/pipeline/fpm"
|
||||||
"github.com/goreleaser/goreleaser/pipeline/git"
|
"github.com/goreleaser/goreleaser/pipeline/git"
|
||||||
"github.com/goreleaser/goreleaser/pipeline/release"
|
"github.com/goreleaser/goreleaser/pipeline/release"
|
||||||
"github.com/goreleaser/goreleaser/pipeline/repos"
|
"github.com/goreleaser/goreleaser/pipeline/repos"
|
||||||
@@ -33,6 +34,7 @@ var pipes = []pipeline.Pipe{
|
|||||||
// real work
|
// real work
|
||||||
build.Pipe{},
|
build.Pipe{},
|
||||||
archive.Pipe{},
|
archive.Pipe{},
|
||||||
|
fpm.Pipe{},
|
||||||
release.Pipe{},
|
release.Pipe{},
|
||||||
brew.Pipe{},
|
brew.Pipe{},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const formula = `class {{ .Name }} < Formula
|
|||||||
desc "{{ .Desc }}"
|
desc "{{ .Desc }}"
|
||||||
homepage "{{ .Homepage }}"
|
homepage "{{ .Homepage }}"
|
||||||
url "https://github.com/{{ .Repo }}/releases/download/{{ .Tag }}/{{ .File }}.{{ .Format }}"
|
url "https://github.com/{{ .Repo }}/releases/download/{{ .Tag }}/{{ .File }}.{{ .Format }}"
|
||||||
version "{{ .Tag }}"
|
version "{{ .Version }}"
|
||||||
sha256 "{{ .SHA256 }}"
|
sha256 "{{ .SHA256 }}"
|
||||||
|
|
||||||
{{- if .Dependencies }}
|
{{- if .Dependencies }}
|
||||||
@@ -50,6 +50,7 @@ type templateData struct {
|
|||||||
Homepage string
|
Homepage string
|
||||||
Repo string
|
Repo string
|
||||||
Tag string
|
Tag string
|
||||||
|
Version string
|
||||||
BinaryName string
|
BinaryName string
|
||||||
Caveats string
|
Caveats string
|
||||||
File string
|
File string
|
||||||
@@ -156,6 +157,7 @@ func dataFor(ctx *context.Context, client *github.Client) (result templateData,
|
|||||||
Homepage: homepage,
|
Homepage: homepage,
|
||||||
Repo: ctx.Config.Release.Repo,
|
Repo: ctx.Config.Release.Repo,
|
||||||
Tag: ctx.Git.CurrentTag,
|
Tag: ctx.Git.CurrentTag,
|
||||||
|
Version: ctx.Version,
|
||||||
BinaryName: ctx.Config.Build.BinaryName,
|
BinaryName: ctx.Config.Build.BinaryName,
|
||||||
Caveats: ctx.Config.Brew.Caveats,
|
Caveats: ctx.Config.Brew.Caveats,
|
||||||
File: file,
|
File: file,
|
||||||
|
|||||||
100
pipeline/fpm/fpm.go
Normal file
100
pipeline/fpm/fpm.go
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
package fpm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"log"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
|
"github.com/goreleaser/goreleaser/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
var linuxArchives = []struct {
|
||||||
|
Key string
|
||||||
|
Arch string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Key: "linuxamd64",
|
||||||
|
Arch: "x86_64",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Key: "linux386",
|
||||||
|
Arch: "i386",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrNoFPM is shown when fpm cannot be found in $PATH
|
||||||
|
var ErrNoFPM = errors.New("fpm not present in $PATH")
|
||||||
|
|
||||||
|
// Pipe for fpm packaging
|
||||||
|
type Pipe struct{}
|
||||||
|
|
||||||
|
// Description of the pipe
|
||||||
|
func (Pipe) Description() string {
|
||||||
|
return "Creating Linux packages with fpm"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the pipe
|
||||||
|
func (Pipe) Run(ctx *context.Context) error {
|
||||||
|
cmd := exec.Command("which", "fpm")
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
return ErrNoFPM
|
||||||
|
}
|
||||||
|
if len(ctx.Config.FPM.Formats) == 0 {
|
||||||
|
log.Println("No output formats configured")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var g errgroup.Group
|
||||||
|
for _, format := range ctx.Config.FPM.Formats {
|
||||||
|
for _, archive := range linuxArchives {
|
||||||
|
if ctx.Archives[archive.Key] == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
archive := archive
|
||||||
|
g.Go(func() error {
|
||||||
|
return create(
|
||||||
|
ctx,
|
||||||
|
format.Name,
|
||||||
|
ctx.Archives[archive.Key],
|
||||||
|
archive.Arch,
|
||||||
|
format.Dependencies,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return g.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
|
func create(ctx *context.Context, format, archive, arch string, deps []string) error {
|
||||||
|
var path = filepath.Join("dist", archive)
|
||||||
|
var file = path + ".deb"
|
||||||
|
var name = ctx.Config.Build.BinaryName
|
||||||
|
log.Println("Creating", file)
|
||||||
|
|
||||||
|
var options = []string{
|
||||||
|
"-s", "dir",
|
||||||
|
"-t", format,
|
||||||
|
"-n", name,
|
||||||
|
"-v", ctx.Version,
|
||||||
|
"-a", arch,
|
||||||
|
"-C", path,
|
||||||
|
"-p", file,
|
||||||
|
"--force",
|
||||||
|
}
|
||||||
|
for _, dep := range deps {
|
||||||
|
options = append(options, "-d", dep)
|
||||||
|
}
|
||||||
|
options = append(options, name+"="+filepath.Join("/usr/local/bin", name))
|
||||||
|
cmd := exec.Command("fpm", options...)
|
||||||
|
log.Println(cmd)
|
||||||
|
var stdout bytes.Buffer
|
||||||
|
cmd.Stdout = &stdout
|
||||||
|
cmd.Stderr = &stdout
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
return errors.New(stdout.String())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
package git
|
package git
|
||||||
|
|
||||||
import "github.com/goreleaser/goreleaser/context"
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/goreleaser/goreleaser/context"
|
||||||
|
)
|
||||||
|
|
||||||
// Pipe for brew deployment
|
// Pipe for brew deployment
|
||||||
type Pipe struct{}
|
type Pipe struct{}
|
||||||
@@ -30,5 +34,7 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
|||||||
PreviousTag: previous,
|
PreviousTag: previous,
|
||||||
Diff: log,
|
Diff: log,
|
||||||
}
|
}
|
||||||
|
// removes usual `v` prefix
|
||||||
|
ctx.Version = strings.TrimPrefix(tag, "v")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,9 +31,13 @@ func (Pipe) Run(ctx *context.Context) error {
|
|||||||
for _, archive := range ctx.Archives {
|
for _, archive := range ctx.Archives {
|
||||||
archive := archive
|
archive := archive
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
return upload(client, *r.ID, archive, ctx)
|
return upload(ctx, client, *r.ID, archive, ctx.Config.Archive.Format)
|
||||||
})
|
})
|
||||||
|
for _, fpm := range ctx.Config.FPM.Formats {
|
||||||
|
g.Go(func() error {
|
||||||
|
return upload(ctx, client, *r.ID, archive, fpm.Name)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return g.Wait()
|
return g.Wait()
|
||||||
}
|
}
|
||||||
@@ -67,8 +71,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, ctx *context.Context) error {
|
func upload(ctx *context.Context, client *github.Client, releaseID int, archive, format string) error {
|
||||||
archive = archive + "." + ctx.Config.Archive.Format
|
archive = archive + "." + format
|
||||||
file, err := os.Open("dist/" + archive)
|
file, err := os.Open("dist/" + archive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user