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

Merge pull request #363 from goreleaser/docker-img-on-release-notes

adding docker images into the release notes
This commit is contained in:
Carlos Alexandro Becker 2017-09-16 15:54:43 -03:00 committed by GitHub
commit b0e60af5e6
9 changed files with 98 additions and 15 deletions

View File

@ -15,6 +15,7 @@ checksum:
name_template: '{{ .ProjectName }}_checksums.txt' name_template: '{{ .ProjectName }}_checksums.txt'
dockers: dockers:
- image: goreleaser/goreleaser - image: goreleaser/goreleaser
latest: true
archive: archive:
name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
replacements: replacements:

View File

@ -35,6 +35,7 @@ type Context struct {
Git GitInfo Git GitInfo
Binaries map[string]map[string][]Binary Binaries map[string]map[string][]Binary
Artifacts []string Artifacts []string
Dockers []string
ReleaseNotes string ReleaseNotes string
Version string Version string
Validate bool Validate bool
@ -45,6 +46,7 @@ type Context struct {
} }
var artifactsLock sync.Mutex var artifactsLock sync.Mutex
var dockersLock sync.Mutex
var binariesLock sync.Mutex var binariesLock sync.Mutex
// AddArtifact adds a file to upload list // AddArtifact adds a file to upload list
@ -56,6 +58,14 @@ func (ctx *Context) AddArtifact(file string) {
log.WithField("artifact", file).Info("new release artifact") log.WithField("artifact", file).Info("new release artifact")
} }
// AddDocker adds a docker image to the docker images list
func (ctx *Context) AddDocker(image string) {
dockersLock.Lock()
defer dockersLock.Unlock()
ctx.Dockers = append(ctx.Dockers, image)
log.WithField("image", image).Info("new docker image")
}
// AddBinary adds a built binary to the current context // AddBinary adds a built binary to the current context
func (ctx *Context) AddBinary(platform, folder, name, path string) { func (ctx *Context) AddBinary(platform, folder, name, path string) {
binariesLock.Lock() binariesLock.Lock()

View File

@ -8,19 +8,24 @@ import (
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
func TestMultipleArtifactAdds(t *testing.T) { func TestMultipleAdds(t *testing.T) {
var assert = assert.New(t) var assert = assert.New(t)
var list = []string{ var artifacts = []string{
"dist/a", "dist/a",
"dist/b", "dist/b",
"dist/c", "dist/c",
"dist/d", "dist/d",
} }
var dockerfiles = []string{
"a/b:1.0.0",
"c/d:2.0.0",
"e/f:3.0.0",
}
var ctx = New(config.Project{ var ctx = New(config.Project{
Dist: "dist", Dist: "dist",
}) })
var g errgroup.Group var g errgroup.Group
for _, f := range list { for _, f := range artifacts {
f := f f := f
g.Go(func() error { g.Go(func() error {
ctx.AddArtifact(f) ctx.AddArtifact(f)
@ -28,8 +33,18 @@ func TestMultipleArtifactAdds(t *testing.T) {
}) })
} }
assert.NoError(g.Wait()) assert.NoError(g.Wait())
assert.Len(ctx.Artifacts, len(list)) for _, d := range dockerfiles {
d := d
g.Go(func() error {
ctx.AddDocker(d)
return nil
})
}
assert.NoError(g.Wait())
assert.Len(ctx.Artifacts, len(artifacts))
assert.Contains(ctx.Artifacts, "a", "b", "c", "d") assert.Contains(ctx.Artifacts, "a", "b", "c", "d")
assert.Len(ctx.Dockers, len(dockerfiles))
assert.Contains(ctx.Dockers, "a/b:1.0.0", "c/d:2.0.0", "e/f:3.0.0")
} }
func TestMultipleBinaryAdds(t *testing.T) { func TestMultipleBinaryAdds(t *testing.T) {

View File

@ -35,8 +35,8 @@ var pipes = []pipeline.Pipe{
fpm.Pipe{}, // archive via fpm (deb, rpm, etc) fpm.Pipe{}, // archive via fpm (deb, rpm, etc)
snapcraft.Pipe{}, // archive via snapcraft (snap) snapcraft.Pipe{}, // archive via snapcraft (snap)
checksums.Pipe{}, // checksums of the files checksums.Pipe{}, // checksums of the files
release.Pipe{}, // release to github
docker.Pipe{}, // create and push docker images docker.Pipe{}, // create and push docker images
release.Pipe{}, // release to github
brew.Pipe{}, // push to brew tap brew.Pipe{}, // push to brew tap
} }

View File

@ -95,6 +95,7 @@ func process(ctx *context.Context, folder string, docker config.Docker, binary c
return err return err
} }
} }
ctx.AddDocker(image)
return nil return nil
} }

