@@ -81,7 +81,8 @@ func main() {
8181 ret := & BuildResult {}
8282 if err != nil {
8383 log .Printf ("failed to checkout: %v" , err )
84- uploadReq .Log = []byte (err .Error ())
84+ reportResults (ctx , client , nil , nil , []byte (err .Error ()))
85+ return
8586 } else {
8687 if * flagSmokeBuild {
8788 skip , err := alreadyBuilt (ctx , client , uploadReq )
@@ -95,7 +96,8 @@ func main() {
9596 ret , err = buildKernel (tracer , req )
9697 if err != nil {
9798 log .Printf ("build process failed: %v" , err )
98- uploadReq .Log = []byte (err .Error ())
99+ reportResults (ctx , client , nil , nil , []byte (err .Error ()))
100+ return
99101 } else {
100102 uploadReq .Compiler = ret .Compiler
101103 uploadReq .Config = ret .Config
@@ -108,38 +110,44 @@ func main() {
108110 }
109111 }
110112 }
111- reportResults (ctx , client , req . SeriesID != "" , uploadReq , ret .Finding , output .Bytes ())
113+ reportResults (ctx , client , uploadReq , ret .Finding , output .Bytes ())
112114}
113115
114- func reportResults (ctx context.Context , client * api.Client , patched bool ,
116+ func reportResults (ctx context.Context , client * api.Client ,
115117 uploadReq * api.UploadBuildReq , finding * api.NewFinding , output []byte ) {
116- buildInfo , err := client .UploadBuild (ctx , uploadReq )
117- if err != nil {
118- app .Fatalf ("failed to upload build: %v" , err )
118+ var buildID string
119+ status := api .TestPassed
120+ if uploadReq != nil {
121+ if ! uploadReq .BuildSuccess {
122+ status = api .TestFailed
123+ }
124+ buildInfo , err := client .UploadBuild (ctx , uploadReq )
125+ if err != nil {
126+ app .Fatalf ("failed to upload build: %v" , err )
127+ }
128+ log .Printf ("uploaded build, reply: %q" , buildInfo )
129+ } else {
130+ status = api .TestError
119131 }
120- log .Printf ("uploaded build, reply: %q" , buildInfo )
121132 osutil .WriteJSON (filepath .Join (* flagOutput , "result.json" ), & api.BuildResult {
122- BuildID : buildInfo . ID ,
123- Success : uploadReq . BuildSuccess ,
133+ BuildID : buildID ,
134+ Success : status == api . TestPassed ,
124135 })
125136 if * flagSmokeBuild {
126137 return
127138 }
128139 testResult := & api.TestResult {
129140 SessionID : * flagSession ,
130141 TestName : * flagTestName ,
131- Result : api . TestFailed ,
142+ Result : status ,
132143 Log : output ,
133144 }
134- if uploadReq .BuildSuccess {
135- testResult .Result = api .TestPassed
136- }
137- if patched {
138- testResult .PatchedBuildID = buildInfo .ID
145+ if uploadReq .SeriesID != "" {
146+ testResult .PatchedBuildID = buildID
139147 } else {
140- testResult .BaseBuildID = buildInfo . ID
148+ testResult .BaseBuildID = buildID
141149 }
142- err = client .UploadTestResult (ctx , testResult )
150+ err : = client .UploadTestResult (ctx , testResult )
143151 if err != nil {
144152 app .Fatalf ("failed to report the test result: %v" , err )
145153 }
0 commit comments