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 3097f31
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 66 deletions.
96 changes: 46 additions & 50 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,90 +1,86 @@
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";
if (!['pull_request', 'merge_group', 'workflow_run'].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"
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 +95,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.

64 changes: 64 additions & 0 deletions .github/workflows/run-workflow-on-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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: |
let tokens = "${{ github.event.comment.body }}".split(" ");
console.log(tokens);
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' };
}
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) {
console.log("User does not have permission to try.");
return { try: false };
}
}
console.log("Triggering try with configuration: " + JSON.stringify(returnValue));
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 }}

0 comments on commit 3097f31

Please sign in to comment.