generated from pmo-actions/healthchecks-ping
Initial commit
This commit is contained in:
29
README.md
Normal file
29
README.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Les pmo-actions
|
||||||
|
|
||||||
|
Les actions de la *petite maison orange* sont des actions réutilisables dans un environnement Gitea.
|
||||||
|
Elles sont avant tout faites pour me faciliter la vie dans la gestion de mon nuage personnel.
|
||||||
|
|
||||||
|
Pour les inclures utiliser la syntaxe:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
uses: https://gargoton.petite-maison-orange.fr/pmo-actions/ACTION@main
|
||||||
|
```
|
||||||
|
|
||||||
|
En remplaçant `ACTION` par l'action désirée.
|
||||||
|
|
||||||
|
## L'action `healthchecks-ping`
|
||||||
|
|
||||||
|
Elle a pour but d'envoyer un ping sur un serveur [`healthchecks.io`](https://healthchecks.io/). Elles acceptent
|
||||||
|
quatre valeurs en entrée, dont deux premières sont obligatoires.
|
||||||
|
|
||||||
|
- `server`: l'adresse du serveur inclue le protocole
|
||||||
|
par exemple: `https://monserveur.mondomaine.io`
|
||||||
|
- `uuid`: l'identifiant hexadecimal du service. l'*uuid* sera combiné avec
|
||||||
|
l'adresse du serveur pour construire l'URL à sonner:
|
||||||
|
`$serveur/ping/$uuid`
|
||||||
|
|
||||||
|
- `command`: cette valeur peut prendre 4 valeurs : `start`|`log`|`fail`|`stop`.
|
||||||
|
|
||||||
|
- `message`: Le message qui sera logguer lors du ping sur le serveur [`healthchecks.io`](https://healthchecks.io/).
|
||||||
|
|
||||||
|
|
||||||
90
action.yaml
Normal file
90
action.yaml
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
name: 'Ping a Healthchecks.io server'
|
||||||
|
description: 'Description de l action'
|
||||||
|
author: 'Eric Coissac'
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
check_server:
|
||||||
|
description: 'Address of the Healthchecks server'
|
||||||
|
required: true
|
||||||
|
check_uuid:
|
||||||
|
description: 'Deuxième paramètre'
|
||||||
|
required: true
|
||||||
|
check_command:
|
||||||
|
description: 'Command to sen to the server can be nothing, start, log or fail'
|
||||||
|
required: false
|
||||||
|
default: 'stop'
|
||||||
|
check_message:
|
||||||
|
description: 'Message to log with the ping'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
debug:
|
||||||
|
description: 'Run the action in debug mode'
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: 'composite'
|
||||||
|
steps:
|
||||||
|
- name: Set debug mode
|
||||||
|
if: ${{ inputs.debug == true }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
source "${{ github.action_path }}/bashlib.sh"
|
||||||
|
export DEBUG="ON"
|
||||||
|
echo "DEBUG=ON" >> $GITEA_ENV
|
||||||
|
debug Debug switch on
|
||||||
|
|
||||||
|
- name: Ping the server
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
source "${{ github.action_path }}/bashlib.sh"
|
||||||
|
|
||||||
|
check_command curl
|
||||||
|
|
||||||
|
SERVER="${{ inputs.check_server }}"
|
||||||
|
HEALTHPOINT="${{ inputs.check_server }}/ping/${{ inputs.check_uuid }}"
|
||||||
|
OPTIONS="-fsS -m 10 --retry 5"
|
||||||
|
MESSAGE="${{ inputs.check_message }}"
|
||||||
|
COMMAND="${{ inputs.check_command }}"
|
||||||
|
|
||||||
|
CURL_DATA=()
|
||||||
|
if [[ -n "$MESSAGE" ]]; then
|
||||||
|
CURL_DATA+=(--data-raw "$MESSAGE")
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$COMMAND" in
|
||||||
|
start|log|fail)
|
||||||
|
URL="${HEALTHPOINT}/$COMMAND"
|
||||||
|
;;
|
||||||
|
|
||||||
|
stop)
|
||||||
|
URL="${HEALTHPOINT}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
error Error "Invalid command: $COMMAND (must be start|log|fail|stop)"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
curl_cmd=(
|
||||||
|
curl
|
||||||
|
$OPTIONS
|
||||||
|
"${CURL_DATA[@]}"
|
||||||
|
"$URL"
|
||||||
|
)
|
||||||
|
|
||||||
|
debug "Run command" "${curl_cmd[*]}"
|
||||||
|
|
||||||
|
result=$("${curl_cmd[@]}") \
|
||||||
|
&& success "Success" "$COMMAND ping sent to ${SERVER}" \
|
||||||
|
|| error "Error" "$COMMAND ping to ${SERVER} failed ${result}"
|
||||||
|
|
||||||
|
if [[ "$COMMAND" == "fail" ]] ; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
65
bashlib.sh
Normal file
65
bashlib.sh
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
GREEN='\033[0;32m'
|
||||||
|
RED='\033[0;31m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
|
||||||
|
debug() {
|
||||||
|
if [[ -n "$DEBUG" ]]; then
|
||||||
|
local prompt="$1"
|
||||||
|
shift
|
||||||
|
local message="$*"
|
||||||
|
|
||||||
|
if [[ -n "$message" ]] ; then
|
||||||
|
message=": $message"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "🐛 \033[0;36m[DEBUG] ${prompt}\033[0m${message}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
local prompt="$1"
|
||||||
|
shift
|
||||||
|
local message="$*"
|
||||||
|
|
||||||
|
if [[ -n "$message" ]] ; then
|
||||||
|
message=": $message"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${RED}❌ ${prompt}:${NC}${message}"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
step() {
|
||||||
|
local prompt="$1"
|
||||||
|
shift
|
||||||
|
local message="$*"
|
||||||
|
|
||||||
|
if [[ -n "$message" ]] ; then
|
||||||
|
message=": $message"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${YELLOW}🔄 ${prompt}${NC}${message}"
|
||||||
|
}
|
||||||
|
|
||||||
|
success() {
|
||||||
|
local prompt="$1"
|
||||||
|
shift
|
||||||
|
local message="$*"
|
||||||
|
|
||||||
|
if [[ -n "$message" ]] ; then
|
||||||
|
message=": $message"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}✅ ${prompt}${NC}${message}"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_command() {
|
||||||
|
local command="$1"
|
||||||
|
|
||||||
|
if [[ -z $(which ${command}) ]] ; then
|
||||||
|
error "Missing command" "${command}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user