init: notify-telegram composite action

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
RMSTechStudio 2026-04-29 15:39:10 +02:00
commit 082fa47815
2 changed files with 127 additions and 0 deletions

48
README.md Normal file
View file

@ -0,0 +1,48 @@
## forgejo-actions
Composite actions reused across all RMS Tech Studio repos.
### notify-telegram
Pings a Telegram chat about a workflow outcome. Skips silently if credentials are missing.
**Setup once (org-level)** — in Forgejo, go to your org → Settings → Actions → Secrets, add:
- `TELEGRAM_BOT_TOKEN`
- `TELEGRAM_CHAT_ID`
These propagate to all repos under the org.
**Usage in a workflow:**
```yaml
- name: Notify Telegram (success)
if: success()
uses: rmstechstudio/forgejo-actions/notify-telegram@main
with:
bot-token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
chat-id: ${{ secrets.TELEGRAM_CHAT_ID }}
status: success
title: "RMS Ecosystem deploy"
message: ${{ github.event.head_commit.message }}
- name: Notify Telegram (failure)
if: failure()
uses: rmstechstudio/forgejo-actions/notify-telegram@main
with:
bot-token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
chat-id: ${{ secrets.TELEGRAM_CHAT_ID }}
status: failure
title: "RMS Ecosystem deploy"
```
**Inputs:**
| Name | Required | Default | Description |
|------|----------|---------|-------------|
| `bot-token` | yes | — | Telegram bot token |
| `chat-id` | yes | — | Telegram chat id |
| `status` | yes | — | `success` or `failure` |
| `title` | yes | — | Short label, e.g. "RMS Ecosystem deploy" |
| `message` | no | `""` | Extra body (commit msg, error summary…) |
| `notify-on-success` | no | `true` | Set `false` for silent crons |

View file

@ -0,0 +1,79 @@
name: Notify Telegram
description: Send a Telegram message about a workflow's outcome. Skips silently if secrets are missing.
inputs:
bot-token:
description: Telegram bot token
required: true
chat-id:
description: Telegram chat id
required: true
status:
description: "Workflow status — 'success' or 'failure'"
required: true
title:
description: Short label for the workflow (e.g. "RMS Ecosystem deploy", "TastyTalks build")
required: true
message:
description: Optional extra body line (commit message, error summary, etc)
required: false
default: ""
notify-on-success:
description: "Set to 'false' to skip Telegram on success (useful for chatty crons)"
required: false
default: "true"
runs:
using: composite
steps:
- name: Send Telegram message
shell: bash
env:
BOT_TOKEN: ${{ inputs.bot-token }}
CHAT_ID: ${{ inputs.chat-id }}
STATUS: ${{ inputs.status }}
TITLE: ${{ inputs.title }}
BODY: ${{ inputs.message }}
NOTIFY_SUCCESS: ${{ inputs.notify-on-success }}
COMMIT_SHA: ${{ github.sha }}
REPO: ${{ github.repository }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
if [ -z "$BOT_TOKEN" ] || [ -z "$CHAT_ID" ]; then
echo "Telegram credentials missing, skipping."
exit 0
fi
if [ "$STATUS" = "success" ] && [ "$NOTIFY_SUCCESS" != "true" ]; then
echo "notify-on-success=false, skipping success ping."
exit 0
fi
if [ "$STATUS" = "success" ]; then
icon="OK"
else
icon="FAIL"
fi
short_sha="${COMMIT_SHA:0:7}"
msg="[${icon}] ${TITLE}
Repo: ${REPO}@${short_sha}"
if [ -n "$BODY" ]; then
msg="${msg}
${BODY}"
fi
if [ "$STATUS" != "success" ]; then
msg="${msg}
Logs: ${RUN_URL}"
fi
# Install curl if missing (alpine images often lack it)
if ! command -v curl >/dev/null 2>&1; then
if command -v apk >/dev/null 2>&1; then apk add --no-cache curl >/dev/null
elif command -v apt-get >/dev/null 2>&1; then apt-get update -qq && apt-get install -y -qq curl >/dev/null
fi
fi
curl -sS -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
-d chat_id="${CHAT_ID}" \
--data-urlencode text="${msg}" \
-d disable_web_page_preview=true > /dev/null