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:
Martin Robinson 2023-07-24 17:15:33 +02:00 committed by GitHub
parent dfeced5a8e
commit 7508d8321a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 203 additions and 60 deletions

121
.github/workflows/try.yml vendored Normal file
View file

@ -0,0 +1,121 @@
on: issue_comment
name: Try
jobs:
parse-comment:
name: Process Comment
if: ${{ github.event.issue.pull_request }}
runs-on: ubuntu-latest
outputs:
configuration: ${{ steps.configuration.outputs.result }}
steps:
- uses: actions/github-script@v6
id: configuration
with:
script: |
function makeComment(body) {
console.log(body);
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
}
let tokens = "${{ github.event.comment.body }}".split(" ");
let tagIndex = tokens.indexOf("@bors-servo");
if (tagIndex == -1 || tagIndex + 1 >= tokens.length) {
return { try: false };
}
let tryString = tokens[tagIndex + 1];
console.log("Found try string: '" + tryString + "'");
let returnValue = { try: false };
if (tryString == "try") {
returnValue = { try: true, platform: 'all', layout: 'all', unit_tests: true, };
} else if (tryString == "try=wpt") {
returnValue = { try: true, platform: 'linux', layout: '2013', unit_tests: false };
} else if (tryString == "try=wpt-2020") {
returnValue = { try: true, platform: 'linux', layout: '2020', unit_tests: false };
} else if (tryString == "try=linux") {
returnValue = { try: true, platform: 'linux', layout: 'none', unit_tests: true };
} else if (tryString == "try=mac") {
returnValue = { try: true, platform: 'macos', layout: 'none', unit_tests: true };
} else if (tryString == "try=windows") {
returnValue = { try: true, platform: 'windows', layout: 'none', unit_tests: true };
} else {
makeComment("🤔 Unknown try string '" + tryString + "'");
return returnValue;
}
if (returnValue.try) {
let result = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: "${{ github.event.sender.login }}"
});
if (!result.data.user.permissions.push) {
makeComment('🔒 User @${{ github.event.sender.login }} does not have permission to trigger try jobs.');
return { try: false };
}
}
const url = context.serverUrl +
"/" + context.repo.owner +
"/" + context.repo.repo +
"/actions/runs/" + context.runId;
const formattedURL = "[#" + context.runId + "](" + url + ")";
makeComment("🔨 Triggering try run (" + formattedURL + ") with platform=" + returnValue.platform + " and layout=" + returnValue.layout);
return returnValue;
run-try:
name: Run Try
needs: ["parse-comment"]
if: ${{ fromJson(needs.parse-comment.outputs.configuration).try}}
uses: ./.github/workflows/main.yml
with:
platform: ${{ fromJson(needs.parse-comment.outputs.configuration).platform }}
layout: ${{ fromJson(needs.parse-comment.outputs.configuration).layout }}
unit-tests: ${{ fromJson(needs.parse-comment.outputs.configuration).unit_tests }}
results:
name: Results
needs: ["parse-comment", "run-try"]
runs-on: ubuntu-latest
if: ${{ always() && fromJson(needs.parse-comment.outputs.configuration).try}}
steps:
- name: Success
if: ${{ !contains(join(needs.*.result, ','), 'failure') }}
uses: actions/github-script@v6
with:
script: |
const url = context.serverUrl +
"/" + context.repo.owner +
"/" + context.repo.repo +
"/actions/runs/" + context.runId;
const formattedURL = "[#" + context.runId + "](" + url + ")";
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "✨ Try run (" + formattedURL + ") " + "succeeded.",
});
- name: Failure
if: ${{ contains(join(needs.*.result, ','), 'failure') }}
uses: actions/github-script@v6
with:
script: |
const url = context.serverUrl +
"/" + context.repo.owner +
"/" + context.repo.repo +
"/actions/runs/" + context.runId;
const formattedURL = "[#" + context.runId + "](" + url + ")";
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "⚠️ Try run (" + formattedURL + ") " + "failed.",
});