mirror of
https://github.com/servo/servo
synced 2026-05-13 10:27:03 +02:00
This should prevent multiple `parse-comment` jobs from running at the same time for the same pull request, reducing the number of duplicate builds when multiple labels are applied.
188 lines
7.0 KiB
YAML
188 lines
7.0 KiB
YAML
name: Try
|
|
|
|
on:
|
|
pull_request_target:
|
|
types: [labeled]
|
|
|
|
jobs:
|
|
parse-comment:
|
|
name: Trigger Try
|
|
runs-on: ubuntu-latest
|
|
concurrency:
|
|
group: try-${{ github.event.number }}
|
|
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
|
|
})
|
|
}
|
|
|
|
function combineWPTLayoutOptions(layout, newLayout) {
|
|
let has2013 = layout == "2013" || layout == "all";
|
|
let has2020 = layout == "2020" || layout == "all";
|
|
let adding2013 = newLayout == "2013";
|
|
let adding2020 = newLayout == "2020";
|
|
|
|
if ((adding2020 && has2020) || (adding2013 && has2013)) {
|
|
return layout;
|
|
}
|
|
if (adding2020) {
|
|
return has2013 ? "all" : "2020";
|
|
}
|
|
if (adding2013) {
|
|
return has2020 ? "all" : "2013";
|
|
}
|
|
return layout;
|
|
}
|
|
|
|
function addPlatformToConfiguration(platform, configuration) {
|
|
if (!configuration.platforms.includes(platform)) {
|
|
configuration.platforms.push(platform);
|
|
}
|
|
}
|
|
|
|
function updateConfigurationFromString(tryString, configuration) {
|
|
if (tryString.includes("full")) {
|
|
configuration.platforms = ["linux", "macos", "windows"];
|
|
configuration.unit_tests = true;
|
|
configuration.layout = "all";
|
|
return configuration;
|
|
}
|
|
|
|
if (tryString.includes("linux")) {
|
|
addPlatformToConfiguration("linux", configuration);
|
|
configuration.unit_tests = true;
|
|
} else if (tryString.includes("macos")) {
|
|
addPlatformToConfiguration("macos", configuration);
|
|
configuration.unit_tests = true;
|
|
} else if (tryString.includes("win")) {
|
|
addPlatformToConfiguration("windows", configuration);
|
|
configuration.unit_tests = true;
|
|
}
|
|
|
|
if (tryString.includes("wpt")) {
|
|
addPlatformToConfiguration("linux", configuration);
|
|
if (tryString.includes("2020")) {
|
|
configuration.layout = combineWPTLayoutOptions(configuration.layout, "2020");
|
|
} else {
|
|
configuration.layout = combineWPTLayoutOptions(configuration.layout, "2013");
|
|
}
|
|
}
|
|
}
|
|
|
|
let configuration = {
|
|
platforms: [],
|
|
layout: "none",
|
|
unit_tests: false,
|
|
};
|
|
|
|
let try_labels = [];
|
|
for (const label of context.payload.pull_request.labels) {
|
|
if (!label.name.startsWith("T-")) {
|
|
continue;
|
|
}
|
|
|
|
// Try to remove the label. If that fails, it's likely that another
|
|
// workflow has already processed it or a user has removed it.
|
|
try {
|
|
await github.rest.issues.removeLabel({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: context.issue.number,
|
|
name: label.name,
|
|
});
|
|
} catch (exception) {
|
|
console.log("Assuming '" + label.name + "' is already removed: " + exception);
|
|
continue;
|
|
}
|
|
|
|
console.log("Found label: " + label.name);
|
|
updateConfigurationFromString(label.name, configuration);
|
|
}
|
|
|
|
console.log(JSON.stringify(configuration));
|
|
|
|
if (configuration.platforms.length == 0) {
|
|
return { platforms: [] };
|
|
}
|
|
|
|
let username = context.payload.sender.login;
|
|
let result = await github.rest.repos.getCollaboratorPermissionLevel({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
username
|
|
});
|
|
if (!result.data.user.permissions.push) {
|
|
makeComment('🔒 User @' + username + ' does not have permission to trigger try jobs.');
|
|
return { platforms: [] };
|
|
}
|
|
|
|
const url = context.serverUrl +
|
|
"/" + context.repo.owner +
|
|
"/" + context.repo.repo +
|
|
"/actions/runs/" + context.runId;
|
|
const formattedURL = "[#" + context.runId + "](" + url + ")";
|
|
let platformsString = configuration.platforms.toString();
|
|
makeComment("🔨 Triggering try run (" + formattedURL + ") with platforms=" +
|
|
platformsString + " and layout=" + configuration.layout);
|
|
return configuration;
|
|
|
|
run-try:
|
|
name: Run Try
|
|
needs: ["parse-comment"]
|
|
if: ${{ fromJson(needs.parse-comment.outputs.configuration).platforms[0] != null }}
|
|
uses: ./.github/workflows/main.yml
|
|
with:
|
|
configuration: ${{ needs.parse-comment.outputs.configuration }}
|
|
|
|
results:
|
|
name: Results
|
|
needs: ["parse-comment", "run-try"]
|
|
runs-on: ubuntu-latest
|
|
if: ${{ always() && fromJson(needs.parse-comment.outputs.configuration).platforms[0] != null }}
|
|
steps:
|
|
- name: Success
|
|
if: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
|
|
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(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.",
|
|
});
|
|
|
|
|