From 5fb998e7333770b7aeb5a89b98ddf103c97cb935 Mon Sep 17 00:00:00 2001 From: pmo-actions <> Date: Mon, 14 Apr 2025 13:02:19 +0200 Subject: [PATCH] Initial commit --- README.md | 66 ++++++++++++++++++++++++++++++++++++++ action.yaml | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 README.md create mode 100644 action.yaml diff --git a/README.md b/README.md new file mode 100644 index 0000000..cf4e541 --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ +# L'action `healthchecks-ping` + +Cette action permet d’envoyer un *ping* vers un serveur [Healthchecks.io](https://healthchecks.io) (ou un serveur compatible). +Elle est conçue pour être utilisée dans des workflows Gitea avec des runners auto-hébergés. + +--- + +## 🔧 Utilisation + +```yaml +- name: Notify healthchecks + uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main +``` + +--- + +## 📥 Paramètres + +| Nom | Obligatoire | Par défaut | Description | +|------------------|-------------|------------|-----------------------------------------------------------------------------| +| `check_server` | ✅ | – | Adresse du serveur Healthchecks, incluant `https://`. | +| `check_uuid` | ✅ | – | Identifiant UUID de la vérification. | +| `check_command` | ❌ | `stop` | Commande : `start`, `log`, `fail`, ou `stop`. | +| `check_message` | ❌ | `""` | Message transmis avec le ping (visible dans l’interface Healthchecks). | +| `debug` | ❌ | `false` | Affiche des messages de debug détaillés si activé. | + +--- + +## ▶️ Exemple de workflow + +```yaml +- name: Notify healthchecks (start) + uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main + with: + check_server: https://hc-ping.com + check_uuid: a1b2c3d4-1234-5678-9abc-def123456789 + check_command: start + +- name: Build my project + run: make build + +- name: Notify healthchecks (stop) + uses: https://gargoton.petite-maison-orange.fr/pmo-actions/healthchecks-ping@main + with: + check_server: https://hc-ping.com + check_uuid: a1b2c3d4-1234-5678-9abc-def123456789 + check_message: "Build terminé avec succès ✅" +``` + +--- + +## ⚙️ Comportement + +- Si `check_command: fail` est utilisé, **l’action échoue volontairement** (`exit 1`). +- Si `curl` échoue, l’action affiche l’erreur et échoue également. +- L’URL appelée par `curl` dépend de la commande : + - `https:///ping/` *(commande `stop` ou vide)* + - `https:///ping//` *(commande `start`, `log`, `fail`)* + +--- + +## 🧡 À propos + +Cette action fait partie des actions de la **Petite Maison Orange**. +Toutes les actions sont disponibles ici : +👉 [https://gargoton.petite-maison-orange.fr/pmo-actions/](https://gargoton.petite-maison-orange.fr/pmo-actions/) diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..8c71453 --- /dev/null +++ b/action.yaml @@ -0,0 +1,92 @@ +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: Load bash library + uses: https://gargoton.petite-maison-orange.fr/pmo-actions/bash-library@main + - 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 + + + +