diff --git a/verify/plugin.go b/verify/plugin.go index 2d4e3bd..9bc2468 100644 --- a/verify/plugin.go +++ b/verify/plugin.go @@ -226,6 +226,38 @@ func (p PRPlugin) finishCheckRun(client *github.Client, owner, repo string, chec return nil } +// duplicateCheckRun creates a new Check-Run with the same info as the provided one but for a new headSHA +// TODO(Adirio): rebinding should be preferred but it is bugged, see: https://github.com/google/go-github/issues/1652 +// When is is solved, remove the duplicateCheckRun function. +func (p PRPlugin) duplicateCheckRun(client *github.Client, owner, repo, headSHA string, checkRun *github.CheckRun) (*github.CheckRun, error) { + p.debugf("creating check run %q on %s/%s @ %s...", p.Name, owner, repo, headSHA) + + checkRun, res, err := client.Checks.CreateCheckRun( + context.TODO(), + owner, + repo, + github.CreateCheckRunOptions{ + Name: p.Name, + HeadSHA: headSHA, + DetailsURL: checkRun.DetailsURL, + ExternalID: checkRun.ExternalID, + Status: checkRun.Status, + Conclusion: checkRun.Conclusion, + StartedAt: checkRun.StartedAt, + CompletedAt: checkRun.CompletedAt, + Output: checkRun.Output, + }, + ) + if err != nil { + return nil, fmt.Errorf("unable to submit check result: %w", err) + } + + p.debugf("create check API response: %+v", res) + p.debugf("created run: %+v", checkRun) + + return checkRun, nil +} + //////////////////////////////////////////////////////////////////////////////// // Entrypoint // //////////////////////////////////////////////////////////////////////////////// @@ -311,9 +343,11 @@ func (p PRPlugin) onSync(env *ActionsEnv) error { } // Rebind the check run - if err := p.rebindCheckRun(env.Client, env.Owner, env.Repo, checkRun.GetID(), after); err != nil { - return err - } + // TODO(Adirio): rebinding should be preferred but it is bugged, see: https://github.com/google/go-github/issues/1652 + // When it is solved, uncomment the rebindCheckRun call and its error check. + //if err := p.rebindCheckRun(env.Client, env.Owner, env.Repo, checkRun.GetID(), after); err != nil { + // return err + //} // Rerun the tests if they weren't finished if !Finished.Equal(checkRun.GetStatus()) { @@ -321,6 +355,14 @@ func (p PRPlugin) onSync(env *ActionsEnv) error { return p.processAndSubmit(env, checkRun) } + // Create a duplicate for the new commit + // TODO(Adirio): rebinding should be preferred but it is bugged, see: https://github.com/google/go-github/issues/1652 + // When it is solved, remove the duplicateCheckRun call and its error check. + checkRun, err = p.duplicateCheckRun(env.Client, env.Owner, env.Repo, after, checkRun) + if err != nil { + return err + } + // Return failure here too so that the whole suite fails (since the actions // suite seems to ignore failing check runs when calculating general failure) if *checkRun.Conclusion == "failure" {