Skip to content

Commit b41812b

Browse files
authored
add inputs to summary (#1)
1 parent 2ee6239 commit b41812b

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

.github/workflows/test.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ jobs:
4545
- name: Run action (inputs expected)
4646
uses: ./
4747
id: print_inputs
48+
with:
49+
add_to_summary: true
4850
- name: Check output (inputs expected)
4951
run: |
5052
echo "Action output:"
@@ -56,6 +58,7 @@ jobs:
5658
echo "Test failed: Inputs were not printed as expected for workflow_dispatch event"
5759
exit 1
5860
fi
61+
5962

6063
test-env-vars:
6164
runs-on: ubuntu-latest

README.md

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Print Workflow Dispatch Inputs and Env Vars
22

3-
This GitHub Action prints all input values from a `workflow_dispatch` event to the log. Optionally, it can also print all environment variables. It's a simple and effective tool for debugging or verifying input values and environment settings in your manually triggered workflows.
3+
This GitHub Action prints all input values from a `workflow_dispatch` event to the log. Optionally, it can also print environment variables and add inputs to the GitHub Summary in a collapsible format.
44

55
## Features
66

77
- Prints all `workflow_dispatch` inputs to the log
88
- Optionally prints all environment variables
9+
- Optionally adds inputs to GitHub Summary in a collapsible format
910
- Minimal configuration required
10-
- Doesn't require a GitHub token
1111
- Lightweight and fast
1212

1313
## Usage
@@ -36,24 +36,21 @@ jobs:
3636
- name: Print Workflow Dispatch Inputs and Env Vars
3737
uses: shayki5/print-workflow-dispatch-inputs@v1
3838
with:
39-
print_env_vars: 'true' # Set 'true' to print environment variables as well (default: false)
39+
print_env_vars: 'true' # Set to 'true' to print environment variables
40+
add_to_summary: 'true' # Set to 'true' to add inputs to GitHub Summary
4041
```
4142
42-
When you manually trigger this workflow and provide values for the inputs, the action will print these input values to the log. If `print_env_vars` is set to 'true', it will also print all environment variables.
43-
4443
## Inputs
4544
4645
| Input | Description | Required | Default |
4746
|-------|-------------|----------|---------|
4847
| `print_env_vars` | Whether to print environment variables | No | 'false' |
48+
| `add_to_summary` | Whether to add inputs to GitHub Summary | No | 'false' |
4949

50-
## How it Works
51-
52-
This action reads the event payload from the `GITHUB_EVENT_PATH` environment variable, which is automatically set by GitHub Actions. It then uses `jq` to extract and print the input values. If `print_env_vars` is set to 'true', it also prints all environment variables using the `env` command.
5350

54-
## Requirements
51+
## GitHub Summary
5552

56-
This action is designed to work with `workflow_dispatch` events. It will not print inputs for other event types, but can still print environment variables if enabled.
53+
When `add_to_summary` is set to 'true', the action will add the workflow dispatch inputs to the GitHub Summary in a collapsible format. This allows you to easily view the inputs without cluttering the summary.
5754

5855
## License
5956

action.yml

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ inputs:
55
description: 'Whether to print environment variables'
66
required: false
77
default: 'false'
8+
add_to_summary:
9+
description: 'Whether to add inputs to GitHub Summary'
10+
required: false
11+
default: 'false'
812
outputs:
913
output:
1014
description: 'The output of the action'
@@ -20,6 +24,7 @@ runs:
2024
shell: bash
2125
env:
2226
PRINT_ENV_VARS: ${{ inputs.print_env_vars }}
27+
ADD_TO_SUMMARY: ${{ inputs.add_to_summary }}
2328
run: |
2429
output=$(
2530
echo "Checking for workflow_dispatch inputs:"
@@ -28,6 +33,11 @@ runs:
2833
inputs=$(jq -r '.inputs // empty' "$GITHUB_EVENT_PATH")
2934
if [ -n "$inputs" ] && [ "$inputs" != "null" ]; then
3035
echo "$inputs" | jq -r 'to_entries[] | "\(.key): \(.value)"'
36+
if [ "$ADD_TO_SUMMARY" = "true" ]; then
37+
echo -e "\n<details>\n<summary>Inputs</summary>\n\n\`\`\`" >> $GITHUB_STEP_SUMMARY
38+
echo "$inputs" | jq -r 'to_entries[] | "\(.key): \(.value)"' >> $GITHUB_STEP_SUMMARY
39+
echo -e "\`\`\`\n</details>" >> $GITHUB_STEP_SUMMARY
40+
fi
3141
else
3242
echo "No workflow_dispatch inputs found in the event payload."
3343
fi

0 commit comments

Comments
 (0)