@@ -46,7 +46,7 @@ const (
4646)
4747
4848type GH struct {
49- TriggerNewBuild func (t testing.TB , ctx context.Context , owner , repo , token string , runID int64 ) (int64 , string , string , error )
49+ TriggerNewBuild func (t testing.TB , ctx context.Context , owner , repo , token , commitSha string , runID int64 ) (int64 , string , string , error )
5050 sleepTime time.Duration
5151}
5252
@@ -59,7 +59,7 @@ func NewGH() GH {
5959}
6060
6161// triggerNewBuild triggers a new action execution
62- func triggerNewBuild (t testing.TB , ctx context.Context , owner , repo , token string , runID int64 ) (int64 , string , string , error ) {
62+ func triggerNewBuild (t testing.TB , ctx context.Context , owner , repo , token , commitSha string , runID int64 ) (int64 , string , string , error ) {
6363 ts := oauth2 .StaticTokenSource (& oauth2.Token {AccessToken : token })
6464 tc := oauth2 .NewClient (ctx , ts )
6565 client := github .NewClient (tc )
@@ -75,8 +75,9 @@ func triggerNewBuild(t testing.TB, ctx context.Context, owner, repo, token strin
7575 }
7676 return 0 , "" , "" , fmt .Errorf ("error re-running workflow status: %d body: %s" , resp .StatusCode , string (bodyBytes ))
7777 }
78- opts := & github.ListWorkflowRunsOptions {
7978
79+ opts := & github.ListWorkflowRunsOptions {
80+ HeadSHA : commitSha ,
8081 ListOptions : github.ListOptions {
8182 PerPage : 1 ,
8283 Page : 1 ,
@@ -115,17 +116,18 @@ func triggerNewBuild(t testing.TB, ctx context.Context, owner, repo, token strin
115116}
116117
117118// GetLastActionState returns the state of the latest action
118- func (g GH ) GetLastActionState (t testing.TB , ctx context.Context , owner , repo , token string ) (int64 , string , string , error ) {
119+ func (g GH ) GetLastActionState (t testing.TB , ctx context.Context , owner , repo , token , commitSha string ) (int64 , string , string , error ) {
119120 ts := oauth2 .StaticTokenSource (& oauth2.Token {AccessToken : token })
120121 tc := oauth2 .NewClient (ctx , ts )
121122 client := github .NewClient (tc )
122123
123124 opts := & github.ListWorkflowRunsOptions {
124-
125+ HeadSHA : commitSha ,
125126 ListOptions : github.ListOptions {
126127 PerPage : 1 ,
127128 },
128129 }
130+
129131 runs , _ , err := client .Actions .ListRepositoryWorkflowRuns (ctx , owner , repo , opts )
130132
131133 if err != nil {
@@ -260,7 +262,7 @@ func (g GH) GetFinalActionState(t testing.TB, ctx context.Context, owner, repo,
260262}
261263
262264// WaitBuildSuccess waits for the current build in a repo to finish.
263- func (g GH ) WaitBuildSuccess (t testing.TB , owner , repo , token string , failureMsg string , maxBuildRetry , maxErrorRetries int , timeBetweenErrorRetries time.Duration ) error {
265+ func (g GH ) WaitBuildSuccess (t testing.TB , owner , repo , token , commitSha , failureMsg string , maxBuildRetry , maxErrorRetries int , timeBetweenErrorRetries time.Duration ) error {
264266 var status , conclusion string
265267 var runID int64
266268 var err error
@@ -269,7 +271,7 @@ func (g GH) WaitBuildSuccess(t testing.TB, owner, repo, token string, failureMsg
269271 // wait action creation
270272 time .Sleep (30 * time .Second )
271273
272- runID , status , conclusion , err = g .GetLastActionState (t , ctx , owner , repo , token )
274+ runID , status , conclusion , err = g .GetLastActionState (t , ctx , owner , repo , token , commitSha )
273275 if err != nil {
274276 return err
275277 }
@@ -295,7 +297,7 @@ func (g GH) WaitBuildSuccess(t testing.TB, owner, repo, token string, failureMsg
295297 }
296298
297299 // Trigger a new build
298- runID , status , conclusion , err = g .TriggerNewBuild (t , ctx , owner , repo , token , runID )
300+ runID , status , conclusion , err = g .TriggerNewBuild (t , ctx , owner , repo , token , commitSha , runID )
299301 if err != nil {
300302 return fmt .Errorf ("failed to trigger new action (attempt %d/%d): %w" , i + 1 , maxErrorRetries , err )
301303 }
0 commit comments