-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (60 loc) · 1.85 KB
/
ci-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: Django CI/CD Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
PYTHON_VERSION: '3.11.0'
RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }}
SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }}
jobs:
test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache Python packages
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install flake8 pytest pytest-django coverage
- name: Run Linting
run: |
flake8 . --count --max-line-length=120 --statistics
- name: Run Tests with Coverage
env:
DJANGO_SETTINGS_MODULE: app.settings
DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }}
run: |
coverage run -m pytest
coverage report
- name: Upload Coverage Reports
uses: codecov/codecov-action@v3
deploy:
needs: test
if: github.ref == 'refs/heads/main' || github.event_name == 'pull_request_target'
runs-on: ubuntu-22.04
steps:
- name: Deploy to Render
env:
RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }}
RENDER_DEPLOY_HOOK: ${{ secrets.RENDER_DEPLOY_HOOK }}
run: |
curl -X POST $RENDER_DEPLOY_HOOK \
-H "Authorization: Bearer $RENDER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"serviceId": "${{ secrets.RENDER_SERVICE_ID }}",
"clearCache": "true"
}'