|
18 | 18 | run: | |
19 | 19 | echo "$GITHUB_CONTEXT" |
20 | 20 | echo "$GITHUB_CONTEXT" | jq -c '.event.pull_request.commits' |
| 21 | + - name: Get run count for this PR |
| 22 | + id: pr_runs |
| 23 | + run: | |
| 24 | + PR_NUMBER=${{ github.event.pull_request.number }} |
| 25 | + echo "PR_NUMBER: ${PR_NUMBER}" |
| 26 | + COUNT=$(gh api \ |
| 27 | + repos/${{ github.repository }}/actions/runs \ |
| 28 | + --jq '.workflow_runs | map(select(.pull_requests[].number == '"$PR_NUMBER"')) | length') |
| 29 | + echo "COUNT: ${COUNT}" |
| 30 | + echo "count=$COUNT" >> $GITHUB_OUTPUT |
| 31 | + - name: Count test runs for this PR |
| 32 | + if: ${{ !cancelled() }} |
| 33 | + id: count |
| 34 | + uses: actions/github-script@v9 |
| 35 | + with: |
| 36 | + script: | |
| 37 | + const pr_number = context.payload.pull_request.number; |
| 38 | + const workflow_name = context.workflow; |
| 39 | + console.log(pr_number); |
| 40 | + console.log(workflow_name); |
| 41 | +
|
| 42 | + if (!prNumber) { |
| 43 | + console.log("No pull request number found in context."); |
| 44 | + core.setOutput("count", 0); |
| 45 | + return; |
| 46 | + } |
| 47 | +
|
| 48 | + const runs = await github.rest.actions.listWorkflowRunsForRepo({ |
| 49 | + owner: context.repo.owner, |
| 50 | + repo: context.repo.repo, |
| 51 | + event: "pull_request", |
| 52 | + per_page: 100 |
| 53 | + }); |
| 54 | + console.log(runs); |
| 55 | +
|
| 56 | + const filtered = runs.data.workflow_runs.filter(run => |
| 57 | + run.name === workflow_name && |
| 58 | + run.event === "pull_request" && |
| 59 | + run.pull_requests?.some(p => p.number === pr_number) |
| 60 | + ); |
| 61 | + console.log(filtered); |
| 62 | + console.log(filtered.length); |
| 63 | +
|
| 64 | + core.setOutput("count", filtered.length); |
| 65 | + - name: Dump job context |
| 66 | + run: echo "Test run count = ${{ steps.count.outputs.count }}" |
21 | 67 | - name: Dump job context |
22 | 68 | env: |
23 | 69 | JOB_CONTEXT: ${{ toJson(job) }} |
|
0 commit comments