mirror of
https://github.com/servo/servo.git
synced 2025-08-16 02:45:36 +01:00
Make "@bors-servo try" a GitHub Action (#30014)
This is the last piece of the puzzle to turning off bors. This makes functionality provided by bors to understand "@bors-servo try" a GitHub Action. For now the syntax is more or less the same, but we can modify it in the future and even add support for custom configuration options (more specific build combinations or even passing compiler flags). The big difference between this and what bors does is that there is no merge commit. GitHub simply runs tests on the version of the branch that is on a pull request. There is always the risk that tests might start failing when a branch is rebased, but this offers a bit more control because you can easily rebase from the PR and the merge queue will check this as well.
This commit is contained in:
parent
dfeced5a8e
commit
7508d8321a
3 changed files with 203 additions and 60 deletions
|
@ -156,28 +156,24 @@ def get_github_run_url() -> Optional[str]:
|
|||
return f"[#{run_id}](https://github.com/{repository}/actions/runs/{run_id})"
|
||||
|
||||
|
||||
def is_pr_open(pr_number: str) -> bool:
|
||||
return b"open" == subprocess.check_output(
|
||||
["gh", "api", f"/repos/servo/servo/pulls/{pr_number}", "--template", "{{.state}}"])
|
||||
|
||||
|
||||
def get_pr_number() -> Optional[str]:
|
||||
github_context = json.loads(os.environ.get("GITHUB_CONTEXT", "{}"))
|
||||
if "event" not in github_context:
|
||||
return None
|
||||
if "head_commit" not in github_context["event"]:
|
||||
return None
|
||||
commit_title = github_context["event"]["head_commit"]["message"]
|
||||
match = re.match(r"^Auto merge of #(\d+)", commit_title)
|
||||
|
||||
if not match:
|
||||
return None
|
||||
# If we have a 'merge_group' in the context, this was triggered by
|
||||
# the merge queue.
|
||||
if "merge_group" in github_context["event"]:
|
||||
commit_title = github_context["event"]["merge_group"]["head_commit"]["message"]
|
||||
match = re.match(r"\(#(\d+)\)$", commit_title)
|
||||
return match.group(1) if match else None
|
||||
|
||||
# Only return a PR number if the PR is open. bors will often push old merges
|
||||
# onto the HEAD of try branches and we don't want to return results for these
|
||||
# old PRs.
|
||||
number = match.group(1)
|
||||
return number if is_pr_open(number) else None
|
||||
# If we have an 'issue' in the context, this was triggered by a try comment
|
||||
# on a PR.
|
||||
if "issue" in github_context["event"]:
|
||||
return str(github_context["event"]["issue"]["number"])
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def create_check_run(body: str, tag: str = ""):
|
||||
|
@ -246,7 +242,7 @@ def main():
|
|||
if pr_number:
|
||||
process = subprocess.Popen(
|
||||
['gh', 'pr', 'comment', pr_number, '-F', '-'], stdin=subprocess.PIPE)
|
||||
process.communicate(input=html_string.encode("utf-8"))[0]
|
||||
print(process.communicate(input=html_string.encode("utf-8"))[0])
|
||||
else:
|
||||
print("Could not find PR number in environment. Not making GitHub comment.")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue