Skip to content

Commit

Permalink
Cleaning up some more
Browse files Browse the repository at this point in the history
  • Loading branch information
doggydogworld committed Mar 4, 2025
1 parent 45e1fba commit da54a37
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 37 deletions.
10 changes: 1 addition & 9 deletions tools/mac-distribution/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ func (c *PackageInstallerCmd) Run(cli *CLI) error {
return pkg.Package()
}

func (c *PackageInstallerCmd) Validate() error {
if c.BundleID == "" {
return errors.New("Bundle ID is required for package installer regardless of notarization")
}

return nil
}

func (c *NotarizeCmd) Run(cli *CLI) error {
return c.notaryTool.NotarizeBinaries(c.Files)
}
Expand All @@ -143,7 +135,7 @@ func (g *NotaryCmd) AfterApply() error {
}

if g.CI && g.DryRun {
return errors.New("dry-run mode cannot be used in CI")
return errors.New("--dry-run mode cannot be used in CI")
}

extraOpts := []notarize.Opt{}
Expand Down
56 changes: 29 additions & 27 deletions tools/mac-distribution/notarize/notarize.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,7 @@ func (t *Tool) NotarizeBinaries(files []string) error {
}
args = append(args, files...)
t.log.Info("codesigning binaries")
_, err := t.runRetryable(func() ([]byte, error) {
// Sometimes codesign can fail due to transient issues, so we retry
// For example, we've seen "The timestamp service is not available."
out, err := t.cmdRunner.RunCommand("codesign", args...)
if err != nil {
t.log.Error("codesigning binaries", "error", err)
}
return out, err
})
err := t.runCodesign(args...)
if err != nil {
return fmt.Errorf("codesigning binaries: %w", err)
}
Expand All @@ -152,7 +144,7 @@ func (t *Tool) NotarizeBinaries(files []string) error {
archiveFiles = append(archiveFiles, zipper.FileInfo{Path: f})
}

notaryfile, err := os.CreateTemp("", "notarize-binaries-*.zip")
notaryfile, err := os.CreateTemp("", "notarize-*.zip")
if err != nil {
return err
}
Expand Down Expand Up @@ -206,7 +198,7 @@ func (t *Tool) NotarizeAppBundle(appBundlePath string, opts AppBundleOpts) error
// codesign the app bundle
args = append(args, appBundlePath)
t.log.Info("codesigning app bundle")
_, err := t.cmdRunner.RunCommand("codesign", args...)
err := t.runCodesign(args...)
if err != nil {
return fmt.Errorf("codesigning app bundle: %w", err)
}
Expand All @@ -228,14 +220,7 @@ func (t *Tool) NotarizeAppBundle(appBundlePath string, opts AppBundleOpts) error

// Staple the app bundle
t.log.Info("stapling app bundle")
_, err = t.runRetryable(func() ([]byte, error) {
out, err := t.cmdRunner.RunCommand("xcrun", "stapler", "staple", appBundlePath)
if err != nil {
t.log.Error("stapling package", "error", err)
}
return out, err
})
if err != nil {
if err := t.staple(appBundlePath); err != nil {
return fmt.Errorf("stapling app bundle: %w", err)
}

Expand Down Expand Up @@ -272,14 +257,7 @@ func (t *Tool) NotarizePackageInstaller(pathToPkg string) error {

// Staple
t.log.Info("stapling package", "package", pathToPkg)
_, err = t.runRetryable(func() ([]byte, error) {
out, err := t.cmdRunner.RunCommand("xcrun", "stapler", "staple", pathToPkg)
if err != nil {
t.log.Error("stapling package", "error", err)
}
return out, err
})
if err != nil {
if err := t.staple(pathToPkg); err != nil {
return fmt.Errorf("stapling package: %w", err)
}

Expand All @@ -296,6 +274,30 @@ func (t *Tool) runRetryable(retryableFunc func() ([]byte, error)) ([]byte, error
return stdout, err
}

func (t *Tool) runCodesign(args ...string) error {
_, err := t.runRetryable(func() ([]byte, error) {
// Sometimes codesign can fail due to transient issues, so we retry
// For example, we've seen "The timestamp service is not available."
out, err := t.cmdRunner.RunCommand("codesign", args...)
if err != nil {
t.log.Error("running codesign", "error", err)
}
return out, err
})
return err
}

func (t *Tool) staple(path string) error {
_, err := t.runRetryable(func() ([]byte, error) {
out, err := t.cmdRunner.RunCommand("xcrun", "stapler", "staple", path)
if err != nil {
t.log.Error("stapling package", "error", err)
}
return out, err
})
return err
}

func (t *Tool) validate() error {
missing := []string{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func NewPackager(info Info, opts ...Opt) (*Packager, error) {
// Package creates a package installer.
func (p *Packager) Package() error {
// Create a plist file for the package installer
tmpdir, err := os.MkdirTemp("", "packageinstaller-*")
tmpdir, err := os.MkdirTemp("", fmt.Sprintf("pkg-%s-*", p.Info.BundleID))
if err != nil {
return fmt.Errorf("creating temp dir: %w", err)
}
Expand Down

0 comments on commit da54a37

Please sign in to comment.