mirror of
https://github.com/goreleaser/goreleaser.git
synced 2026-06-19 23:24:39 +02:00
Merge branch 'master' into existing-release
This commit is contained in:
commit
014919d03e
3 files changed
+26
-29
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
# GoReleaser
|
# GoReleaser
|
||||||
|
|
||||||
<img src="https://avatars2.githubusercontent.com/u/24697112?v=3&s=200" alt="goreleaser" align="right" />
|
<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
|
the `repo` scope selected. You can create one
|
||||||
[here](https://github.com/settings/tokens/new).
|
[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`
|
This will build `main.go` as `my-binary`, for `Darwin` and `Linux`
|
||||||
(`amd64` and `i386`), archive the binary and common files as `.tar.gz`,
|
(`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
|
and finally, publish a new github release in the `user/repo` repository with
|
||||||
@@ -52,6 +55,7 @@ repo: user/repo
|
|||||||
binary_name: my-binary
|
binary_name: my-binary
|
||||||
brew:
|
brew:
|
||||||
repo: user/homebrew-tap
|
repo: user/homebrew-tap
|
||||||
|
folder: optional/subfolder/inside/the/repo
|
||||||
caveats: "Optional caveats to add to the formulae"
|
caveats: "Optional caveats to add to the formulae"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ var filePatterns = []string{"LICENCE*", "LICENSE*", "README*", "CHANGELOG*"}
|
|||||||
// Homebrew contains the brew section
|
// Homebrew contains the brew section
|
||||||
type Homebrew struct {
|
type Homebrew struct {
|
||||||
Repo string
|
Repo string
|
||||||
|
Folder string
|
||||||
Token string `yaml:"-"`
|
Token string `yaml:"-"`
|
||||||
Caveats string
|
Caveats string
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-28
@@ -3,9 +3,8 @@ package brew
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
@@ -60,41 +59,34 @@ func (Pipe) Run(config config.ProjectConfig) error {
|
|||||||
client := github.NewClient(tc)
|
client := github.NewClient(tc)
|
||||||
|
|
||||||
owner, repo := split.OnSlash(config.Brew.Repo)
|
owner, repo := split.OnSlash(config.Brew.Repo)
|
||||||
name := config.BinaryName + ".rb"
|
path := filepath.Join(config.Brew.Folder, config.BinaryName+".rb")
|
||||||
|
log.Println("Updating", path, "on", config.Brew.Repo, "...")
|
||||||
log.Println("Updating", name, "on", config.Brew.Repo, "...")
|
|
||||||
out, err := buildFormulae(config, client)
|
out, err := buildFormulae(config, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
return err
|
||||||
}
|
}
|
||||||
_, _, err = client.Repositories.UpdateFile(
|
options.SHA = file.SHA
|
||||||
owner, repo, name, &github.RepositoryContentFileOptions{
|
_, _, err = client.Repositories.UpdateFile(owner, repo, path, options)
|
||||||
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,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
return err
|
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) {
|
func buildFormulae(config config.ProjectConfig, client *github.Client) (bytes.Buffer, error) {
|
||||||
data, err := dataFor(config, client)
|
data, err := dataFor(config, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user