Files
healthchecks-ping/action.yaml

94 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:
server:
description: 'Address of the Healthchecks server'
required: true
uuid:
description: 'Deuxième paramètre'
required: true
command:
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-13 23:03:10 +02:00
message:
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 09:40:33 +02:00
- name: Set debug mode
if: ${{ inputs.debug == true }}
shell: bash
run: |
2025-04-14 09:44:14 +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 09:44:46 +02:00
source "${{ github.action_path }}/bashlib.sh"
2025-04-14 09:14:50 +02:00
if [[ -z $(which curl) ]] ; then
echo -e "${RED}❌ Error:${NC}: Cannot locate the curl command"
exit 1
fi
2025-04-13 23:55:27 +02:00
HEALTHPOINT="${{ inputs.server }}/ping/${{ inputs.uuid }}"
2025-04-13 23:03:10 +02:00
OPTIONS="-fsS -m 10 --retry 5"
MESSAGE="${{ inputs.message }}"
2025-04-13 23:55:27 +02:00
COMMAND="${{ inputs.command }}"
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:14:50 +02:00
echo "${RED}❌ Error:${NC}: Commande invalide: $COMMAND"
2025-04-13 23:57:06 +02:00
exit 1
;;
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 09:23:57 +02:00
echo -e "${YELLOW}🔄 Commande exécutée:${NC} ${curl_cmd[*]}"
2025-04-13 23:55:27 +02:00
2025-04-14 09:14:50 +02:00
"${curl_cmd[@]}" \
2025-04-14 09:15:33 +02:00
&& echo -e "${GREEN}✅ Success:${NC} $COMMAND ping sent to ${HEALTHPOINT}" \
|| echo -e "${RED}❌ Error: ${NC} $COMMAND ping to ${HEALTHPOINT} failed"
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