@@ -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,45 @@ 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+ buildID = buildInfo .ID
130+ } else {
131+ status = api .TestError
119132 }
120- log .Printf ("uploaded build, reply: %q" , buildInfo )
121133 osutil .WriteJSON (filepath .Join (* flagOutput , "result.json" ), & api.BuildResult {
122- BuildID : buildInfo . ID ,
123- Success : uploadReq . BuildSuccess ,
134+ BuildID : buildID ,
135+ Success : status == api . TestPassed ,
124136 })
125137 if * flagSmokeBuild {
126138 return
127139 }
128140 testResult := & api.TestResult {
129141 SessionID : * flagSession ,
130142 TestName : * flagTestName ,
131- Result : api . TestFailed ,
143+ Result : status ,
132144 Log : output ,
133145 }
134- if uploadReq .BuildSuccess {
135- testResult .Result = api .TestPassed
136- }
137- if patched {
138- testResult .PatchedBuildID = buildInfo .ID
146+ if uploadReq .SeriesID != "" {
147+ testResult .PatchedBuildID = buildID
139148 } else {
140- testResult .BaseBuildID = buildInfo . ID
149+ testResult .BaseBuildID = buildID
141150 }
142- err = client .UploadTestResult (ctx , testResult )
151+ err : = client .UploadTestResult (ctx , testResult )
143152 if err != nil {
144153 app .Fatalf ("failed to report the test result: %v" , err )
145154 }
0 commit comments