From 47a8ba1eaac3268ab27d9625c6071903388cca6f Mon Sep 17 00:00:00 2001 From: Keith Williams Date: Sun, 23 Jun 2024 12:38:59 -0300 Subject: [PATCH] chore: streamline ready-for-e2e label check for PRs (#15545) * Added a log for pull_request * Added labels logging * Using labels straight from event PR object * Converting to JSON * Switching to use payload * Fixed issue with undefined pr * Fixed non-mapping issue * Removed the types * Removed issue with run-jobs * Put back the types --- .github/workflows/pr.yml | 73 +++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index a2895b1b2efb7d..698f03458fa80c 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -41,71 +41,75 @@ jobs: name: Check for E2E label outputs: run-e2e: ${{ steps.check-if-pr-has-label.outputs.run-e2e == 'true' && (github.event.action != 'labeled' || (github.event.action == 'labeled' && github.event.label.name == 'ready-for-e2e')) }} - run-jobs: ${{ github.event.action != 'labeled' }} steps: - name: Check if PR exists with ready-for-e2e label for this SHA id: check-if-pr-has-label uses: actions/github-script@v7 with: script: | - console.log('github.event.action', '${{ github.event.action }}'); - try { - const sha = '${{ needs.changes.outputs.commit-sha }}'; - console.log('sha', sha); - const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ - owner: context.repo.owner, - repo: context.repo.repo, - commit_sha: sha - }); - - if (prs.length === 0) { + let labels = []; + + if (context.payload.pull_request) { + labels = context.payload.pull_request.labels; + } else { + try { + const sha = '${{ needs.changes.outputs.commit-sha }}'; + console.log('sha', sha); + const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ + owner: context.repo.owner, + repo: context.repo.repo, + commit_sha: sha + }); + + if (prs.length === 0) { + core.setOutput('run-e2e', false); + console.log(`No pull requests found for commit SHA ${sha}`); + return; + } + + const pr = prs[0]; + console.log(`PR number: ${pr.number}`); + console.log(`PR title: ${pr.title}`); + console.log(`PR state: ${pr.state}`); + console.log(`PR URL: ${pr.html_url}`); + + labels = pr.labels; + } + catch (e) { core.setOutput('run-e2e', false); - console.log(`No pull requests found for commit SHA ${sha}`); - return; + console.log(e); } - - const pr = prs[0]; - console.log(`PR number: ${pr.number}`); - console.log(`PR title: ${pr.title}`); - console.log(`PR state: ${pr.state}`); - console.log(`PR URL: ${pr.html_url}`); - - const labels = pr.labels.map(label => label.name); - const labelFound = labels.includes('ready-for-e2e'); - console.log('PR #', pr.number); - console.log('Found the label?', labelFound); - core.setOutput('run-e2e', labelFound); - } - catch (e) { - core.setOutput('run-e2e', false); - console.log(e); } + const labelFound = labels.map(l => l.name).includes('ready-for-e2e'); + console.log('Found the label?', labelFound); + core.setOutput('run-e2e', labelFound); + type-check: name: Type check needs: [changes, check-label] - if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + if: ${{ github.event.action != 'labeled' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} uses: ./.github/workflows/check-types.yml secrets: inherit lint: name: Linters needs: [changes, check-label] - if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + if: ${{ github.event.action != 'labeled' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} uses: ./.github/workflows/lint.yml secrets: inherit unit-test: name: Tests needs: [changes, check-label] - if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + if: ${{ github.event.action != 'labeled' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} uses: ./.github/workflows/unit-tests.yml secrets: inherit integration-test: name: Tests needs: [changes, check-label] - if: ${{ needs.check-label.outputs.run-jobs == 'true' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} + if: ${{ github.event.action != 'labeled' && needs.changes.outputs.has-files-requiring-all-checks == 'true' }} uses: ./.github/workflows/integration-tests.yml secrets: inherit @@ -166,7 +170,6 @@ jobs: required: needs: [changes, lint, type-check, unit-test, integration-test, check-label, build, build-api-v1, build-api-v2, e2e, e2e-embed, e2e-embed-react, e2e-app-store] - if: ${{ needs.check-label.outputs.run-e2e == 'true' }} runs-on: buildjet-2vcpu-ubuntu-2204 steps: - name: fail if conditional jobs failed