diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index effcfb6..a727e13 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -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:" @@ -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 diff --git a/README.md b/README.md index 6649096..8b3bc51 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/action.yml b/action.yml index 6e6af24..abdd443 100644 --- a/action.yml +++ b/action.yml @@ -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' @@ -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:" @@ -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
\nInputs\n\n\`\`\`" >> $GITHUB_STEP_SUMMARY + echo "$inputs" | jq -r 'to_entries[] | "\(.key): \(.value)"' >> $GITHUB_STEP_SUMMARY + echo -e "\`\`\`\n
" >> $GITHUB_STEP_SUMMARY + fi else echo "No workflow_dispatch inputs found in the event payload." fi