Files
healthchecks-ping/action.yaml

93 lines
2.3 KiB
YAML
Raw Normal View History

2025-04-13 23:03:10 +02:00
name: 'Ping a Healthchecks.io server'
description: 'Description de l action'
author: 'Eric Coissac'
inputs:
2025-04-14 10:15:51 +02:00
check_server:
2025-04-13 23:03:10 +02:00
description: 'Address of the Healthchecks server'
required: true
2025-04-14 10:15:51 +02:00
check_uuid:
2025-04-13 23:03:10 +02:00
description: 'Deuxième paramètre'
required: true
2025-04-14 10:15:51 +02:00
check_command:
2025-04-13 23:03:10 +02:00
description: 'Command to sen to the server can be nothing, start, log or fail'
required: false
2025-04-13 23:44:53 +02:00
default: 'stop'
2025-04-14 10:15:51 +02:00
check_message:
2025-04-13 23:03:10 +02:00
description: 'Message to log with the ping'
required: false
default: ''
2025-04-14 09:23:57 +02:00
debug:
2025-04-14 09:40:33 +02:00
description: 'Run the action in debug mode'
required: false
default: false
type: boolean
2025-04-13 23:03:10 +02:00
runs:
using: 'composite'
steps:
2025-04-14 12:03:26 +02:00
- name: Load bash library
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/bash-library@main
2025-04-14 09:40:33 +02:00
- name: Set debug mode
2025-04-14 14:08:28 +02:00
if: ${{ inputs.debug == 'true' }}
2025-04-14 09:40:33 +02:00
shell: bash
run: |
2025-04-14 12:03:26 +02:00
source "${{ github.action_path }}/../bashlib.sh"
2025-04-14 09:40:33 +02:00
export DEBUG="ON"
echo "DEBUG=ON" >> $GITEA_ENV
debug Debug switch on
2025-04-13 23:03:10 +02:00
- name: Ping the server
shell: bash
run: |
2025-04-14 12:03:26 +02:00
source "${{ github.action_path }}/../bashlib.sh"
2025-04-14 09:14:50 +02:00
2025-04-14 09:56:38 +02:00
check_command curl
2025-04-14 10:15:51 +02:00
SERVER="${{ inputs.check_server }}"
HEALTHPOINT="${{ inputs.check_server }}/ping/${{ inputs.check_uuid }}"
2025-04-13 23:03:10 +02:00
OPTIONS="-fsS -m 10 --retry 5"
2025-04-14 10:15:51 +02:00
MESSAGE="${{ inputs.check_message }}"
COMMAND="${{ inputs.check_command }}"
2025-04-13 23:55:27 +02:00
CURL_DATA=()
if [[ -n "$MESSAGE" ]]; then
CURL_DATA+=(--data-raw "$MESSAGE")
fi
2025-04-13 23:03:10 +02:00
case "$COMMAND" in
2025-04-13 23:57:06 +02:00
start|log|fail)
2025-04-13 23:03:10 +02:00
URL="${HEALTHPOINT}/$COMMAND"
;;
stop)
URL="${HEALTHPOINT}"
;;
2025-04-13 23:57:06 +02:00
*)
2025-04-14 09:56:38 +02:00
error Error "Invalid command: $COMMAND (must be start|log|fail|stop)"
2025-04-13 23:57:06 +02:00
;;
2025-04-14 00:00:42 +02:00
esac
2025-04-13 23:55:27 +02:00
curl_cmd=(
curl
$OPTIONS
"${CURL_DATA[@]}"
"$URL"
)
2025-04-14 10:22:00 +02:00
debug "Run command" "${curl_cmd[*]}"
2025-04-13 23:55:27 +02:00
2025-04-14 10:02:30 +02:00
result=$("${curl_cmd[@]}") \
2025-04-14 09:56:38 +02:00
&& success "Success" "$COMMAND ping sent to ${SERVER}" \
2025-04-14 10:02:30 +02:00
|| error "Error" "$COMMAND ping to ${SERVER} failed ${result}"
2025-04-13 23:55:27 +02:00
if [[ "$COMMAND" == "fail" ]] ; then
2025-04-13 23:27:55 +02:00
exit 1
fi
exit 0
2025-04-13 23:03:10 +02:00