9 Commits

Author SHA1 Message Date
59fd789a91 Merge pull request 'fix deploy #4' (#20) from dev-15 into master
All checks were successful
Deploy to Production / Deploy to Production (push) Successful in 41s
Deploy to Production / Rollback to Previous Version (push) Has been skipped
Reviewed-on: #20
2026-02-28 21:40:26 +00:00
cab85ecbf5 fix deploy #4
Some checks failed
CI pipeline / Test & Code Quality (push) Has been cancelled
CI pipeline / Test & Code Quality (pull_request) Has been cancelled
2026-03-01 00:40:05 +03:00
f398274655 Merge pull request 'dev-15' (#19) from dev-15 into master
Some checks failed
Deploy to Production / Deploy to Production (push) Failing after 19s
Deploy to Production / Rollback to Previous Version (push) Has been skipped
Reviewed-on: #19
2026-02-28 21:38:54 +00:00
a5d221ecad fix deploy #3
Some checks failed
CI pipeline / Test & Code Quality (pull_request) Has been cancelled
CI pipeline / Test & Code Quality (push) Successful in 35s
2026-03-01 00:34:44 +03:00
2ee6ea2b38 fix ci & deploy
Some checks failed
CI pipeline / Test & Code Quality (pull_request) Has been cancelled
CI pipeline / Test & Code Quality (push) Successful in 34s
2026-03-01 00:20:36 +03:00
118189da82 Merge branch 'dev-15' of ssh://192.168.1.103:2222/kerrad/telegram-helper-bot into dev-15
All checks were successful
CI pipeline / Test & Code Quality (push) Successful in 35s
2026-03-01 00:15:33 +03:00
d963ea83ad fix deploy 2026-03-01 00:14:40 +03:00
937c54ecfb Merge pull request 'Merge pull request 'Pull Request: dev-15' (#17) from dev-15 into master' (#18) from master into dev-15
All checks were successful
CI pipeline / Test & Code Quality (push) Successful in 34s
Reviewed-on: #18
2026-02-28 21:13:26 +00:00
b8428a5bac Merge pull request 'Pull Request: dev-15' (#17) from dev-15 into master
All checks were successful
CI pipeline / Test & Code Quality (pull_request) Successful in 34s
Reviewed-on: #17
2026-02-28 21:02:00 +00:00
2 changed files with 54 additions and 32 deletions

View File

@@ -4,7 +4,7 @@ on:
push:
branches: [ 'dev-*', 'feature-*', 'fix-*' ]
pull_request:
branches: [ 'dev-*', 'feature-*', 'fix-*', 'main' ]
branches: [ 'dev-*', 'feature-*', 'fix-*', 'master' ]
workflow_dispatch:
jobs:
@@ -72,7 +72,7 @@ jobs:
✅ All tests passed! Code quality checks completed successfully.
🔗 View details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
🔗 View details: ${{ vars.GITEA_PUBLIC_URL || github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
continue-on-error: true
- name: Send test failure notification
@@ -91,5 +91,5 @@ jobs:
❌ Tests failed! Deployment blocked. Please fix the issues and try again.
🔗 View details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
🔗 View details: ${{ vars.GITEA_PUBLIC_URL || github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
continue-on-error: true

View File

@@ -2,7 +2,7 @@ name: Deploy to Production
on:
push:
branches: [ main ]
branches: [ master ]
workflow_dispatch:
inputs:
action:
@@ -17,10 +17,13 @@ on:
required: false
type: string
dry_run:
description: 'Dry run (deploy only — no SSH, just show what would run)'
required: false
type: boolean
default: false
description: 'Dry run (only for deploy — no SSH, only show planned steps)'
required: true
type: choice
default: no
options:
- no
- yes
jobs:
deploy:
@@ -30,7 +33,7 @@ jobs:
github.event_name == 'push' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.action == 'deploy')
env:
DRY_RUN: ${{ github.event.inputs.dry_run == 'true' }}
DRY_RUN: ${{ github.event.inputs.dry_run == 'yes' }}
concurrency:
group: production-deploy-telegram-helper-bot
cancel-in-progress: false
@@ -41,17 +44,17 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main
ref: master
- name: Dry run (simulate deploy steps)
if: github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true'
if: github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'yes'
run: |
echo "🔍 DRY RUN — no SSH, no changes on server"
echo "Would run on server:"
echo " 1. cd /home/prod/bots/telegram-helper-bot"
echo " 2. CURRENT_COMMIT=\$(git rev-parse HEAD); write to .deploy_history_telegram_helper_bot.txt"
echo " 3. git fetch origin main && git reset --hard origin/main"
echo " 4. python3 scripts/apply_migrations.py --db ... (if DB exists)"
echo " 2. Backup DB → database/tg-bot-database_YYYYMMDD-HHMMSS.db (удаляется при успехе)"
echo " 3. CURRENT_COMMIT + history; git fetch origin master && git reset --hard origin/master"
echo " 4. apply_migrations.py (бэкап БД делается в шаге 1, при успехе удаляется в конце)"
echo " 5. docker-compose -f /home/prod/docker-compose.yml config (validate)"
echo " 6. docker-compose stop telegram-bot; build --pull telegram-bot; up -d telegram-bot"
echo " 7. sleep 10; check container bots_telegram_bot"
@@ -62,7 +65,7 @@ jobs:
fi
- name: Deploy to server
if: github.event_name != 'workflow_dispatch' || github.event.inputs.dry_run != 'true'
if: github.event_name != 'workflow_dispatch' || github.event.inputs.dry_run != 'yes'
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ vars.SERVER_HOST || secrets.SERVER_HOST }}
@@ -76,9 +79,21 @@ jobs:
echo "🚀 Starting deployment to production..."
DB_PATH="/home/prod/bots/telegram-helper-bot/database/tg-bot-database.db"
DB_DIR="/home/prod/bots/telegram-helper-bot/database"
BACKUP_FILE=""
sudo chown -R deploy:deploy /home/prod/bots/telegram-helper-bot || true
cd /home/prod/bots/telegram-helper-bot
# Бэкап БД в самом начале; при успешном деплое удалим в конце
if [ -f "$DB_PATH" ]; then
echo "💾 Creating database backup (before any changes)..."
BACKUP_NAME="tg-bot-database_$(date +%Y%m%d-%H%M%S).db"
BACKUP_FILE="${DB_DIR}/${BACKUP_NAME}"
cp "$DB_PATH" "$BACKUP_FILE" && echo "✅ Backup: $BACKUP_FILE" || { echo "❌ Backup failed!"; exit 1; }
fi
# Сохраняем информацию о коммите (до pull) — из репо telegram-helper-bot
CURRENT_COMMIT=$(git rev-parse HEAD)
COMMIT_MESSAGE=$(git log -1 --pretty=format:"%s" || echo "Unknown")
@@ -96,21 +111,24 @@ jobs:
tail -n "$HISTORY_SIZE" "$HISTORY_FILE" > "${HISTORY_FILE}.tmp" && mv "${HISTORY_FILE}.tmp" "$HISTORY_FILE"
# Обновляем код
echo "📥 Pulling latest changes from main..."
git fetch origin main
git reset --hard origin/main
echo "📥 Pulling latest changes from master..."
git fetch origin master
git reset --hard origin/master
sudo chown -R deploy:deploy /home/prod/bots/telegram-helper-bot || true
NEW_COMMIT=$(git rev-parse HEAD)
echo "✅ Code updated: $CURRENT_COMMIT → $NEW_COMMIT"
# Применяем миграции БД перед перезапуском контейнера
# Применяем миграции БД (нужен venv с зависимостями: aiosqlite и др.)
echo "🔄 Applying database migrations..."
DB_PATH="/home/prod/bots/telegram-helper-bot/database/tg-bot-database.db"
if [ -f "$DB_PATH" ]; then
cd /home/prod/bots/telegram-helper-bot
python3 scripts/apply_migrations.py --db "$DB_PATH" || {
if [ ! -d .venv ]; then
echo "📦 Creating .venv for migrations..."
python3 -m venv .venv
fi
.venv/bin/pip install -q -r requirements.txt
.venv/bin/python scripts/apply_migrations.py --db "$DB_PATH" || {
echo "❌ Ошибка при применении миграций!"
exit 1
}
@@ -152,6 +170,10 @@ jobs:
if docker ps | grep -q bots_telegram_bot; then
echo "✅ Container is running"
# Успешный деплой — удаляем бэкап (при ошибке на любом шаге бэкап остаётся для rollback)
if [ -n "${BACKUP_FILE:-}" ] && [ -f "$BACKUP_FILE" ]; then
rm -f "$BACKUP_FILE" && echo "✅ Backup removed (deploy success)"
fi
else
echo "❌ Container failed to start!"
docker logs bots_telegram_bot --tail 50 || true
@@ -189,13 +211,13 @@ jobs:
${{ job.status == 'success' && '✅' || '❌' }} Deployment: ${{ job.status }}
📦 Repository: telegram-helper-bot
🌿 Branch: main
🌿 Branch: master
📝 Commit: ${{ github.sha }}
👤 Author: ${{ github.actor }}
${{ job.status == 'success' && '✅ Deployment successful! Container restarted with migrations applied.' || '❌ Deployment failed! Check logs for details.' }}
🔗 View details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
🔗 View details: ${{ vars.GITEA_PUBLIC_URL || github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
continue-on-error: true
- name: Get PR body from merged PR
@@ -205,14 +227,14 @@ jobs:
run: |
echo "🔍 Searching for merged PR associated with commit ${{ github.sha }}..."
# Находим последний мерженный PR для main ветки по merge commit SHA
# Находим последний мерженный PR для master по merge commit SHA
COMMIT_SHA="${{ github.sha }}"
PR_NUMBER=$(gh pr list --state merged --base main --limit 10 --json number,mergeCommit --jq ".[] | select(.mergeCommit.oid == \"$COMMIT_SHA\") | .number" | head -1)
PR_NUMBER=$(gh pr list --state merged --base master --limit 10 --json number,mergeCommit --jq ".[] | select(.mergeCommit.oid == \"$COMMIT_SHA\") | .number" | head -1)
# Если не нашли по merge commit, ищем последний мерженный PR
if [ -z "$PR_NUMBER" ]; then
echo "⚠️ PR not found by merge commit, trying to get latest merged PR..."
PR_NUMBER=$(gh pr list --state merged --base main --limit 1 --json number --jq '.[0].number')
PR_NUMBER=$(gh pr list --state merged --base master --limit 1 --json number --jq '.[0].number')
fi
if [ -n "$PR_NUMBER" ] && [ "$PR_NUMBER" != "null" ]; then
@@ -244,7 +266,7 @@ jobs:
${{ env.PR_BODY }}
🔗 PR: ${{ github.server_url }}/${{ github.repository }}/pull/${{ env.PR_NUMBER }}
🔗 PR: ${{ vars.GITEA_PUBLIC_URL || github.server_url }}/${{ github.repository }}/pull/${{ env.PR_NUMBER }}
📝 Commit: ${{ github.sha }}
continue-on-error: true
@@ -261,7 +283,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main
ref: master
- name: Rollback on server
uses: appleboy/ssh-action@v1.0.0
@@ -319,7 +341,7 @@ jobs:
# Откатываем код
echo "🔄 Rolling back code..."
git fetch origin main
git fetch origin master
git reset --hard "$ROLLBACK_COMMIT"
# Исправляем права после отката
@@ -371,12 +393,12 @@ jobs:
${{ job.status == 'success' && '🔄' || '❌' }} Rollback: ${{ job.status }}
📦 Repository: telegram-helper-bot
🌿 Branch: main
🌿 Branch: master
📝 Rolled back to: ${{ github.event.inputs.rollback_commit || 'Last successful commit' }}
👤 Triggered by: ${{ github.actor }}
${{ job.status == 'success' && '✅ Rollback completed successfully! Services restored to previous version.' || '❌ Rollback failed! Check logs for details.' }}
🔗 View details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
🔗 View details: ${{ vars.GITEA_PUBLIC_URL || github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
continue-on-error: true