36 lines
900 B
YAML
36 lines
900 B
YAML
name: Deploy Django
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ] # 触发分支
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install -r requirements.txt
|
|
|
|
- name: Run tests
|
|
run: python manage.py test
|
|
|
|
- name: Deploy to Server
|
|
uses: appleboy/ssh-action@v1
|
|
with:
|
|
host: ${{ secrets.SERVER_IP }}
|
|
username: ${{ secrets.SSH_USER }}
|
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
script: |
|
|
cd /var/www/your_project
|
|
git pull origin main
|
|
source venv/bin/activate
|
|
pip install -r requirements.txt
|
|
python manage.py migrate
|
|
python manage.py collectstatic --noinput
|
|
sudo systemctl restart gunicorn
|
|
sudo systemctl reload nginx |