Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summary #2

Merged
merged 8 commits into from
Jul 28, 2024
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
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
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Print Workflow Dispatch Inputs and Env Vars
# Print Workflow Dispatch Inputs

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
14 changes: 12 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name: 'Print Workflow Dispatch Inputs and Env Vars'
description: 'A GitHub Action that prints all workflow_dispatch input values and optionally environment variables to the log'
name: 'Print Workflow Dispatch Inputs'
description: 'A GitHub Action that prints all workflow_dispatch input values and optionally environment variables to the log. optionally can add inputs to the GitHub Summary in a collapsible format.'
inputs:
print_env_vars:
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
Loading