mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-31 01:53:50 +02:00
release to github
This commit is contained in:
parent
eea2878693
commit
580ee4ca46
@ -1,4 +1,7 @@
|
||||
repo: goreleaser/releaser
|
||||
binary_name: release
|
||||
brew:
|
||||
repo: goreleaser/homebrew
|
||||
repo: goreleaser/brew
|
||||
build:
|
||||
arches:
|
||||
- amd64
|
2
main.go
2
main.go
@ -39,7 +39,7 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalln("Failed to diff current and previous tags", err.Error())
|
||||
}
|
||||
err = release.Release(version, diff, config)
|
||||
err = release.Release(tag, diff, config)
|
||||
if err != nil {
|
||||
log.Fatalln("Failed to create the GitHub release", err.Error())
|
||||
}
|
||||
|
@ -1,7 +1,58 @@
|
||||
package release
|
||||
|
||||
import "github.com/goreleaser/releaser/config"
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
"github.com/goreleaser/releaser/config"
|
||||
"github.com/goreleaser/releaser/uname"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
func Release(version, diff string, config config.ProjectConfig) error {
|
||||
fmt.Println("Creating release", version, "on repo", config.Repo, "...")
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: config.Token},
|
||||
)
|
||||
tc := oauth2.NewClient(context.Background(), ts)
|
||||
client := github.NewClient(tc)
|
||||
|
||||
owner := strings.Split(config.Repo, "/")[0]
|
||||
repo := strings.Split(config.Repo, "/")[1]
|
||||
|
||||
r, _, err := client.Repositories.CreateRelease(owner, repo, &github.RepositoryRelease{
|
||||
TargetCommitish: github.String(version),
|
||||
Draft: github.Bool(true),
|
||||
Name: github.String(version),
|
||||
TagName: github.String(version),
|
||||
Body: github.String(diff + "\n\nAutomated with @goreleaser"),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, system := range config.Build.Oses {
|
||||
for _, arch := range config.Build.Arches {
|
||||
if err := upload(client, *r.ID, owner, repo, system, arch, config.BinaryName); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func upload(client *github.Client, releaseID int, owner, repo, system, arch, binaryName string) error {
|
||||
name := binaryName + "_" + uname.FromGo(system) + "_" + uname.FromGo(arch) + ".tar.gz"
|
||||
file, err := os.Open("dist/" + name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
fmt.Println("Uploading", file.Name(), "...")
|
||||
_, _, err = client.Repositories.UploadReleaseAsset(owner, repo, releaseID, &github.UploadOptions{
|
||||
Name: name,
|
||||
}, file)
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user