DispelEvilBot/.gitea/workflows/ci.yml

63 lines
2.0 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: CI
on:
# Только пуш в master (теги ничего не триггерят).
push:
branches: [master]
workflow_dispatch:
# Отменяем предыдущий незавершённый прогон при новом пуше.
concurrency:
group: ci
cancel-in-progress: true
env:
REGISTRY: git.mpakosrv.ru
IMAGE_NAME_BOT: mpakobecex/dispelevilbot-bot
IMAGE_NAME_ADMIN: mpakobecex/dispelevilbot-admin
jobs:
lint-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Установка зависимостей
run: pip install -r requirements-dev.txt
- name: Ruff
run: ruff check .
- name: Black
run: black --check .
- name: Pytest
run: pytest -q
build-push:
runs-on: ubuntu-latest
needs: lint-test
# Собираем и пушим образ. Автодеплой НЕ делаем — выкатка вручную (test -> prod).
steps:
- uses: actions/checkout@v4
- name: Логин в Gitea Registry
run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "$REGISTRY" -u "${{ secrets.REGISTRY_USER }}" --password-stdin
- name: Сборка и публикация образов
run: |
set -e
SHORT_SHA="$(echo "${GITHUB_SHA:-unknown}" | cut -c1-12)"
VERSION="$(sed -n 's/^__version__ = "\(.*\)"/\1/p' common/version.py)"
build_push() {
image="$1"
dockerfile="$2"
tags="$image:$SHORT_SHA $image:latest"
if [ -n "$VERSION" ]; then tags="$tags $image:$VERSION"; fi
args=""
for t in $tags; do args="$args -t $t"; done
docker build $args -f "$dockerfile" .
for t in $tags; do docker push "$t"; done
}
build_push "$REGISTRY/$IMAGE_NAME_BOT" Dockerfile
build_push "$REGISTRY/$IMAGE_NAME_ADMIN" admin/Dockerfile