Skip to content

Commit c664cb3

Browse files
committed
add files
0 parents  commit c664cb3

File tree

4 files changed

+175
-0
lines changed

4 files changed

+175
-0
lines changed

.github/workflows/test.yaml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Test Action
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
inputs:
10+
test_name:
11+
description: 'Test name input'
12+
required: true
13+
type: string
14+
test_number:
15+
description: 'Test number input'
16+
required: false
17+
type: number
18+
19+
jobs:
20+
test-inputs:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: Run action (inputs only)
25+
uses: ./
26+
- name: Check output (inputs only)
27+
run: |
28+
output=$(cat $GITHUB_STEP_SUMMARY)
29+
if [[ $output == *"test_name"* && $output == *"test_number"* ]]; then
30+
echo "Test passed: Inputs were printed correctly"
31+
else
32+
echo "Test failed: Inputs were not printed as expected"
33+
exit 1
34+
fi
35+
36+
test-inputs-and-env:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v3
40+
- name: Run action (inputs and env vars)
41+
uses: ./
42+
with:
43+
print_env_vars: 'true'
44+
- name: Check output (inputs and env vars)
45+
run: |
46+
output=$(cat $GITHUB_STEP_SUMMARY)
47+
if [[ $output == *"test_name"* && $output == *"test_number"* && $output == *"Printing environment variables:"* ]]; then
48+
echo "Test passed: Inputs and env vars were printed correctly"
49+
else
50+
echo "Test failed: Inputs or env vars were not printed as expected"
51+
exit 1
52+
fi

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Shayki Abramczyk
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Print Workflow Dispatch Inputs and Env Vars
2+
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.
4+
5+
## Features
6+
7+
- Prints all `workflow_dispatch` inputs to the log
8+
- Optionally prints all environment variables
9+
- Minimal configuration required
10+
- Doesn't require a GitHub token
11+
- Lightweight and fast
12+
13+
## Usage
14+
15+
To use this action in your workflow, add it as a step in your `workflow_dispatch` triggered workflow:
16+
17+
```yaml
18+
name: Print Inputs and Env Vars Example
19+
20+
on:
21+
workflow_dispatch:
22+
inputs:
23+
name:
24+
description: 'Your name'
25+
required: true
26+
type: string
27+
age:
28+
description: 'Your age'
29+
required: false
30+
type: number
31+
32+
jobs:
33+
print-inputs-and-env:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Print Workflow Dispatch Inputs and Env Vars
37+
uses: shayki5/print-workflow-dispatch-inputs@v1
38+
with:
39+
print_env_vars: 'true' # Set to 'true' to print environment variables
40+
```
41+
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+
44+
## Inputs
45+
46+
| Input | Description | Required | Default |
47+
|-------|-------------|----------|---------|
48+
| `print_env_vars` | Whether to print environment variables | No | 'false' |
49+
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.
53+
54+
## Requirements
55+
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.
57+
58+
## License
59+
60+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
61+
62+
## Contributing
63+
64+
Contributions, issues, and feature requests are welcome! Feel free to check [issues page](https://github.com/shayki5/print-workflow-dispatch-inputs/issues).
65+
66+
## Support
67+
68+
If you encounter any problems or have any questions, please open an issue in this repository.

action.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: 'Print Workflow Dispatch Inputs and Env Vars'
2+
description: 'A GitHub Action that prints all workflow_dispatch input values and optionally environment variables to the log'
3+
inputs:
4+
print_env_vars:
5+
description: 'Whether to print environment variables'
6+
required: false
7+
default: 'false'
8+
branding:
9+
icon: 'printer'
10+
color: 'blue'
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Print inputs & env vars
15+
shell: bash
16+
env:
17+
PRINT_ENV_VARS: ${{ inputs.print_env_vars }}
18+
run: |
19+
echo "Printing all workflow_dispatch inputs:"
20+
if [ -n "$GITHUB_EVENT_PATH" ] && [ -f "$GITHUB_EVENT_PATH" ]; then
21+
inputs=$(jq -r '.inputs // empty' "$GITHUB_EVENT_PATH")
22+
if [ -n "$inputs" ] && [ "$inputs" != "null" ]; then
23+
echo "$inputs" | jq -r 'to_entries[] | "\(.key): \(.value)"'
24+
else
25+
echo "No workflow_dispatch inputs found in the event payload."
26+
fi
27+
else
28+
echo "GITHUB_EVENT_PATH is not set or the file does not exist. This action may not be running in a workflow_dispatch context."
29+
fi
30+
31+
if [ "$PRINT_ENV_VARS" = "true" ]; then
32+
echo -e "\nPrinting environment variables:"
33+
env | sort
34+
fi

0 commit comments

Comments
 (0)