diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 0bc9055d51..91eeff5262 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -19,6 +19,7 @@ jobs: pull-requests: read outputs: has-files-requiring-all-checks: ${{ steps.filter.outputs.has-files-requiring-all-checks }} + commit-sha: ${{ steps.get_sha.outputs.commit-sha }} steps: - uses: actions/checkout@v4 - uses: ./.github/actions/dangerous-git-checkout @@ -28,59 +29,57 @@ jobs: filters: | has-files-requiring-all-checks: - "!(**.md|.github/CODEOWNERS)" + - name: Get Latest Commit SHA + id: get_sha + run: | + echo "commit-sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT check-label: + needs: [changes] runs-on: buildjet-2vcpu-ubuntu-2204 name: Check for E2E label outputs: - run-e2e: ${{ steps.check-if-pr-has-label.outputs.run-e2e == 'true' && (github.event_name != 'labeled' || (github.event_name == 'labeled' && github.event.label.name == 'ready-for-e2e')) }} - run-jobs: ${{ github.event_name != 'labeled' }} + 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: Get PR from branch name + - 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: | - let pr; - console.log('github.event_name', '${{ github.event_name }}'); - const parsedEvent = ${{ github.event }}; - if (parsedEvent && parsedEvent.pull_request) { - const response = await github.rest.pulls.get({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, - pull_number: parsedEvent.pull_request.number - }); - - pr = response.data; - } else { - const ref = '${{ github.ref }}'; - const branch = ref.replace('refs/heads/', ''); - console.log('ref', ref); - console.log('branch', branch); - const response = await github.rest.pulls.list({ + 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, - state: 'open', - head: `${context.repo.owner}:${branch}` + commit_sha: sha }); - if (response.data.length > 0) { - pr = response.data[0]; + if (prs.length === 0) { + core.setOutput('run-e2e', false); + console.log(`No pull requests found for commit SHA ${sha}`); + return; } - } - if (!pr) { + 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('No PR found'); - return; + console.log(e); } - 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); - type-check: name: Type check needs: [changes, check-label]