build: update webfactory/ssh-agent version #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.12' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Set up Django environment | |
run: | | |
python manage.py migrate | |
- name: Run tests | |
run: | | |
python manage.py test | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.12' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Add SSH key | |
uses: webfactory/ssh-agent@v0.5.3 # Usando a versão mais recente estável conhecida | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Deploy to Server | |
env: | |
DEPLOY_SERVER: ${{ secrets.DEPLOY_SERVER }} | |
DEPLOY_USER: ${{ secrets.DEPLOY_USER }} | |
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }} | |
run: | | |
ssh $DEPLOY_USER@$DEPLOY_SERVER 'cd $DEPLOY_PATH && git pull && source env/bin/activate && pip install -r requirements.txt && python manage.py migrate && sudo systemctl restart gunicorn && sudo systemctl reload nginx' |