ci: CI на тегах v*, проверка DEPLOY_*, документация деплоя и тегов
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
Made-with: Cursor
This commit is contained in:
@ -1,14 +1,22 @@
|
||||
# Forgejo / Gitea Actions — проверка перед деплоем
|
||||
# Forgejo / Gitea Actions — проверка перед деплоем (совместимо с синтаксисом GitHub Actions).
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags:
|
||||
- "v*"
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
concurrency:
|
||||
group: ci-${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
@ -17,8 +25,12 @@ jobs:
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
cache: pip
|
||||
cache-dependency-path: pyproject.toml
|
||||
|
||||
- name: Pytest
|
||||
run: |
|
||||
pip install -e ".[dev]"
|
||||
pytest -q
|
||||
set -euo pipefail
|
||||
python -m pip install -U pip
|
||||
python -m pip install -e ".[dev]"
|
||||
python -m pytest tests/ -q --tb=short
|
||||
|
||||
@ -25,10 +25,26 @@ jobs:
|
||||
echo "ref=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
# Без секретов appleboy/ssh-action падает с «missing server host» — даём явную подсказку.
|
||||
- name: Проверить секреты деплоя
|
||||
env:
|
||||
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
||||
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
||||
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
|
||||
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
run: |
|
||||
ok=0
|
||||
[ -n "$DEPLOY_HOST" ] || { echo "::error::Секрет DEPLOY_HOST пустой. Forgejo → репозиторий → Настройки → Actions → Secrets."; ok=1; }
|
||||
[ -n "$DEPLOY_USER" ] || { echo "::error::Секрет DEPLOY_USER пустой."; ok=1; }
|
||||
[ -n "$DEPLOY_PATH" ] || { echo "::error::Секрет DEPLOY_PATH пустой (каталог клона на сервере, напр. /opt/onGuard24)."; ok=1; }
|
||||
[ -n "$DEPLOY_SSH_KEY" ] || { echo "::error::Секрет DEPLOY_SSH_KEY пустой (приватный SSH-ключ целиком, PEM)."; ok=1; }
|
||||
exit "$ok"
|
||||
|
||||
- name: SSH — fetch, checkout, docker compose
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.DEPLOY_HOST }}
|
||||
port: "22"
|
||||
username: ${{ secrets.DEPLOY_USER }}
|
||||
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
script_stop: true
|
||||
@ -38,6 +54,7 @@ jobs:
|
||||
cd "${{ secrets.DEPLOY_PATH }}"
|
||||
git fetch origin --tags --prune
|
||||
git checkout "${{ steps.pick.outputs.ref }}"
|
||||
# Теги не дают refs/remotes/origin/<тег> — только ветки; для v* срабатывает else.
|
||||
if git show-ref --verify --quiet "refs/remotes/origin/${{ steps.pick.outputs.ref }}"; then
|
||||
git reset --hard "origin/${{ steps.pick.outputs.ref }}"
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user