Filter runs by branch to tighthen the results #21
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| # this file is *not* meant to cover or endorse the use of GitHub Actions, but | |
| # rather to help make automated releases for this project | |
| name: Context testing | |
| on: [push, pull_request] # yamllint disable-line rule:truthy | |
| jobs: | |
| dump_contexts_to_log: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Dump GitHub context | |
| env: | |
| GITHUB_CONTEXT: ${{ toJson(github) }} | |
| # "event.pull_request.commits" is interesting | |
| run: | | |
| echo "$GITHUB_CONTEXT" | |
| echo "$GITHUB_CONTEXT" | jq -c '.event.pull_request.commits' | |
| - name: Count test runs for this PR | |
| if: ${{ !cancelled() }} | |
| id: count | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| const pr_number = context.payload.pull_request.number; | |
| const workflow_name = context.workflow; | |
| const branch_name = context.ref; | |
| const branch_name2 = context.head_ref; | |
| const event_match = "pull_request"; | |
| console.log(pr_number); | |
| console.log(workflow_name); | |
| console.log(branch_name); | |
| console.log(branch_name2); | |
| if (!pr_number) { | |
| console.log("No pull request number found in context."); | |
| core.setOutput("count", 0); | |
| return; | |
| } | |
| const runs = await github.rest.actions.listWorkflowRunsForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| event: event_match, | |
| per_page: 100 | |
| }); | |
| // console.log(runs); | |
| const filtered = runs.data.workflow_runs.filter(run => | |
| run.name === workflow_name && | |
| run.event === event_match && | |
| run.pull_requests?.some(p => p.number === pr_number) | |
| ); | |
| // console.log(filtered); | |
| console.log(filtered.length); | |
| core.setOutput("count", filtered.length); | |
| - name: Dump job context | |
| run: echo "Test run count = ${{ steps.count.outputs.count }}" | |
| - name: Dump job context | |
| env: | |
| JOB_CONTEXT: ${{ toJson(job) }} | |
| run: echo "$JOB_CONTEXT" | |
| - name: Dump steps context | |
| env: | |
| STEPS_CONTEXT: ${{ toJson(steps) }} | |
| run: echo "$STEPS_CONTEXT" | |
| - name: Dump runner context | |
| env: | |
| RUNNER_CONTEXT: ${{ toJson(runner) }} | |
| run: echo "$RUNNER_CONTEXT" | |
| - name: Dump strategy context | |
| env: | |
| STRATEGY_CONTEXT: ${{ toJson(strategy) }} | |
| run: echo "$STRATEGY_CONTEXT" | |
| - name: Dump matrix context | |
| env: | |
| MATRIX_CONTEXT: ${{ toJson(matrix) }} | |
| run: echo "$MATRIX_CONTEXT" |