Skip to content

Commit

Permalink
Add try support via GitHub action
Browse files Browse the repository at this point in the history
  • Loading branch information
mrobinson committed Jul 19, 2023
1 parent ae3f33b commit b71c7e6
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 68 deletions.
101 changes: 49 additions & 52 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,90 +1,87 @@
name: Main

on:
push:
# Run the entire pipeline for 'master' even though the merge queue already runs checks
# for every change. This just offers an extra layer of testing and covers the case of
# random force pushes.
branches: ["master", "try"]
pull_request:
types: ['opened', 'synchronize']
branches: ["**"]
merge_group:
types: [checks_requested]
workflow_dispatch:
workflow_call:
inputs:
platform:
required: true
type: string
layout:
required: true
type: string

jobs:
decision:
name: Decision
runs-on: ubuntu-20.04
outputs:
skipped: ${{ steps.skipDecision.outputs.result }}
platforms: ${{ steps.platformDecision.outputs.result }}
configuration: ${{ steps.configuration.outputs.result }}
steps:
- name: Skip Decision
id: skipDecision
- name: Configuration
id: configuration
uses: actions/github-script@v6
with:
result-encoding: string
script: |
// Never skip workflow runs for pull requests or merge groups, which might
// need to actually run / retry WPT tests.
if (context.eventName == "pull_request" || context.eventName == "merge_group") {
return "run";
// Never skip workflow runs for pull requests, merge groups, or manually triggered
// workfows / try jobs, which might need to actually run / retry WPT tests.
if (!['pull_request', 'merge_group', 'workflow_run', 'workflow_call'].includes(context.eventName)) {
// Skip the run if an identical run already exists. This helps to avoid running
// the workflow over and over again for the same commit hash.
if ((await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: "main.yml",
head_sha: context.sha,
status: "success",
})).data.workflow_runs.length > 0) {
console.log("Skipping workflow, because of duplicate job.");
return { platform: "none" };
}
}
// Skip the run if an identical run already exists. This helps to avoid running
// the workflow over and over again for the same commit hash.
if ((await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: "main.yml",
head_sha: context.sha,
status: "success",
})).data.workflow_runs.length > 0) {
return "skip"
} else {
return "run"
}
- name: Platform Decision
id: platformDecision
uses: actions/github-script@v6
with:
result-encoding: string
script: |
if ("${{ steps.skipDecision.outputs.result }}" == "skip") {
return "none";
}
if (context.eventName == "push" || context.eventName == "merge_group") {
return "all";
}
return "linux"
console.log("EVENT: " + context.eventName);
let platform = "linux";
let layout = "none";
if (context.eventName == "workflow_call") {
platform = "${{ inputs.platform }}";
layout = "${{ inputs.layout }}";
} else if (["push", "merge_group"].includes(context.eventName)) {
platform = "all";
layout = "all";
}
let returnValue = {
platform,
layout,
unit_tests: ['push', 'merge_group', 'workflow_call'].includes(context.eventName)
};
console.log("Using configuration: " + JSON.stringify(returnValue));
return returnValue;
build-win:
name: Windows
needs: ["decision"]
if: ${{ needs.decision.outputs.platforms == 'all' }}
if: ${{ contains(fromJson('["windows", "all"]'), fromJson(needs.decision.outputs.configuration).platform) }}
uses: ./.github/workflows/windows.yml
with:
unit-tests: true

build-mac:
name: Mac
needs: ["decision"]
if: ${{ needs.decision.outputs.platforms == 'all' }}
if: ${{ contains(fromJson('["macos", "all"]'), fromJson(needs.decision.outputs.configuration).platform) }}
uses: ./.github/workflows/mac.yml
with:
unit-tests: true

build-linux:
name: Linux
needs: ["decision"]
if: ${{ needs.decision.outputs.platforms == 'all' || needs.decision.outputs.platforms == 'linux' }}
if: ${{ contains(fromJson('["linux", "all"]'), fromJson(needs.decision.outputs.configuration).platform) }}
uses: ./.github/workflows/linux.yml
with:
wpt: 'test'
layout: ${{ (github.event_name == 'push' || github.event_name == 'merge_group') && 'all' || 'none' }}
unit-tests: ${{ github.event_name == 'push' || github.event_name == 'merge_group' }}
layout: ${{ fromJson(needs.decision.outputs.configuration).layout }}
unit-tests: ${{ fromJson(needs.decision.outputs.configuration).unit_tests }}

build-result:
name: Result
Expand All @@ -99,7 +96,7 @@ jobs:

steps:
- name: Mark skipped jobs as successful
if: ${{ needs.decision.outputs.skipped == 'skip' }}
if: ${{ fromJson(needs.decision.outputs.configuration).platform == 'none' }}
run: exit 0
- name: Mark the job as successful
if: ${{ !contains(join(needs.*.result, ','), 'failure') && !contains(join(needs.*.result, ','), 'cancelled') }}
Expand Down
16 changes: 0 additions & 16 deletions .github/workflows/quick-check.yml

This file was deleted.

120 changes: 120 additions & 0 deletions .github/workflows/run-workflow-on-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
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' };
} else if (tryString == "try=wpt") {
returnValue = { try: true, platform: 'linux', layout: '2013' };
} else if (tryString == "try=wpt-2020") {
returnValue = { try: true, platform: 'linux', layout: '2020' };
} else if (tryString == "try=linux") {
returnValue = { try: true, platform: 'linux', layout: 'none' };
} else if (tryString == "try=mac") {
returnValue = { try: true, platform: 'macos', layout: 'none' };
} else if (tryString == "try=windows") {
returnValue = { try: true, platform: 'windows', layout: 'none' };
} 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 }}

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.",
});

0 comments on commit b71c7e6

Please sign in to comment.