Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/context.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---

# 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 = context.payload.pull_request;

if (!pr) {
core.setFailed("This workflow must be triggered by a pull request.");
return;
}

const pr_number = pr.number;
const workflow_name = context.workflow;
const branch_name = pr.head.ref;
const event_match = "pull_request";
console.log(pr_number);
console.log(workflow_name);
console.log(branch_name);

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,
branch: branch_name,
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"
Loading