mirror of
https://github.com/jimeh/build-emacs-for-macos.git
synced 2026-02-19 08:26:39 +00:00
feat(notarize): add notarize command to notarize and staple *.dmg files
This commit is contained in:
@@ -46,6 +46,7 @@ func New(version, commit, date string) *CLI {
|
||||
Commands: []*cli2.Command{
|
||||
planCmd(),
|
||||
signCmd(),
|
||||
notarizeCmd(),
|
||||
{
|
||||
Name: "version",
|
||||
Usage: "print the version",
|
||||
|
||||
79
pkg/cli/notarize.go
Normal file
79
pkg/cli/notarize.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/jimeh/build-emacs-for-macos/pkg/notarize"
|
||||
"github.com/jimeh/build-emacs-for-macos/pkg/plan"
|
||||
cli2 "github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func notarizeCmd() *cli2.Command {
|
||||
return &cli2.Command{
|
||||
Name: "notarize",
|
||||
Usage: "notarize and staple a dmg, zip, or pkg",
|
||||
ArgsUsage: "<file>",
|
||||
Flags: []cli2.Flag{
|
||||
&cli2.StringFlag{
|
||||
Name: "bundle-id",
|
||||
Usage: "Bundle",
|
||||
Value: "org.gnu.Emacs",
|
||||
},
|
||||
&cli2.StringFlag{
|
||||
Name: "ac-username",
|
||||
Usage: "Apple Connect username",
|
||||
EnvVars: []string{"AC_USERNAME"},
|
||||
},
|
||||
&cli2.StringFlag{
|
||||
Name: "ac-password",
|
||||
Usage: "Apple Connect password",
|
||||
Value: "@env:AC_PASSWORD",
|
||||
},
|
||||
&cli2.StringFlag{
|
||||
Name: "ac-provider",
|
||||
Usage: "Apple Connect provider",
|
||||
EnvVars: []string{"AC_PROVIDER"},
|
||||
},
|
||||
&cli2.BoolFlag{
|
||||
Name: "staple",
|
||||
Usage: "stable file after notarization",
|
||||
Value: true,
|
||||
},
|
||||
&cli2.StringFlag{
|
||||
Name: "plan",
|
||||
Usage: "path to build plan YAML file produced by " +
|
||||
"emacs-builder plan",
|
||||
Aliases: []string{"p"},
|
||||
EnvVars: []string{"EMACS_BUILDER_PLAN"},
|
||||
TakesFile: true,
|
||||
},
|
||||
},
|
||||
Action: actionWrapper(notarizeAction),
|
||||
}
|
||||
}
|
||||
|
||||
func notarizeAction(c *cli2.Context, opts *Options) error {
|
||||
options := ¬arize.Options{
|
||||
File: c.Args().Get(0),
|
||||
BundleID: c.String("bundle-id"),
|
||||
Username: c.String("ac-username"),
|
||||
Password: c.String("ac-password"),
|
||||
Provider: c.String("ac-provider"),
|
||||
Staple: c.Bool("staple"),
|
||||
}
|
||||
|
||||
if f := c.String("plan"); f != "" {
|
||||
p, err := plan.Load(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if p.Output != nil {
|
||||
options.File = filepath.Join(
|
||||
p.Output.Directory, p.Output.DiskImage,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return notarize.Notarize(c.Context, options)
|
||||
}
|
||||
98
pkg/notarize/notarize.go
Normal file
98
pkg/notarize/notarize.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package notarize
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/mitchellh/gon/notarize"
|
||||
"github.com/mitchellh/gon/staple"
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
File string
|
||||
BundleID string
|
||||
Username string
|
||||
Password string
|
||||
Provider string
|
||||
Staple bool
|
||||
}
|
||||
|
||||
func Notarize(ctx context.Context, opts *Options) error {
|
||||
logger := hclog.FromContext(ctx).Named("notarize")
|
||||
|
||||
notarizeOpts := ¬arize.Options{
|
||||
File: opts.File,
|
||||
BundleId: opts.BundleID,
|
||||
Username: opts.Username,
|
||||
Password: opts.Password,
|
||||
Provider: opts.Provider,
|
||||
BaseCmd: exec.CommandContext(ctx, ""),
|
||||
Status: &status{
|
||||
Lock: &sync.Mutex{},
|
||||
Logger: logger,
|
||||
},
|
||||
}
|
||||
|
||||
logger.Info("notarizing", "file", filepath.Base(opts.File))
|
||||
|
||||
info, err := notarize.Notarize(ctx, notarizeOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Info(
|
||||
"notarization complete",
|
||||
"status", info.Status,
|
||||
"message", info.StatusMessage,
|
||||
)
|
||||
|
||||
if opts.Staple {
|
||||
logger.Info("stapling", "file", filepath.Base(opts.File))
|
||||
err := staple.Staple(ctx, &staple.Options{
|
||||
File: opts.File,
|
||||
BaseCmd: exec.CommandContext(ctx, ""),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type status struct {
|
||||
Lock *sync.Mutex
|
||||
Logger hclog.Logger
|
||||
|
||||
lastStatusTime time.Time
|
||||
}
|
||||
|
||||
func (s *status) Submitting() {
|
||||
s.Lock.Lock()
|
||||
defer s.Lock.Unlock()
|
||||
|
||||
s.Logger.Info("submitting file for notarization...")
|
||||
}
|
||||
|
||||
func (s *status) Submitted(uuid string) {
|
||||
s.Lock.Lock()
|
||||
defer s.Lock.Unlock()
|
||||
|
||||
s.Logger.Info("submitted")
|
||||
s.Logger.Debug("request", "uuid", uuid)
|
||||
s.Logger.Info("waiting for result from Apple...")
|
||||
}
|
||||
|
||||
func (s *status) Status(info notarize.Info) {
|
||||
s.Lock.Lock()
|
||||
defer s.Lock.Unlock()
|
||||
|
||||
if time.Now().After(s.lastStatusTime.Add(60 * time.Second)) {
|
||||
s.lastStatusTime = time.Now()
|
||||
s.Logger.Info("status update", "status", info.Status)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user