Skip to content

Commit 0ffb888

Browse files
authored
[AUTOREVERT] fix bug ignoring workflow dispatch errors (#7277)
Signed-off-by: Jean Schmidt <[email protected]>
1 parent a5abb6f commit 0ffb888

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

aws/lambda/pytorch-auto-revert/pytorch_auto_revert/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import urllib.parse
44
from enum import Enum
55

6+
import github
7+
68

79
class RestartAction(Enum):
810
"""Controls restart behavior.
@@ -140,3 +142,20 @@ def build_pytorch_hud_url(
140142
f"https://hud.pytorch.org/hud/{repo_full_name}/{top_sha}/1?"
141143
f"per_page={num_commits}&name_filter={encoded_name}&mergeEphemeralLF=true"
142144
)
145+
146+
147+
def proper_workflow_create_dispatch(
148+
workflow: github.Workflow,
149+
ref: github.Branch.Branch | github.Tag.Tag | github.Commit.Commit | str,
150+
inputs: dict,
151+
) -> bool:
152+
"""
153+
:calls: `POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches
154+
<https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event>`
155+
"""
156+
status, headers, body = workflow._requester.requestJson(
157+
"POST", f"{workflow.url}/dispatches", input={"ref": ref, "inputs": inputs}
158+
)
159+
if status != 204:
160+
raise ValueError(f"Error dispatching workflow: {status}, {headers}, {body}")
161+
return True

aws/lambda/pytorch-auto-revert/pytorch_auto_revert/workflow_checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Dict, Set
99

1010
from .clickhouse_client_helper import CHCliFactory
11-
from .utils import RetryWithBackoff
11+
from .utils import proper_workflow_create_dispatch, RetryWithBackoff
1212
from .workflow_resolver import WorkflowResolver
1313

1414

@@ -142,7 +142,7 @@ def restart_workflow(self, workflow_name: str, commit_sha: str) -> None:
142142
with attempt:
143143
repo = client.get_repo(f"{self.repo_owner}/{self.repo_name}")
144144
workflow = repo.get_workflow(wf_ref.file_name)
145-
workflow.create_dispatch(ref=tag_ref, inputs={})
145+
proper_workflow_create_dispatch(workflow, ref=tag_ref, inputs={})
146146

147147
workflow_url = (
148148
f"https://github.com/{self.repo_owner}/{self.repo_name}"

0 commit comments

Comments
 (0)