Files
vasyanskandClaude Sonnet 5 273cd54415
Build / Tests (push) Successful in 13s
Build / Build image (push) Failing after 15s
Build / Notify on failure (push) Failing after 0s
feat: traefik-selectel-dns — A-записи Selectel по роутам Traefik + CI сборка образа
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-21 21:50:07 +07:00

119 lines
4.2 KiB
YAML

name: Build
on:
push:
branches: [main, master]
paths:
- "cmd/**"
- "internal/**"
- "go.mod"
- "go.sum"
- "Dockerfile"
- ".gitea/workflows/**"
workflow_dispatch:
env:
REGISTRY: git.realmanual.ru
# Образ называется как репозиторий: git.realmanual.ru/pub/traefik-selectel
IMAGE: git.realmanual.ru/${{ gitea.repository }}
# Секреты репозитория: TOKEN (write:package — сборка пушит образ),
# TELEGRAM_BOT_URI, TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID.
permissions:
contents: read
packages: write
jobs:
# Имя без дефиса намеренно: к результату job'а обращаются как
# needs.<имя>.result, а дефис в этом выражении разбирается как минус.
tests:
name: Tests
runs-on: ubuntu-22.04
container: catthehacker/ubuntu:act-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
# Кэш модулей выключен: в self-hosted раннерах сервис кэша actions
# обычно недоступен (getCacheEntry → ETIMEDOUT).
cache: false
- name: Run tests
run: go test ./... -count=1
- name: Vet
run: go vet ./...
# gofmt не падает сам по себе, поэтому проверяем список файлов.
- name: Check gofmt
run: |
unformatted="$(gofmt -l .)"
if [ -n "$unformatted" ]; then
echo "не отформатированы:"
echo "$unformatted"
exit 1
fi
build:
needs: tests
name: Build image
runs-on: ubuntu-22.04
container: catthehacker/ubuntu:act-latest
outputs:
tag: ${{ steps.meta.outputs.TAG }}
steps:
- uses: actions/checkout@v3
- name: Compute tag
id: meta
# Короткий SHA коммита: тег неизменяем, по нему видно, какой код
# работает на ВМ, и есть куда откатиться.
run: echo "TAG=$(echo "${{ github.sha }}" | cut -c1-8)" >> $GITHUB_OUTPUT
- name: Log in to registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
build-args: |
VERSION=${{ steps.meta.outputs.TAG }}
tags: |
${{ env.IMAGE }}:${{ steps.meta.outputs.TAG }}
${{ env.IMAGE }}:latest
- name: Notify Telegram
if: success()
run: |
curl -s -X POST "${{ secrets.TELEGRAM_BOT_URI }}/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
-d chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \
-d parse_mode="HTML" \
-d text="✅ <b>traefik-selectel</b> образ собран%0A%0AОбраз: <code>${{ env.IMAGE }}:${{ steps.meta.outputs.TAG }}</code>"
# Отдельным job: ловит падение любой из стадий.
# failure() сам по себе не годится: он истинен только когда упал прямой
# предок, поэтому результаты перечисляем явно.
notifyfailure:
name: Notify on failure
needs: [tests, build]
if: always() && (needs.tests.result == 'failure' || needs.build.result == 'failure')
runs-on: ubuntu-22.04
container: catthehacker/ubuntu:act-latest
steps:
- name: Notify Telegram
run: |
curl -s -X POST "${{ secrets.TELEGRAM_BOT_URI }}/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
-d chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \
-d parse_mode="HTML" \
-d text="❌ <b>traefik-selectel</b> — тесты или сборка упали%0A%0A<a href=\"${{ gitea.server_url }}/${{ gitea.repository }}/actions\">Логи</a>"