mirror of
https://github.com/jimeh/build-emacs-for-macos.git
synced 2026-02-19 13:06:38 +00:00
fix(release): attempt to fix issue with talking to GitHub API
This commit is contained in:
@@ -19,7 +19,11 @@ var checkCmd = &cli.Command{
|
||||
func checkAction(c *cli.Context, opts *globalOptions) error {
|
||||
gh := opts.gh
|
||||
repo := opts.repo
|
||||
plan := opts.plan
|
||||
plan, err := LoadPlan(opts.plan)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
releaseName := plan.ReleaseName()
|
||||
|
||||
fmt.Printf(
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/google/go-github/v35/github"
|
||||
"github.com/urfave/cli/v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var app = &cli.App{
|
||||
@@ -37,30 +36,20 @@ var app = &cli.App{
|
||||
Commands: []*cli.Command{
|
||||
checkCmd,
|
||||
publishCmd,
|
||||
planCmd,
|
||||
},
|
||||
}
|
||||
|
||||
type globalOptions struct {
|
||||
gh *github.Client
|
||||
repo *Repo
|
||||
plan *Plan
|
||||
plan string
|
||||
}
|
||||
|
||||
func actionHandler(
|
||||
f func(*cli.Context, *globalOptions) error,
|
||||
) func(*cli.Context) error {
|
||||
return func(c *cli.Context) error {
|
||||
b, err := os.ReadFile(c.Path("plan"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
plan := &Plan{}
|
||||
err = yaml.Unmarshal(b, plan)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
token := c.String("github-token")
|
||||
if t := os.Getenv("GITHUB_TOKEN"); t != "" {
|
||||
token = t
|
||||
@@ -69,7 +58,7 @@ func actionHandler(
|
||||
opts := &globalOptions{
|
||||
gh: NewGitHubClient(c.Context, token),
|
||||
repo: NewRepo(c.String("repo")),
|
||||
plan: plan,
|
||||
plan: c.String("plan"),
|
||||
}
|
||||
|
||||
return f(c, opts)
|
||||
|
||||
44
cmd/github-release/os_info.go
Normal file
44
cmd/github-release/os_info.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var OSInfo = &osInfo{}
|
||||
|
||||
type osInfo struct {
|
||||
version string
|
||||
arch string
|
||||
}
|
||||
|
||||
func (s *osInfo) Arch() string {
|
||||
if s.arch != "" {
|
||||
return s.arch
|
||||
}
|
||||
|
||||
cmd, err := exec.Command("uname", "-m").CombinedOutput()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
s.arch = strings.TrimSpace(string(cmd))
|
||||
|
||||
return s.arch
|
||||
}
|
||||
|
||||
func (s *osInfo) Version() string {
|
||||
if s.version != "" {
|
||||
return s.version
|
||||
}
|
||||
|
||||
cmd, err := exec.Command("sw_vers", "-productVersion").CombinedOutput()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
parts := strings.Split(string(cmd), ".")
|
||||
s.version = strings.Join(parts[0:2], ".")
|
||||
|
||||
return s.version
|
||||
}
|
||||
@@ -2,9 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Plan struct {
|
||||
@@ -14,6 +17,18 @@ type Plan struct {
|
||||
Archive string `yaml:"archive"`
|
||||
}
|
||||
|
||||
func LoadPlan(filename string) (*Plan, error) {
|
||||
b, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
plan := &Plan{}
|
||||
err = yaml.Unmarshal(b, plan)
|
||||
|
||||
return plan, err
|
||||
}
|
||||
|
||||
func (s *Plan) ReleaseName() string {
|
||||
ref := nonAlphaNum.ReplaceAllString(s.Ref, "-")
|
||||
ref = regexp.MustCompile(`\.`).ReplaceAllString(ref, "-")
|
||||
|
||||
77
cmd/github-release/plan_cmd.go
Normal file
77
cmd/github-release/plan_cmd.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var planCmd = &cli.Command{
|
||||
Name: "plan",
|
||||
Usage: "Plan if GitHub release and asset exists",
|
||||
UsageText: "github-release [global options] plan [<gif-ref>]",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "emacs-mirror-repo",
|
||||
Usage: "Github owner/repo to get Emacs commit info from",
|
||||
Aliases: []string{"e"},
|
||||
EnvVars: []string{"EMACS_MIRROR_REPO"},
|
||||
Value: "emacs-mirror/emacs",
|
||||
},
|
||||
},
|
||||
Action: actionHandler(planAction),
|
||||
}
|
||||
|
||||
func planAction(c *cli.Context, opts *globalOptions) error {
|
||||
gh := opts.gh
|
||||
planFile := opts.plan
|
||||
emacsRepo := NewRepo(c.String("emacs-mirror-repo"))
|
||||
|
||||
ref := c.Args().Get(0)
|
||||
if ref == "" {
|
||||
ref = "master"
|
||||
}
|
||||
|
||||
commit, _, err := gh.Repositories.GetCommit(
|
||||
c.Context, emacsRepo.Owner, emacsRepo.Name, ref,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commitDate := commit.GetCommit().Committer.GetDate()
|
||||
date := commitDate.Format("2006-01-02")
|
||||
sha := commit.GetSHA()
|
||||
|
||||
archive := fmt.Sprintf(
|
||||
"Emacs.app-[%s][%s][%s][%s][%s].tbz",
|
||||
nonAlphaNum.ReplaceAllString(ref, "-"),
|
||||
date,
|
||||
sha[0:7],
|
||||
"macOS-"+OSInfo.Version(),
|
||||
OSInfo.Arch(),
|
||||
)
|
||||
|
||||
rootDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buildsDir := filepath.Join(rootDir, "builds")
|
||||
|
||||
plan := &Plan{
|
||||
Ref: ref,
|
||||
SHA: sha,
|
||||
Date: date,
|
||||
Archive: filepath.Join(buildsDir, archive),
|
||||
}
|
||||
|
||||
b, err := yaml.Marshal(plan)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return os.WriteFile(planFile, b, 0666)
|
||||
}
|
||||
@@ -33,7 +33,10 @@ var publishCmd = &cli.Command{
|
||||
func publishAction(c *cli.Context, opts *globalOptions) error {
|
||||
gh := opts.gh
|
||||
repo := opts.repo
|
||||
plan := opts.plan
|
||||
plan, err := LoadPlan(opts.plan)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
releaseName := plan.ReleaseName()
|
||||
githubSHA := c.String("github-sha")
|
||||
|
||||
Reference in New Issue
Block a user