View File

@ -10,23 +10,36 @@ import (
const bodyTemplate = `{{ .ReleaseNotes }} const bodyTemplate = `{{ .ReleaseNotes }}
{{- if .DockerImages }}
Docker images:
{{ range $element := .DockerImages }}
- {{ . -}}
{{ end -}}
{{- end }}
--- ---
Automated with [GoReleaser](https://github.com/goreleaser) Automated with [GoReleaser](https://github.com/goreleaser)
Built with {{ .GoVersion }} Built with {{ .GoVersion }}`
`
func describeBody(ctx *context.Context) (bytes.Buffer, error) { func describeBody(ctx *context.Context) (bytes.Buffer, error) {
var out bytes.Buffer
bts, err := exec.Command("go", "version").CombinedOutput() bts, err := exec.Command("go", "version").CombinedOutput()
if err != nil { if err != nil {
return out, err return bytes.Buffer{}, err
} }
return describeBodyVersion(ctx, string(bts))
}
func describeBodyVersion(ctx *context.Context, version string) (bytes.Buffer, error) {
var out bytes.Buffer
var template = template.Must(template.New("release").Parse(bodyTemplate)) var template = template.Must(template.New("release").Parse(bodyTemplate))
err = template.Execute(&out, struct { err := template.Execute(&out, struct {
ReleaseNotes, GoVersion string ReleaseNotes, GoVersion string
DockerImages []string
}{ }{
ReleaseNotes: ctx.ReleaseNotes, ReleaseNotes: ctx.ReleaseNotes,
GoVersion: string(bts), GoVersion: version,
DockerImages: ctx.Dockers,
}) })
return out, err return out, err
} }

View File

@ -1,6 +1,7 @@
package release package release
import ( import (
"io/ioutil"
"os" "os"
"testing" "testing"
@ -13,12 +14,35 @@ func TestDescribeBody(t *testing.T) {
var changelog = "\nfeature1: description\nfeature2: other description" var changelog = "\nfeature1: description\nfeature2: other description"
var ctx = &context.Context{ var ctx = &context.Context{
ReleaseNotes: changelog, ReleaseNotes: changelog,
Dockers: []string{
"goreleaser/goreleaser:0.40.0",
"goreleaser/godownloader:0.1.0",
},
} }
out, err := describeBody(ctx) out, err := describeBodyVersion(ctx, "go version go1.9 darwin/amd64")
assert.NoError(err) assert.NoError(err)
assert.Contains(out.String(), changelog)
assert.Contains(out.String(), "Automated with [GoReleaser]") bts, err := ioutil.ReadFile("testdata/release1.txt")
assert.Contains(out.String(), "Built with go version go1.") assert.NoError(err)
ioutil.WriteFile("testdata/release1.txt", out.Bytes(), 0755)
assert.Equal(string(bts), out.String())
}
func TestDescribeBodyNoDockerImages(t *testing.T) {
var assert = assert.New(t)
var changelog = "\nfeature1: description\nfeature2: other description"
var ctx = &context.Context{
ReleaseNotes: changelog,
}
out, err := describeBodyVersion(ctx, "go version go1.9 darwin/amd64")
assert.NoError(err)
bts, err := ioutil.ReadFile("testdata/release2.txt")
assert.NoError(err)
ioutil.WriteFile("testdata/release2.txt", out.Bytes(), 0755)
assert.Equal(string(bts), out.String())
} }
func TestDontEscapeHTML(t *testing.T) { func TestDontEscapeHTML(t *testing.T) {

12
pipeline/release/testdata/release1.txt vendored Normal file
View File

@ -0,0 +1,12 @@
feature1: description
feature2: other description
Docker images:
- goreleaser/goreleaser:0.40.0
- goreleaser/godownloader:0.1.0
---
Automated with [GoReleaser](https://github.com/goreleaser)
Built with go version go1.9 darwin/amd64

7
pipeline/release/testdata/release2.txt vendored Executable file
View File

@ -0,0 +1,7 @@
feature1: description
feature2: other description
---
Automated with [GoReleaser](https://github.com/goreleaser)
Built with go version go1.9 darwin/amd64