You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-09-16 09:26:52 +02:00
Merge pull request #70 from goreleaser/create-update-formulae
improved create/update formulae logic
This commit is contained in:
@@ -3,8 +3,6 @@ package brew
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
@@ -60,41 +58,35 @@ 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 := config.BinaryName + ".rb"
|
||||||
|
|
||||||
log.Println("Updating", name, "on", config.Brew.Repo, "...")
|
log.Println("Updating", path, "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