1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

Merge branch 'master' into existing-release

This commit is contained in:
Carlos Alexandro Becker 2017-01-14 11:25:55 -02:00 committed by GitHub
commit 014919d03e
3 changed files with 26 additions and 29 deletions

View File

@ -1,4 +1,4 @@
# GoReleaser
# GoReleaser
<img src="https://avatars2.githubusercontent.com/u/24697112?v=3&s=200" alt="goreleaser" align="right" />
@ -38,6 +38,9 @@ For that to work, you need to export a `GITHUB_TOKEN` environment variable with
the `repo` scope selected. You can create one
[here](https://github.com/settings/tokens/new).
GoReleaser uses the latest [Git tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) of your repository,
so you need to [create a tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging#Annotated-Tags) first.
This will build `main.go` as `my-binary`, for `Darwin` and `Linux`
(`amd64` and `i386`), archive the binary and common files as `.tar.gz`,
and finally, publish a new github release in the `user/repo` repository with
@ -52,6 +55,7 @@ repo: user/repo
binary_name: my-binary
brew:
repo: user/homebrew-tap
folder: optional/subfolder/inside/the/repo
caveats: "Optional caveats to add to the formulae"
```

View File

@ -16,6 +16,7 @@ var filePatterns = []string{"LICENCE*", "LICENSE*", "README*", "CHANGELOG*"}
// Homebrew contains the brew section
type Homebrew struct {
Repo string
Folder string
Token string `yaml:"-"`
Caveats string
}

View File

@ -3,9 +3,8 @@ package brew
import (
"bytes"
"context"
"crypto/sha256"
"fmt"
"log"
"path/filepath"
"strings"
"text/template"
@ -60,41 +59,34 @@ func (Pipe) Run(config config.ProjectConfig) error {
client := github.NewClient(tc)
owner, repo := split.OnSlash(config.Brew.Repo)
name := config.BinaryName + ".rb"
log.Println("Updating", name, "on", config.Brew.Repo, "...")
path := filepath.Join(config.Brew.Folder, config.BinaryName+".rb")
log.Println("Updating", path, "on", config.Brew.Repo, "...")
out, err := buildFormulae(config, client)
if err != nil {
return err
}
sha, err := formulaeSHA(client, owner, repo, name, out)
if err != nil {
options := &github.RepositoryContentFileOptions{
Committer: &github.CommitAuthor{
Name: github.String("goreleaserbot"),
Email: github.String("bot@goreleaser"),
},
Content: out.Bytes(),
Message: github.String(config.BinaryName + " version " + config.Git.CurrentTag),
}
file, _, res, err := client.Repositories.GetContents(
owner, repo, path, &github.RepositoryContentGetOptions{},
)
if err != nil && res.StatusCode == 404 {
_, _, err = client.Repositories.CreateFile(owner, repo, path, options)
return err
}
_, _, err = client.Repositories.UpdateFile(
owner, repo, name, &github.RepositoryContentFileOptions{
Committer: &github.CommitAuthor{
Name: github.String("goreleaserbot"),
Email: github.String("bot@goreleaser"),
},
Content: out.Bytes(),
Message: github.String(config.BinaryName + " version " + config.Git.CurrentTag),
SHA: sha,
},
)
options.SHA = file.SHA
_, _, err = client.Repositories.UpdateFile(owner, repo, path, options)
return err
}
func formulaeSHA(client *github.Client, owner, repo, name string, out bytes.Buffer) (*string, error) {
file, _, _, err := client.Repositories.GetContents(
owner, repo, name, &github.RepositoryContentGetOptions{},
)
if err == nil {
return file.SHA, err
}
return github.String(fmt.Sprintf("%s", sha256.Sum256(out.Bytes()))), nil
}
func buildFormulae(config config.ProjectConfig, client *github.Client) (bytes.Buffer, error) {
data, err := dataFor(config, client)
if err != nil {