Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't wait to send GH updates on error/done #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
// the GitHub Commit Status describing which steps are running, errored or done.
// The status check links directly to the build or first erroring build step.
//
// For example usage in GCB see
// https://github.com/unravelin/google-cloud-build-tools/tree/v0/cmd/gcb2gh
// For example usage in GCB see https://github.com/unravelin/gcb2gh.
package main

import (
Expand All @@ -14,7 +13,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -135,6 +133,16 @@ func run(ctx context.Context) (err error) {
}
}

// If we think we're done, send the update as quickly as we can.
// The process is about to be killed.
if s.status == gcbStatusError || s.status == gcbStatusDone {
if !kick.Stop() {
<-kick.C
}
kick.Reset(10 * time.Second)
break
}

// Schedule an update to GitHub, if nothing else happens first.
// Debounces the initial requests.
if !kick.Stop() {
Expand Down Expand Up @@ -256,10 +264,10 @@ func dockerUpdates(ctx context.Context, dockerHost string, updates chan<- gcbSte
switch err {
case nil:
// Continue.
default:
return fmt.Errorf("decoding event: %w", err)
case io.EOF:
return nil
default:
return fmt.Errorf("decoding event: %w", err)
}

// Filter for step container events.
Expand Down Expand Up @@ -419,7 +427,7 @@ func updateGitHub(build buildContext, status ghStatusUpdate) error {
b, _ := httputil.DumpResponse(res, true)
return fmt.Errorf("%s response from github:\n%s", res.Status, b)
}
if _, err := io.Copy(ioutil.Discard, res.Body); err != nil {
if _, err := io.Copy(io.Discard, res.Body); err != nil {
return fmt.Errorf("discarding github response body: %w", err)
}
return nil
Expand Down