Skip to content

Commit

Permalink
feat: Use step debugging instead custom verbose input
Browse files Browse the repository at this point in the history
  • Loading branch information
marverix committed Feb 4, 2025
1 parent a516e7b commit 80bcbcf
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -63,11 +69,16 @@ jobs:
Run number ${{ github.run_number }} of workflow <i>${{ github.workflow }}</i> has failed!<br>
<a href="${{ env.RUN_URL }}" target="_blank">Open run in new window</a>
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/)
Expand Down
6 changes: 0 additions & 6 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -96,4 +91,3 @@ runs:
input_priority: ${{ inputs.priority }}
input_user: ${{ inputs.user }}
input_note: ${{ inputs.note }}
input_verbose: ${{ inputs.verbose }}
8 changes: 3 additions & 5 deletions src/alert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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}" \
Expand Down
2 changes: 1 addition & 1 deletion src/payload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions test/test_helper/common.bash
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down

0 comments on commit 80bcbcf

Please sign in to comment.