signal-bot/.github/workflows/deploy.yml
copilot-swe-agent[bot] 2130511f02 Address code review feedback and fix CodeQL security alert
Co-authored-by: kuhyx <147418882+kuhyx@users.noreply.github.com>
2025-12-01 15:22:48 +00:00

61 lines
1.7 KiB
YAML

name: Deploy to Server
on:
push:
branches: [ "main" ]
workflow_dispatch:
permissions:
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-asyncio
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- name: Run tests
run: |
pytest tests/ -v
- name: Deploy to server via SSH
if: success()
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
port: ${{ secrets.DEPLOY_PORT || 22 }}
script: |
cd ${{ secrets.DEPLOY_PATH || '~/signal-bot' }}
git pull origin main
source venv/bin/activate || python3 -m venv venv && source venv/bin/activate
pip install -r requirements.txt
# Restart the service (adjust based on your setup)
if [ -f "supervisorctl.conf" ]; then
supervisorctl restart signal-bot
elif systemctl is-active --quiet signal-bot; then
sudo systemctl restart signal-bot
else
# Kill existing process and restart
pkill -f "uvicorn main:app" || true
nohup ./run.sh > nohup.out 2>&1 &
fi