Files
emacs-builds/cmd/github-release/check_cmd.go
Jim Myhrberg 6510f68cdd feat(builds): add custom github-release tool
This tool is responsible for three distinct operations:

- Plan:
  - Accepts a optional git ref (branch/tag), defaulting to "master"
    branch if not specified.
  - Fetches commit information about the git-ref from the
    emacs-mirror/emacs GitHub repo.
  - Based on commit info, a plan.yml file is created, key information in
    it is the git ref, git SHA, date of commit, current macOS version
    and CPU architecture.
- Check:
  - Loads plan.yml and checks if GitHub Release name specified in plan
    exists, exiting with an error if it does not exist.
  - Checks if GitHub Release contains a asset file matching the name of
    the archive specified in the plan, exiting with an error if it does
    not exist.
  - If both GitHub Release and asset exist, it exits with not errors.
- Release:
  - Loads plan.yml and checks if archive specified in plan exists
    on disk.
  - Checks if GitHub Release name specified in plan exists, creating it
    if it does not exist.
  - Checks if GitHub Release contains a asset file matching that of
    archive specified in plan. If the asset it missing, it will be
    uploaded. If it exists but size does not match that of archive on
    disk, the existing asset will be replaced.
2021-05-08 19:48:36 +01:00

57 lines
1.2 KiB
Go

package main
import (
"fmt"
"net/http"
"github.com/urfave/cli/v2"
)
func checkCmd() *cli.Command {
return &cli.Command{
Name: "check",
Usage: "Check if GitHub release and asset exists",
UsageText: "github-release [global options] check [options]",
Action: actionHandler(checkAction),
}
}
func checkAction(c *cli.Context, opts *globalOptions) error {
gh := opts.gh
repo := opts.repo
plan, err := LoadPlan(opts.plan)
if err != nil {
return err
}
fmt.Printf(
"==> Checking github.com/%s for release: %s\n",
repo.String(), plan.Release,
)
release, resp, err := gh.Repositories.GetReleaseByTag(
c.Context, repo.Owner, repo.Name, plan.Release,
)
if err != nil {
if resp.StatusCode == http.StatusNotFound {
return fmt.Errorf("release %s does not exist", plan.Release)
} else {
return err
}
}
fmt.Println(" -> Release exists")
filename := plan.ReleaseAsset()
fmt.Printf("==> Checking release for asset: %s\n", filename)
for _, a := range release.Assets {
if a.Name != nil && filename == *a.Name {
fmt.Println(" -> Asset exists")
return nil
}
}
return fmt.Errorf("release does contain asset: %s", filename)
}