-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworker_darwin.go
64 lines (52 loc) · 1.68 KB
/
worker_darwin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"encoding/json"
"fmt"
"os/exec"
"strings"
"github.com/pkg/errors"
)
func (worker *Worker) uploadAndWait() {
defer worker.wait.Done()
worker.logger.Info().Msg("Uploading package to Apple notarization service")
info, err := worker.uploadForNotarization()
if err != nil {
worker.logger.Error().Err(err).Msg("Upload to Apple failed")
return
}
if strings.ToLower(info.Status) == "invalid" {
worker.logger.Error().Msg("Notarization failed, please see the log file for more information")
} else {
worker.logger.Info().Msgf("Notarization completed successfully with status: %s", info.Status)
}
if strings.ToLower(info.Status) != "invalid" {
if err := worker.staplePackage(); err != nil {
worker.logger.Error().Err(err).Msg("Failed to staple notarization to package")
}
}
worker.logger.Info().Msg("Retrieving notarization log from Apple")
if err := worker.downloadNotarizationLog(info.RequestUUID); err != nil {
worker.logger.Error().Err(err).Msg("Failed to download notarization log")
}
worker.logger.Info().Msg("Notarization finished")
}
func (worker *Worker) downloadNotarizationLog(requestUUID string) error {
if len(requestUUID) == 0 {
return fmt.Errorf("request uuid not found")
}
cmd := exec.Command("xcrun", "notarytool", "log")
cmd.Args = append(cmd.Args, []string{
"--apple-id", worker.config.Username,
"--keychain-profile", worker.config.Password,
requestUUID,
}...)
stdOut, err := cmd.Output()
if err != nil {
return errors.Wrap(err, "request notarization log")
}
worker.log = new(NotarizationLog)
if err := json.Unmarshal(stdOut, worker.log); err != nil {
return errors.Wrap(err, "unmarshal notarization log")
}
return nil
}