Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Commit

Permalink
[ci][tvmbot] Trigger GitHub Actions after merging (apache#12361)
Browse files Browse the repository at this point in the history
This fixes the issue where merging from GitHub Actions (i.e. with the default `GITHUB_TOKEN`) doesn't trigger post merge GitHub Actions on the commit it creates in `main`. Instead these jobs are triggered manually by a call to the Actions API after the merge has taken place.

This also updates the tvmbot testing code (and by extension some of the other CI testing code) to remove the fixtures for each test in favor of constructing them from a single sample at runtime, this makes it a lot easier to add new tests and see what is different between each data sample and clean up the testing anti-patterns that were there before (e.g. `run()` instead of `pytest.mark.parameterize`, but none of the tests in `test_ci.py` have changed)

Tested in driazati#36 which ran https://github.com/driazati/tvm/actions/runs/2881047903
  • Loading branch information
driazati authored and xinetzone committed Nov 25, 2022
1 parent b40ccc9 commit 8373a07
Show file tree
Hide file tree
Showing 16 changed files with 624 additions and 2,105 deletions.
22 changes: 18 additions & 4 deletions ci/scripts/github_tvmbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def __init__(
self.number = number
self.repo_name = repo
self.dry_run = dry_run
self.has_error = False

if dry_run and raw_data:
# In test mode there is no need to fetch anything
Expand Down Expand Up @@ -468,7 +469,10 @@ def find_missing_expected_jobs(self) -> List[str]:

def trigger_gha_ci(self, sha: str) -> None:
logging.info(f"POST-ing a workflow_dispatch event to main.yml")
r = self.github.post(
actions_github = GitHubRepo(
user=self.github.user, repo=self.github.repo, token=GH_ACTIONS_TOKEN
)
r = actions_github.post(
url="actions/workflows/main.yml/dispatches",
data={
"ref": "main",
Expand Down Expand Up @@ -537,9 +541,12 @@ def rerun_github_actions(self) -> None:

workflow_ids = list(set(workflow_ids))
logging.info(f"Rerunning GitHub Actions workflows with IDs: {workflow_ids}")
actions_github = GitHubRepo(
user=self.github.user, repo=self.github.repo, token=GH_ACTIONS_TOKEN
)
if self.dry_run:
actions_github = None
else:
actions_github = GitHubRepo(
user=self.github.user, repo=self.github.repo, token=GH_ACTIONS_TOKEN
)
for workflow_id in workflow_ids:
if self.dry_run:
logging.info(f"Dry run, not restarting workflow {workflow_id}")
Expand Down Expand Up @@ -576,6 +583,7 @@ def comment_failure(self, msg: str, exceptions: Union[Exception, List[Exception]
comment += "</details>"

pr.comment(comment)
pr.has_error = True
return exception


Expand Down Expand Up @@ -750,6 +758,9 @@ def run(pr: PR):
for name, check in command_to_run.auth:
if check(pr, comment, args):
logging.info(f"Passed auth check '{name}', continuing")
# Only one authorization check needs to pass (e.g. just mentionable
# or PR author), not all of them so quit
break
else:
logging.info(f"Failed auth check '{name}', quitting")
# Add a sad face
Expand All @@ -767,3 +778,6 @@ def run(pr: PR):

# Run the command
command_to_run.run(pr)

if pr.has_error:
raise RuntimeError("PR commented a failure")
130 changes: 0 additions & 130 deletions tests/python/ci/sample_prs/pr10786-badci.json

This file was deleted.

131 changes: 0 additions & 131 deletions tests/python/ci/sample_prs/pr10786-changes-requested.json

This file was deleted.

Loading

0 comments on commit 8373a07

Please sign in to comment.