Перейти к содержимому

Уведомления из CI/CD

CI присылает почту, в которую никто не смотрит, или пишет в Slack/Telegram, где тонет среди мемов. Notifly даёт изолированный канал «только инфраструктура» — сообщения видны сразу, не теряются и не отвлекают коллег.

Везде ниже использую два секрета:

  • NOTIFLY_URL — полный URL вашего сервера, например https://notifly.example.com
  • NOTIFLY_TOKEN — app-токен (префикс A)

В GitHub: Settings → Secrets and variables → Actions → New repository secret. В GitLab: Settings → CI/CD → Variables → Add variable (поставьте «Masked»).

.github/workflows/build.yml:

name: Build & Notify
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm test
- run: npm run build
notify:
needs: build
if: always()
runs-on: ubuntu-latest
steps:
- name: Notifly
env:
NOTIFLY_URL: ${{ secrets.NOTIFLY_URL }}
NOTIFLY_TOKEN: ${{ secrets.NOTIFLY_TOKEN }}
STATUS: ${{ needs.build.result }}
run: |
if [ "$STATUS" = "success" ]; then
TITLE="✅ ${{ github.repository }} build OK"
PRIO=4
else
TITLE="❌ ${{ github.repository }} build FAILED"
PRIO=9
fi
MSG="Branch: ${{ github.ref_name }}
Commit: ${{ github.sha }}
By: ${{ github.actor }}
Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
curl -s --max-time 10 \
"$NOTIFLY_URL/message?token=$NOTIFLY_TOKEN" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg t "$TITLE" --arg m "$MSG" --argjson p "$PRIO" \
'{title:$t, message:$m, priority:$p}')"

Положите в .github/actions/notifly/action.yml:

name: 'Notifly send'
inputs:
title: {required: true}
message: {required: true}
priority: {default: '5'}
runs:
using: composite
steps:
- shell: bash
env:
NOTIFLY_URL: ${{ env.NOTIFLY_URL }}
NOTIFLY_TOKEN: ${{ env.NOTIFLY_TOKEN }}
run: |
curl -s --max-time 10 \
"$NOTIFLY_URL/message?token=$NOTIFLY_TOKEN" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg t '${{ inputs.title }}' \
--arg m '${{ inputs.message }}' \
--argjson p ${{ inputs.priority }} \
'{title:$t, message:$m, priority:$p}')"

Используем:

- uses: ./.github/actions/notifly
with:
title: '🚀 deploy started'
message: 'release ${{ github.ref_name }}'
priority: 5

.gitlab-ci.yml:

stages: [build, notify]
build:
stage: build
script:
- npm ci && npm test && npm run build
notify:success:
stage: notify
when: on_success
script:
- |
curl -s --max-time 10 \
"$NOTIFLY_URL/message?token=$NOTIFLY_TOKEN" \
-H "Content-Type: application/json" \
-d "$(jq -n \
--arg t '✅ '"$CI_PROJECT_PATH"' build OK' \
--arg m 'Branch: '"$CI_COMMIT_REF_NAME"$'\nCommit: '"$CI_COMMIT_SHORT_SHA"$'\nURL: '"$CI_PIPELINE_URL" \
'{title:$t, message:$m, priority:4}')"
notify:failure:
stage: notify
when: on_failure
script:
- |
curl -s --max-time 10 \
"$NOTIFLY_URL/message?token=$NOTIFLY_TOKEN" \
-H "Content-Type: application/json" \
-d "$(jq -n \
--arg t '❌ '"$CI_PROJECT_PATH"' build FAILED' \
--arg m 'Branch: '"$CI_COMMIT_REF_NAME"$'\nCommit: '"$CI_COMMIT_SHORT_SHA"$'\nURL: '"$CI_PIPELINE_URL" \
'{title:$t, message:$m, priority:9}')"
  • Долгий билд (> 10 мин) — алерт «что-то идёт не так».
  • Новый релиз — отдельное событие с changelog.
  • Регрессия покрытия ниже порога — приоритет 5, чтобы не пропустить.
  • Найдены security-issues в npm audit / pip-audit — приоритет 8.
  • Один канал на всю инфру. Запушил → пуш → собрал → пуш → деплой → пуш.
  • Никаких писем «build #12345 failed» в почту, где они тонут.
  • На телефоне видно прогресс. Особенно удобно для выкаток ночью или в дороге.