diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index acb9c4f05a31d..e1f60c64e5c40 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,69 +1,65 @@ 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 @@ -71,7 +67,7 @@ jobs: 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 @@ -79,12 +75,12 @@ jobs: 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 @@ -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') }} diff --git a/.github/workflows/quick-check.yml b/.github/workflows/quick-check.yml deleted file mode 100644 index e7fbc28d23929..0000000000000 --- a/.github/workflows/quick-check.yml +++ /dev/null @@ -1,16 +0,0 @@ -# This action is meant as a quick check to be run when pushing to -# branches on forks. This allows forks to test the build and unit -# tests automatically without opening a pull request. -name: Quick check -on: - push: - branches: - ["**", "!master", "!auto", "!try", "!try-linux", "!try-mac", "!try-windows", "!try-wpt", "!try-wpt-2020", "!dependabot/**"] - -jobs: - build-linux: - name: Linux - if: github.repository != 'servo/servo' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/linux.yml - with: - unit-tests: true \ No newline at end of file diff --git a/.github/workflows/run-workflow-on-comment.yml b/.github/workflows/run-workflow-on-comment.yml new file mode 100644 index 0000000000000..bb6e310b22218 --- /dev/null +++ b/.github/workflows/run-workflow-on-comment.yml @@ -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 }} +