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