From f2882879d8d345c62d8d1d076485af6280e54dde Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Thu, 21 Dec 2023 16:12:54 +0100 Subject: [PATCH] Fix the try build when pushing to branches (#30903) Make it so that all try builds go through try.yml and pass workflow_call arguments as expected to subsequent workflows. Co-authored-by: Samson <16504129+sagudev@users.noreply.github.com> --- .github/workflows/linux-wpt.yml | 2 +- .github/workflows/linux.yml | 10 +++--- .github/workflows/mac.yml | 8 ++--- .github/workflows/main.yml | 2 +- .github/workflows/try.yml | 60 ++++++++++++++++++++------------- .github/workflows/windows.yml | 4 +-- 6 files changed, 47 insertions(+), 39 deletions(-) diff --git a/.github/workflows/linux-wpt.yml b/.github/workflows/linux-wpt.yml index 9f18e80ba18..7ac08bfb861 100644 --- a/.github/workflows/linux-wpt.yml +++ b/.github/workflows/linux-wpt.yml @@ -113,7 +113,7 @@ jobs: report-test-results: name: Report WPT Results runs-on: ubuntu-latest - if: ${{ always() && !cancelled() && (github.ref_name == 'try-wpt' || github.ref_name == 'try-wpt-2020' || inputs.wpt == 'test') }} + if: ${{ always() && !cancelled() && inputs.wpt == 'test' }} needs: - "linux-wpt" steps: diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index c01dd0170d0..f89d791d535 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -47,8 +47,6 @@ on: required: false default: false type: boolean - push: - branches: ["try-linux", "try-wpt", "try-wpt-2020"] env: RUST_BACKTRACE: 1 @@ -96,11 +94,11 @@ jobs: - name: Build (${{ inputs.profile }}) run: python3 ./mach build --${{ inputs.profile }} - name: Smoketest - run: xvfb-run python3 ./mach smoketest --${{ inputs.profile }} + run: xvfb-run python3 ./mach smoketest --${{ inputs.profile }} - name: Script tests run: ./mach test-scripts - name: Unit tests - if: ${{ inputs.unit-tests || github.ref_name == 'try-linux' }} + if: ${{ inputs.unit-tests }} uses: nick-fields/retry@v2 with: timeout_minutes: 20 @@ -142,7 +140,7 @@ jobs: path: target.tar.gz wpt-2020: - if: ${{ github.ref_name == 'try-wpt-2020' || inputs.layout == '2020' || inputs.layout == 'all' }} + if: ${{ inputs.layout == '2020' || inputs.layout == 'all' }} name: Linux WPT Tests 2020 needs: ["build"] uses: ./.github/workflows/linux-wpt.yml @@ -153,7 +151,7 @@ jobs: secrets: inherit wpt-2013: - if: ${{ github.ref_name == 'try-wpt' || inputs.layout == '2013' || inputs.layout == 'all' }} + if: ${{ inputs.layout == '2013' || inputs.layout == 'all' }} name: Linux WPT Tests 2013 needs: ["build"] uses: ./.github/workflows/linux-wpt.yml diff --git a/.github/workflows/mac.yml b/.github/workflows/mac.yml index e7e0b2c75bd..5e2b6948853 100644 --- a/.github/workflows/mac.yml +++ b/.github/workflows/mac.yml @@ -40,8 +40,6 @@ on: required: false default: false type: boolean - push: - branches: ["try-mac", "try-wpt-mac", "try-wpt-mac-2020"] env: RUST_BACKTRACE: 1 @@ -97,7 +95,7 @@ jobs: - name: Script tests run: ./mach test-scripts - name: Unit tests - if: ${{ inputs.unit-tests || github.ref_name == 'try-mac' }} + if: ${{ inputs.unit-tests }} uses: nick-fields/retry@v2 with: timeout_minutes: 20 # https://github.com/servo/servo/issues/30275 @@ -143,7 +141,7 @@ jobs: path: target.tar.gz wpt-2020: - if: ${{ github.ref_name == 'try-wpt-mac-2020' || inputs.wpt-layout == '2020' || inputs.wpt-layout == 'all' }} + if: ${{ inputs.wpt-layout == '2020' || inputs.wpt-layout == 'all' }} name: Mac WPT Tests 2020 needs: ["build"] uses: ./.github/workflows/mac-wpt.yml @@ -153,7 +151,7 @@ jobs: secrets: inherit wpt-2013: - if: ${{ github.ref_name == 'try-wpt-mac' || inputs.wpt-layout == '2013' || inputs.wpt-layout == 'all' }} + if: ${{ inputs.wpt-layout == '2013' || inputs.wpt-layout == 'all' }} name: Mac WPT Tests 2013 needs: ["build"] uses: ./.github/workflows/mac-wpt.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a372b3c0ebe..d841afd5095 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ on: # Run the entire pipeline for 'main' 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: ["main", "try"] + branches: ["main"] pull_request: types: ['opened', 'synchronize'] branches: ["**"] diff --git a/.github/workflows/try.yml b/.github/workflows/try.yml index 3644fcbbfc4..e6d4a97773d 100644 --- a/.github/workflows/try.yml +++ b/.github/workflows/try.yml @@ -3,6 +3,8 @@ name: Try on: pull_request_target: types: [labeled] + push: + branches: ["try", "try-linux", "try-mac", "try-wpt-mac", "try-wpt-mac-2020", "try-wpt", "try-wpt-2020", "try-windows"] jobs: parse-comment: @@ -19,6 +21,10 @@ jobs: script: | function makeComment(body) { console.log(body); + + if (github.event_name != 'pull_request_target') + return; + github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, @@ -62,7 +68,7 @@ jobs: if (tryString.includes("linux")) { addPlatformToConfiguration("linux", configuration); configuration.unit_tests = true; - } else if (tryString.includes("macos")) { + } else if (tryString.includes("mac")) { addPlatformToConfiguration("macos", configuration); configuration.unit_tests = true; } else if (tryString.includes("win")) { @@ -86,28 +92,36 @@ jobs: unit_tests: false, }; - let try_labels = []; - for (const label of context.payload.pull_request.labels) { - if (!label.name.startsWith("T-")) { - continue; - } + if (github.event_name == 'pull_request_target') { + 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; - } + // 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("Found label: " + label.name); + updateConfigurationFromString(label.name, configuration); + } + } else { + let ref_name = "${{ github.ref_name || 'empty' }}"; + if (ref_name == "try") { + updateConfigurationFromString("full", configuration); + } else { + updateConfigurationFromString(ref_name, configuration); + } } console.log(JSON.stringify(configuration)); @@ -152,7 +166,7 @@ jobs: if: ${{ always() && fromJson(needs.parse-comment.outputs.configuration).platforms[0] != null }} steps: - name: Success - if: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }} + if: ${{ github.event_name == 'pull_request_target' && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }} uses: actions/github-script@v6 with: script: | @@ -168,7 +182,7 @@ jobs: body: "✨ Try run (" + formattedURL + ") " + "succeeded.", }); - name: Failure - if: ${{ contains(needs.*.result, 'failure') }} + if: ${{ github.event_name == 'pull_request_target' && contains(needs.*.result, 'failure') }} uses: actions/github-script@v6 with: script: | diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index c2f76078f91..a17dbec89a2 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -32,8 +32,6 @@ on: required: false default: false type: boolean - push: - branches: ["try-windows"] env: RUST_BACKTRACE: 1 @@ -89,7 +87,7 @@ jobs: - name: Smoketest run: python mach smoketest --angle --${{ inputs.profile }} - name: Unit tests - if: ${{ inputs.unit-tests || github.ref_name == 'try-windows' }} + if: ${{ inputs.unit-tests }} uses: nick-fields/retry@v2 with: timeout_minutes: 30