Skip to content

Commit

Permalink
add inputs to summary (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
shayki5 authored Jul 25, 2024
1 parent 2ee6239 commit b41812b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:
- name: Run action (inputs expected)
uses: ./
id: print_inputs
with:
add_to_summary: true
- name: Check output (inputs expected)
run: |
echo "Action output:"
Expand All @@ -56,6 +58,7 @@ jobs:
echo "Test failed: Inputs were not printed as expected for workflow_dispatch event"
exit 1
fi

test-env-vars:
runs-on: ubuntu-latest
Expand Down
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Print Workflow Dispatch Inputs and Env Vars

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.
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.

## Features

- Prints all `workflow_dispatch` inputs to the log
- Optionally prints all environment variables
- Optionally adds inputs to GitHub Summary in a collapsible format
- Minimal configuration required
- Doesn't require a GitHub token
- Lightweight and fast

## Usage
Expand Down Expand Up @@ -36,24 +36,21 @@ jobs:
- name: Print Workflow Dispatch Inputs and Env Vars
uses: shayki5/print-workflow-dispatch-inputs@v1
with:
print_env_vars: 'true' # Set 'true' to print environment variables as well (default: false)
print_env_vars: 'true' # Set to 'true' to print environment variables
add_to_summary: 'true' # Set to 'true' to add inputs to GitHub Summary
```
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.

## Inputs
| Input | Description | Required | Default |
|-------|-------------|----------|---------|
| `print_env_vars` | Whether to print environment variables | No | 'false' |
| `add_to_summary` | Whether to add inputs to GitHub Summary | No | 'false' |

## How it Works

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.

## Requirements
## GitHub Summary

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.
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.

## License

Expand Down
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
description: 'Whether to print environment variables'
required: false
default: 'false'
add_to_summary:
description: 'Whether to add inputs to GitHub Summary'
required: false
default: 'false'
outputs:
output:
description: 'The output of the action'
Expand All @@ -20,6 +24,7 @@ runs:
shell: bash
env:
PRINT_ENV_VARS: ${{ inputs.print_env_vars }}
ADD_TO_SUMMARY: ${{ inputs.add_to_summary }}
run: |
output=$(
echo "Checking for workflow_dispatch inputs:"
Expand All @@ -28,6 +33,11 @@ runs:
inputs=$(jq -r '.inputs // empty' "$GITHUB_EVENT_PATH")
if [ -n "$inputs" ] && [ "$inputs" != "null" ]; then
echo "$inputs" | jq -r 'to_entries[] | "\(.key): \(.value)"'
if [ "$ADD_TO_SUMMARY" = "true" ]; then
echo -e "\n<details>\n<summary>Inputs</summary>\n\n\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "$inputs" | jq -r 'to_entries[] | "\(.key): \(.value)"' >> $GITHUB_STEP_SUMMARY
echo -e "\`\`\`\n</details>" >> $GITHUB_STEP_SUMMARY
fi
else
echo "No workflow_dispatch inputs found in the event payload."
fi
Expand Down

0 comments on commit b41812b

Please sign in to comment.