Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

Commit f0322b5

Browse files
committed
feat: Add log submission to process
1 parent 66d5ca3 commit f0322b5

File tree

6 files changed

+79
-29
lines changed

6 files changed

+79
-29
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ bundle_id = "com.mitchellh.example.terraform"
149149
apple_id {
150150
username = "[email protected]"
151151
password = "@env:AC_PASSWORD"
152+
provider = "UL304B4VGY"
152153
}
153154
154155
sign {
@@ -171,7 +172,8 @@ zip {
171172
"bundle_id" : "com.mitchellh.example.terraform",
172173
"apple_id": {
173174
"username" : "[email protected]",
174-
"password": "@env:AC_PASSWORD"
175+
"password": "@env:AC_PASSWORD",
176+
"provider": "UL304B4VGY"
175177
},
176178
"sign" :{
177179
"application_identity" : "Developer ID Application: Mitchell Hashimoto"
@@ -216,7 +218,7 @@ Supported configurations:
216218
**NOTE**: If you have 2FA enabled, the password must be an application password, not
217219
your normal apple id password. See [Troubleshooting](#troubleshooting) for details.
218220

219-
* `provider` (`string` _optional_) - The App Store Connect provider when using
221+
* `provider` (`string`) - The App Store Connect provider when using
220222
multiple teams within App Store Connect. If this isn't set, we'll attempt
221223
to read the `AC_PROVIDER` environment variable as a default.
222224

cmd/gon/item.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (i *item) notarize(ctx context.Context, opts *processOptions) error {
6464
}
6565

6666
// Start notarization
67-
_, err := notarize.Notarize(ctx, &notarize.Options{
67+
_, _, err := notarize.Notarize(ctx, &notarize.Options{
6868
File: i.Path,
6969
DeveloperId: opts.Config.AppleId.Username,
7070
Password: opts.Config.AppleId.Password,
@@ -75,7 +75,7 @@ func (i *item) notarize(ctx context.Context, opts *processOptions) error {
7575
})
7676

7777
// Save the error state. We don't save the notarization result yet
78-
// because we don't know it for sure until we download the log file.
78+
// because we don't know it for sure until we retrieve the log information.
7979
i.State.NotarizeError = err
8080

8181
// If we had an error, we mention immediate we have an error.

cmd/gon/status_human.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ type statusHuman struct {
1818
Prefix string
1919
Lock *sync.Mutex
2020

21-
lastStatus string
21+
lastInfoStatus string
22+
lastLogStatus string
2223
}
2324

2425
func (s *statusHuman) Submitting() {
@@ -37,13 +38,23 @@ func (s *statusHuman) Submitted(uuid string) {
3738
os.Stdout, " %sWaiting for results from Apple. This can take minutes to hours.\n", s.Prefix)
3839
}
3940

40-
func (s *statusHuman) Status(info notarize.Info) {
41+
func (s *statusHuman) InfoStatus(info notarize.Info) {
4142
s.Lock.Lock()
4243
defer s.Lock.Unlock()
4344

44-
if info.Status != s.lastStatus {
45-
s.lastStatus = info.Status
46-
color.New().Fprintf(os.Stdout, " %sStatus: %s\n", s.Prefix, info.Status)
45+
if info.Status != s.lastInfoStatus {
46+
s.lastInfoStatus = info.Status
47+
color.New().Fprintf(os.Stdout, " %sInfoStatus: %s\n", s.Prefix, info.Status)
48+
}
49+
}
50+
51+
func (s *statusHuman) LogStatus(log notarize.Log) {
52+
s.Lock.Lock()
53+
defer s.Lock.Unlock()
54+
55+
if log.Status != s.lastLogStatus {
56+
s.lastLogStatus = log.Status
57+
color.New().Fprintf(os.Stdout, " %sLogStatus: %s\n", s.Prefix, log.Status)
4758
}
4859
}
4960

notarize/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func log(ctx context.Context, uuid string, opts *Options) (*Log, error) {
8585
cmd.Stderr = &combined
8686

8787
// Log what we're going to execute
88-
logger.Info("requesting notarization info",
88+
logger.Info("requesting notarization log",
8989
"uuid", uuid,
9090
"command_path", cmd.Path,
9191
"command_args", cmd.Args,

notarize/notarize.go

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type Options struct {
4444

4545
// BaseCmd is the base command for executing app submission. This is
4646
// used for tests to overwrite where the codesign binary is. If this isn't
47-
// specified then we use `xcrun altool` as the base.
47+
// specified then we use `xcrun notarytool` as the base.
4848
BaseCmd *exec.Cmd
4949
}
5050

@@ -58,7 +58,7 @@ type Options struct {
5858
//
5959
// If error is nil, then Info is guaranteed to be non-nil.
6060
// If error is not nil, notarization failed and Info _may_ be non-nil.
61-
func Notarize(ctx context.Context, opts *Options) (*Info, error) {
61+
func Notarize(ctx context.Context, opts *Options) (*Info, *Log, error) {
6262
logger := opts.Logger
6363
if logger == nil {
6464
logger = hclog.NewNullLogger()
@@ -80,18 +80,18 @@ func Notarize(ctx context.Context, opts *Options) (*Info, error) {
8080
uuid, err := upload(ctx, opts)
8181
lock.Unlock()
8282
if err != nil {
83-
return nil, err
83+
return nil, nil, err
8484
}
8585
status.Submitted(uuid)
8686

8787
// Begin polling the info. The first thing we wait for is for the status
8888
// _to even exist_. While we get an error requesting info with an error
8989
// code of 1519 (UUID not found), then we are stuck in a queue. Sometimes
9090
// this queue is hours long. We just have to wait.
91-
result := &Info{RequestUUID: uuid}
91+
infoResult := &Info{RequestUUID: uuid}
9292
for {
9393
time.Sleep(10 * time.Second)
94-
_, err := info(ctx, result.RequestUUID, opts)
94+
_, err := info(ctx, infoResult.RequestUUID, opts)
9595
if err == nil {
9696
break
9797
}
@@ -103,7 +103,7 @@ func Notarize(ctx context.Context, opts *Options) (*Info, error) {
103103
}
104104

105105
// A real error, just return that
106-
return result, err
106+
return infoResult, nil, err
107107
}
108108

109109
// Now that the UUID result has been found, we poll more quickly
@@ -112,40 +112,73 @@ func Notarize(ctx context.Context, opts *Options) (*Info, error) {
112112
for {
113113
// Update the info. It is possible for this to return a nil info
114114
// and we dont' ever want to set result to nil so we have a check.
115-
newResult, err := info(ctx, result.RequestUUID, opts)
116-
if newResult != nil {
117-
result = newResult
115+
newInfoResult, err := info(ctx, infoResult.RequestUUID, opts)
116+
if newInfoResult != nil {
117+
infoResult = newInfoResult
118118
}
119119

120120
if err != nil {
121121
// This code is the network became unavailable error. If this
122122
// happens then we just log and retry.
123123
if e, ok := err.(Errors); ok && e.ContainsCode(-19000) {
124124
logger.Warn("error that network became unavailable, will retry")
125-
goto RETRY
125+
goto RETRYINFO
126126
}
127127

128-
return result, err
128+
return infoResult, nil, err
129129
}
130130

131-
status.Status(*result)
131+
status.InfoStatus(*infoResult)
132132

133133
// If we reached a terminal state then exit
134-
if result.Status == "Accepted" || result.Status == "Invalid" {
134+
if infoResult.Status == "Accepted" || infoResult.Status == "Invalid" {
135135
break
136136
}
137137

138-
RETRY:
138+
RETRYINFO:
139+
// Sleep, we just do a constant poll every 5 seconds. I haven't yet
140+
// found any rate limits to the service so this seems okay.
141+
time.Sleep(5 * time.Second)
142+
}
143+
144+
logResult := &Log{JobId: uuid}
145+
for {
146+
// Update the log. It is possible for this to return a nil log
147+
// and we dont' ever want to set result to nil so we have a check.
148+
newLogResult, err := log(ctx, logResult.JobId, opts)
149+
if newLogResult != nil {
150+
logResult = newLogResult
151+
}
152+
153+
if err != nil {
154+
// This code is the network became unavailable error. If this
155+
// happens then we just log and retry.
156+
if e, ok := err.(Errors); ok && e.ContainsCode(-19000) {
157+
logger.Warn("error that network became unavailable, will retry")
158+
goto RETRYLOG
159+
}
160+
161+
return infoResult, logResult, err
162+
}
163+
164+
status.LogStatus(*logResult)
165+
166+
// If we reached a terminal state then exit
167+
if logResult.Status == "Accepted" || logResult.Status == "Invalid" {
168+
break
169+
}
170+
171+
RETRYLOG:
139172
// Sleep, we just do a constant poll every 5 seconds. I haven't yet
140173
// found any rate limits to the service so this seems okay.
141174
time.Sleep(5 * time.Second)
142175
}
143176

144177
// If we're in an invalid status then return an error
145178
err = nil
146-
if result.Status == "Invalid" {
179+
if logResult.Status == "Invalid" && infoResult.Status == "Invalid" {
147180
err = fmt.Errorf("package is invalid.")
148181
}
149182

150-
return result, err
183+
return infoResult, logResult, err
151184
}

notarize/status.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,23 @@ type Status interface {
1212
// The arguments give you access to the requestUUID to query more information.
1313
Submitted(requestUUID string)
1414

15-
// Status is called as the status of the submitted package changes.
15+
// InfoStatus is called as the status of the submitted package changes.
1616
// The info argument contains additional information about the status.
1717
// Note that some fields in the info argument may not be populated, please
1818
// refer to the docs.
19-
Status(Info)
19+
InfoStatus(Info)
20+
21+
// LogStatus is called as the status of the submitted package changes.
22+
LogStatus(Log)
2023
}
2124

2225
// noopStatus implements Status and does nothing.
2326
type noopStatus struct{}
2427

2528
func (noopStatus) Submitting() {}
2629
func (noopStatus) Submitted(string) {}
27-
func (noopStatus) Status(Info) {}
30+
func (noopStatus) InfoStatus(Info) {}
31+
func (noopStatus) LogStatus(Log) {}
2832

2933
// Assert that we always implement it
3034
var _ Status = noopStatus{}

0 commit comments

Comments
 (0)