Skip to content

Commit 50b6c12

Browse files
Count runs for this PR
1 parent 7d42b9e commit 50b6c12

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

.github/workflows/context.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,44 @@ jobs:
1818
run: |
1919
echo "$GITHUB_CONTEXT"
2020
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 = context.payload.pull_request.number;
38+
console.log(pr);
39+
40+
const runs = await github.rest.actions.listWorkflowRunsForRepo({
41+
owner: context.repo.owner,
42+
repo: context.repo.repo,
43+
event: "pull_request",
44+
per_page: 100
45+
});
46+
console.log(runs);
47+
48+
const filtered = runs.data.workflow_runs.filter(run =>
49+
run.name === "Context testing" &&
50+
run.event === "pull_request" &&
51+
run.pull_requests.some(p => p.number === pr)
52+
);
53+
console.log(filtered);
54+
console.log(filtered.length);
55+
56+
core.setOutput("count", filtered.length);
57+
- name: Dump job context
58+
run: echo "Test run count = ${{ steps.count.outputs.count }}"
2159
- name: Dump job context
2260
env:
2361
JOB_CONTEXT: ${{ toJson(job) }}

0 commit comments

Comments
 (0)