Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
name: validate
runs-on: ubuntu-latest
steps:
- uses: hwrok/print-workflow-data@v1

- name: checkout
uses: actions/checkout@v6

- uses: ./

- name: pnpm
uses: pnpm/action-setup@v4
with:
Expand Down
101 changes: 95 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,104 @@
# Print Workflow Data

Prints most of the data from the `github` object, as well as matrix context, job context, runner context, and optionally passed inputs, needs, and vars from the caller.
Composite action that prints GitHub Actions context data for debugging. Outputs formatted, color-coded sections for github, matrix, job, runner contexts, plus optional caller-provided data.

See [github documentation](https://docs.github.com/en/actions/reference/workflows-and-actions/contexts) for information about each context and what certain values may mean.
Designed to run at the top of a workflow. Swallows errors to not fail workflows.

## example usage:
## Usage

```yaml
- uses: hwrok/print-workflow-data@v1
```

### With optional inputs

```yaml
- uses: hwrok/print-workflow-data@v1
with:
caller-inputs: ${{ toJSON(inputs) }} # optional
caller-needs: ${{ toJSON(needs) }} # optional
caller-vars: ${{ toJSON(vars) }} # optional
caller-inputs: ${{ toJSON(inputs) }}
caller-needs: ${{ toJSON(needs) }}
caller-vars: ${{ toJSON(vars) }}
extras: ${{ toJSON(matrix) }}
```

## Inputs

| Input | Description | Required |
| --------------- | ------------------------------------------------ | -------- |
| `caller-inputs` | Workflow inputs — `${{ toJSON(inputs) }}` | No |
| `caller-needs` | Job dependency results — `${{ toJSON(needs) }}` | No |
| `caller-vars` | Repository/org variables — `${{ toJSON(vars) }}` | No |
| `extras` | Any additional data, ideally as `toJSON(...)` | No |

## Output

JSON objects are automatically formatted as aligned key-value tables (requires `jq` on the runner, falls back to raw JSON otherwise).

```
┌────────────────┐
│ github context │
└────────────────┘
github.repository : org/repo
github.actor : some_user
github.triggering_actor : some_user
github.job : build
github.workflow : Build and Test
github.workflow_ref : org/repo/.github/workflows/build.yml@refs/heads/main
github.run_id : 123456789
github.run_number : 42
github.run_attempt : 1
github.event_name : push
github.event.action :
github.event.pr_number :
github.base_ref :
github.head_ref :
is_default_branch : true
is_default_target : false
github.ref : refs/heads/main
github.ref_name : main
github.sha : abc1234def5678
┌────────────────┐
│ matrix context │
└────────────────┘
n/a
┌─────────────┐
│ job context │
└─────────────┘
check_run_id : 63441063310
status : success
┌────────────────┐
│ runner context │
└────────────────┘
arch : X64
environment : github-hosted
name : runner-1
os : Linux
┌───────────────┐
│ caller inputs │
└───────────────┘
n/a
┌──────────────┐
│ caller needs │
└──────────────┘
n/a
┌─────────────┐
│ caller vars │
└─────────────┘
n/a
┌────────┐
│ extras │
└────────┘
n/a
```

Section headers are color-coded green in the actual workflow logs. Sections with no data display `n/a`.

## Notes

- `caller-vars` exposes repository/org-level variables. Generally safe unless secrets have been stored as variables instead of secrets.
- `extras` accepts any string, but `toJSON(...)` format gets the nicest output.
- The action uses `continue-on-error: true` and `exit 0` — it will never fail a calling workflow.

## License

MIT
3 changes: 3 additions & 0 deletions action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
[ "$GITHUB_BASE_REF" = "$DEFAULT_BRANCH" ] && is_default_target="true"

github_context_body=$(cat <<EOF
github.repository : $GITHUB_REPOSITORY
github.actor : $GITHUB_ACTOR
github.triggering_actor : $TRIGGERING_ACTOR
github.job : $GITHUB_JOB
github.workflow : $GITHUB_WORKFLOW
github.workflow_ref : $GITHUB_WORKFLOW_REF
github.run_id : $GITHUB_RUN_ID
github.run_number : $GITHUB_RUN_NUMBER
github.run_attempt : $GITHUB_RUN_ATTEMPT
github.event_name : $GITHUB_EVENT_NAME
github.event.action : $EVENT_ACTION
github.event.pr_number : $PR_NUMBER
github.base_ref : $GITHUB_BASE_REF
github.head_ref : $GITHUB_HEAD_REF
is_default_branch : $is_default_branch
Expand Down
7 changes: 4 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ branding:

inputs:
caller-inputs:
description: '`caller-inputs: ${{ toJSON(inputs) }}`'
description: 'workflow inputs as toJSON(inputs)'
required: false
default: ''
caller-needs:
description: '`caller-needs: ${{ toJSON(needs) }}`'
description: 'job dependency results as toJSON(needs)'
required: false
default: ''
caller-vars:
description: 'pass via `caller-vars: ${{ toJSON(vars) }}` (generally safe unless secrets have been mismanaged)'
description: 'repository/org variables as toJSON(vars) generally safe unless secrets have been mismanaged'
required: false
default: ''
extras:
Expand All @@ -32,6 +32,7 @@ runs:
env:
TRIGGERING_ACTOR: ${{ github.triggering_actor }}
EVENT_ACTION: ${{ github.event.action }}
PR_NUMBER: ${{ github.event.pull_request.number }}
DEFAULT_BRANCH: ${{ github.event && github.event.repository && github.event.repository.default_branch }}
MATRIX_CONTEXT: ${{ matrix && toJSON(matrix) || 'n/a' }}
JOB_CONTEXT: ${{ toJSON(job) }}
Expand Down
3 changes: 3 additions & 0 deletions tests/full-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ setup() {
}

set_all_env_vars() {
export GITHUB_REPOSITORY="owner/repo"
export GITHUB_ACTOR="testuser"
export TRIGGERING_ACTOR="testuser"
export GITHUB_JOB="build"
export GITHUB_WORKFLOW="CI"
export GITHUB_WORKFLOW_REF="owner/repo/.github/workflows/ci.yml@refs/heads/main"
export GITHUB_RUN_ID="123456789"
export GITHUB_RUN_NUMBER="42"
export GITHUB_RUN_ATTEMPT="1"
export GITHUB_EVENT_NAME="push"
export EVENT_ACTION=""
export PR_NUMBER=""
export GITHUB_BASE_REF=""
export GITHUB_HEAD_REF=""
export DEFAULT_BRANCH="main"
Expand Down
7 changes: 5 additions & 2 deletions tests/snapshots/full-run.expected.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
┌────────────────┐
│ github context │
└────────────────┘
github.repository : owner/repo
github.actor : testuser
github.triggering_actor : testuser
github.job : build
github.workflow : CI
github.workflow_ref : owner/repo/.github/workflows/ci.yml@refs/heads/main
github.run_id : 123456789
github.run_number : 42
github.run_attempt : 1
github.event_name : push
github.event.action :
github.event.pr_number :
github.base_ref :
github.head_ref :
is_default_branch : true
Expand Down Expand Up @@ -46,8 +49,8 @@ some_dep : {"result":"success"}
┌─────────────┐
│ caller vars │
└─────────────┘
SOME_VAR : the_value
SOME_VAR : the-value
┌────────┐
│ extras │
└────────┘
custom : data
custom : data