mirror of
https://github.com/jimeh/emacs-builds.git
synced 2026-02-19 11:56:40 +00:00
test(builds): add test build options to github-release tool
This will allow me to run test builds against experimental branches of the build-emacs-for-macos build script, and publish them under a pre-release "Test Builds" GitHub Release, rather than a normal nightly release.
This commit is contained in:
@@ -27,15 +27,15 @@ func checkAction(c *cli.Context, opts *globalOptions) error {
|
||||
|
||||
fmt.Printf(
|
||||
"==> Checking github.com/%s for release: %s\n",
|
||||
repo.String(), plan.Release,
|
||||
repo.String(), plan.Release.Name,
|
||||
)
|
||||
|
||||
release, resp, err := gh.Repositories.GetReleaseByTag(
|
||||
c.Context, repo.Owner, repo.Name, plan.Release,
|
||||
c.Context, repo.Owner, repo.Name, plan.Release.Name,
|
||||
)
|
||||
if err != nil {
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
return fmt.Errorf("release %s does not exist", plan.Release)
|
||||
return fmt.Errorf("release %s does not exist", plan.Release.Name)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -6,11 +6,20 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type ReleaseType string
|
||||
|
||||
type Release struct {
|
||||
Name string `yaml:"name"`
|
||||
Title string `yaml:"title,omitempty"`
|
||||
Draft bool `yaml:"draft,omitempty"`
|
||||
Pre bool `yaml:"prerelease,omitempty"`
|
||||
}
|
||||
|
||||
type Plan struct {
|
||||
Commit *Commit `yaml:"commit"`
|
||||
OS *OSInfo `yaml:"os"`
|
||||
Release string `yaml:"release"`
|
||||
Archive string `yaml:"archive"`
|
||||
Commit *Commit `yaml:"commit"`
|
||||
OS *OSInfo `yaml:"os"`
|
||||
Release *Release `yaml:"release"`
|
||||
Archive string `yaml:"archive"`
|
||||
}
|
||||
|
||||
func LoadPlan(filename string) (*Plan, error) {
|
||||
|
||||
@@ -40,6 +40,21 @@ func planCmd() *cli.Command {
|
||||
Name: "sha",
|
||||
Usage: "Override commit SHA of specified git branch/tag",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "test-build",
|
||||
Usage: "Plan a test build, which is published to a draft " +
|
||||
"\"test-builds\" release",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "test-build-name",
|
||||
Usage: "Set a unique name to distinguish the ",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "test-release-type",
|
||||
Value: "prerelease",
|
||||
Usage: "Type of release when doing a test-build " +
|
||||
"(prerelease or draft)",
|
||||
},
|
||||
},
|
||||
Action: actionHandler(planAction),
|
||||
}
|
||||
@@ -78,20 +93,37 @@ func planAction(c *cli.Context, opts *globalOptions) error {
|
||||
cleanOS := sanitizeString(osInfo.Name + "-" + osInfo.ShortVersion())
|
||||
cleanArch := sanitizeString(osInfo.Arch)
|
||||
|
||||
releaseName := fmt.Sprintf(
|
||||
"Emacs.%s.%s.%s",
|
||||
commit.DateString(), commit.ShortSHA(), cleanRef,
|
||||
)
|
||||
release := &Release{
|
||||
Name: fmt.Sprintf(
|
||||
"Emacs.%s.%s.%s",
|
||||
commit.DateString(), commit.ShortSHA(), cleanRef,
|
||||
),
|
||||
}
|
||||
archiveName := fmt.Sprintf(
|
||||
"Emacs.%s.%s.%s.%s.%s.tbz",
|
||||
"Emacs.%s.%s.%s.%s.%s",
|
||||
commit.DateString(), commit.ShortSHA(), cleanRef, cleanOS, cleanArch,
|
||||
)
|
||||
|
||||
if c.Bool("test-build") {
|
||||
release.Title = "Test Builds"
|
||||
release.Name = "test-builds"
|
||||
if c.String("test-release-type") == "draft" {
|
||||
release.Draft = true
|
||||
} else {
|
||||
release.Pre = true
|
||||
}
|
||||
|
||||
archiveName += ".test"
|
||||
if t := c.String("test-build-name"); t != "" {
|
||||
archiveName += "." + sanitizeString(t)
|
||||
}
|
||||
}
|
||||
|
||||
plan := &Plan{
|
||||
Commit: commit,
|
||||
OS: osInfo,
|
||||
Release: releaseName,
|
||||
Archive: filepath.Join(buildsDir, archiveName),
|
||||
Release: release,
|
||||
Archive: filepath.Join(buildsDir, archiveName+".tbz"),
|
||||
}
|
||||
|
||||
buf := bytes.Buffer{}
|
||||
|
||||
@@ -24,12 +24,6 @@ func publishCmd() *cli.Command {
|
||||
Usage: "Git SHA of repo to create release on",
|
||||
EnvVars: []string{"GITHUB_SHA"},
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "prerelease",
|
||||
Usage: "Git SHA of repo to create release on",
|
||||
EnvVars: []string{"RELEASE_PRERELEASE"},
|
||||
Value: false,
|
||||
},
|
||||
},
|
||||
Action: actionHandler(publishAction),
|
||||
}
|
||||
@@ -44,7 +38,6 @@ func publishAction(c *cli.Context, opts *globalOptions) error {
|
||||
}
|
||||
|
||||
releaseSHA := c.String("release-sha")
|
||||
prerelease := c.Bool("prerelease")
|
||||
|
||||
assetBaseName := filepath.Base(plan.Archive)
|
||||
assetSumFile := plan.Archive + ".sha256"
|
||||
@@ -65,20 +58,34 @@ func publishAction(c *cli.Context, opts *globalOptions) error {
|
||||
fmt.Printf(" -> Done: %s\n", assetSum)
|
||||
}
|
||||
|
||||
fmt.Printf("==> Checking release %s\n", plan.Release)
|
||||
tagName := plan.Release.Name
|
||||
name := plan.Release.Title
|
||||
|
||||
if name == "" {
|
||||
name = tagName
|
||||
}
|
||||
|
||||
fmt.Printf("==> Checking release %s\n", tagName)
|
||||
|
||||
release, resp, err := gh.Repositories.GetReleaseByTag(
|
||||
c.Context, repo.Owner, repo.Name, plan.Release,
|
||||
c.Context, repo.Owner, repo.Name, plan.Release.Name,
|
||||
)
|
||||
if err != nil {
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
fmt.Println(" -> Release not found, creating...")
|
||||
|
||||
prerelease := false
|
||||
if !plan.Release.Draft && plan.Release.Pre {
|
||||
prerelease = true
|
||||
}
|
||||
|
||||
release, _, err = gh.Repositories.CreateRelease(
|
||||
c.Context, repo.Owner, repo.Name, &github.RepositoryRelease{
|
||||
Name: &plan.Release,
|
||||
TagName: &plan.Release,
|
||||
Name: &name,
|
||||
TagName: &tagName,
|
||||
TargetCommitish: &releaseSHA,
|
||||
Prerelease: &prerelease,
|
||||
Draft: &plan.Release.Draft,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -89,8 +96,19 @@ func publishAction(c *cli.Context, opts *globalOptions) error {
|
||||
}
|
||||
}
|
||||
|
||||
if release.GetPrerelease() != prerelease {
|
||||
release.Prerelease = &prerelease
|
||||
if release.GetName() != name {
|
||||
release.Name = &name
|
||||
|
||||
release, _, err = gh.Repositories.EditRelease(
|
||||
c.Context, repo.Owner, repo.Name, release.GetID(), release,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if !plan.Release.Draft && release.GetPrerelease() != plan.Release.Pre {
|
||||
release.Prerelease = &plan.Release.Pre
|
||||
|
||||
release, _, err = gh.Repositories.EditRelease(
|
||||
c.Context, repo.Owner, repo.Name, release.GetID(), release,
|
||||
|
||||
Reference in New Issue
Block a user