From 80bcbcfb8724fc945f082bbc868c9b94243453ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Sieroci=C5=84ski?= Date: Tue, 4 Feb 2025 06:44:46 +0100 Subject: [PATCH] feat: Use step debugging instead custom verbose input --- README.md | 15 +++++++++++++-- action.yaml | 6 ------ src/alert.sh | 8 +++----- src/payload.sh | 2 +- src/validate.sh | 2 +- test/test_helper/common.bash | 1 + 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index cdcd5e4..5e35653 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,13 @@ This GitHub Action creates an alerts in [OpsGenie](https://www.atlassian.com/software/opsgenie). +## Pre-requisites + +To use this GitHub Action, you need to have: + +* an OpsGenie account and an API key +* have following tools installed on your runner: jq, curl (both are usually pre-installed on GitHub-hosted runners, but you might need to install them on self-hosted runners) + ## Usage ```yaml @@ -30,7 +37,6 @@ This GitHub Action creates an alerts in [OpsGenie](https://www.atlassian.com/sof | `priority` | No | Priority level of the alert. Default value is P3. | Possible values: P1, P2, P3, P4, P5 | | `user` | No | Display name of the request owner | 100 characters | | `note` | No | Additional note that will be added while creating the alert | 25000 characters | -| `verbose` | No | Enable verbose mode for _curl_ | | Please note that fields that are _arrays_ or _objects_ should be valid JSON arrays/objects. See examples below. @@ -63,11 +69,16 @@ jobs: Run number ${{ github.run_number }} of workflow ${{ github.workflow }} has failed!
Open run in new window tags: '["tag1", "tag2"]' # Note that this is an JSON array but between apostophes. You can use doublequotes, but you will need to do the escaping. - verbose: "true" # For debugging purposes you can enable verbose mode for curl (which is used under the hood) ``` +### Debugging + +To see the debug logs (for _curl_ too), you can either click checkbox _Enable debug logging_ while re-running the failed job +or you can enable debugging for whole repo by adding the following secret to your repository: `ACTIONS_STEP_DEBUG` with value `true`. +You can read more about it [here](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/troubleshooting-workflows/enabling-debug-logging#enabling-step-debug-logging). + ## Resources * Create OpsGenie API key with [an API integration](https://support.atlassian.com/opsgenie/docs/create-a-default-api-integration/) diff --git a/action.yaml b/action.yaml index 6e2e712..3cc9873 100644 --- a/action.yaml +++ b/action.yaml @@ -69,11 +69,6 @@ inputs: description: 'Additional note that will be added while creating the alert. (Limit: 25000 characters)' required: false - verbose: - description: 'Enable curl verbose output' - default: "false" - required: false - runs: using: composite steps: @@ -96,4 +91,3 @@ runs: input_priority: ${{ inputs.priority }} input_user: ${{ inputs.user }} input_note: ${{ inputs.note }} - input_verbose: ${{ inputs.verbose }} diff --git a/src/alert.sh b/src/alert.sh index cd8f2ac..004e7e6 100755 --- a/src/alert.sh +++ b/src/alert.sh @@ -4,7 +4,7 @@ set -e -SCRIPT_DIR="$(cd "$(dirname "$@")" >/dev/null 2>&1 && pwd)" +export SCRIPT_DIR="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)" source "$SCRIPT_DIR/helpers/log_helpers.sh" source "$SCRIPT_DIR/payload.sh" @@ -32,8 +32,6 @@ input_user=$(trim "$input_user") input_note=$(trim "$input_note") input_message=$(trim "$input_message") -input_verbose=$(trim "$input_verbose") - log_debug "Preparing request..." req_type="POST" req_url="${input_apiUrl}/alerts" @@ -57,14 +55,14 @@ payload=$(get_payload \ ) log_debug "Sending request..." -if [[ $input_verbose == "true" ]]; then +if [[ -n $RUNNER_DEBUG ]]; then curl --request "${req_type}" \ --url "${req_url}" \ --header "${req_header_auth}" \ --header "${req_header_content}" \ --data "${payload}" \ --fail \ - --verbose + -vvv else curl --request "${req_type}" \ --url "${req_url}" \ diff --git a/src/payload.sh b/src/payload.sh index 0a5ed0c..567d418 100644 --- a/src/payload.sh +++ b/src/payload.sh @@ -4,7 +4,7 @@ set -e -SCRIPT_DIR="$(cd "$(dirname "$@")" >/dev/null 2>&1 && pwd)" +# SCRIPT_DIR="$(cd "$(dirname "$@")" >/dev/null 2>&1 && pwd)" source "$SCRIPT_DIR/helpers/log_helpers.sh" source "$SCRIPT_DIR/helpers/json_helpers.sh" diff --git a/src/validate.sh b/src/validate.sh index b4635f3..5d758ba 100644 --- a/src/validate.sh +++ b/src/validate.sh @@ -4,7 +4,7 @@ set -e -SCRIPT_DIR="$(cd "$(dirname "$@")" >/dev/null 2>&1 && pwd)" +# SCRIPT_DIR="$(cd "$(dirname "$@")" >/dev/null 2>&1 && pwd)" source "$SCRIPT_DIR/helpers/log_helpers.sh" source "$SCRIPT_DIR/helpers/json_helpers.sh" diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index dda13e7..e011581 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -1,6 +1,7 @@ DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." >/dev/null 2>&1 && pwd)" PATH="$DIR/../src:$PATH" +SCRIPT_DIR="$DIR/src" ORIGINAL_GITHUB_ACTIONS=$GITHUB_ACTIONS function common_setup() {