-
Notifications
You must be signed in to change notification settings - Fork 1
232 lines (196 loc) · 6.47 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# yamllint disable rule:line-length rule:truthy
---
name: CI/CD
on:
pull_request:
branches:
- main
- master
push:
branches:
- main
- master
env:
IMAGE_REPOSITORY: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
DATABASE_URL: psql://postgres:postgres@localhost:5432/django_wtf
DJANGO_SETTINGS_MODULE: config.settings.test
REDIS_URL: redis://localhost:6379/
CELERY_BROKER_URL: redis://localhost:6379/
# Common Django Env
DJANGO_ADMIN_URL: ""
DJANGO_SECRET_KEY: placeholder-g7cLmscguS3fnxCPK2j12lc73j0vDAuUciazNxbl09AVj4dTtY
DJANGO_HASHID_FIELD_SALT: salty
DJANGO_AWS_ACCESS_KEY_ID: ""
DJANGO_AWS_SECRET_ACCESS_KEY: ""
DJANGO_AWS_STORAGE_BUCKET_NAME: ""
PROMETHEUS_EXPORT_MIGRATIONS: "false"
MAILGUN_API_KEY: ""
MAILGUN_DOMAIN: ""
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Image Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Inject slug/short variables
uses: rlespinasse/[email protected]
- name: Build and push Default
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
${{ env.IMAGE_REPOSITORY }}:${{ github.event.pull_request.head.sha }}
${{ env.IMAGE_REPOSITORY }}:${{ env.GITHUB_REF_NAME_SLUG }}-latest
cache-from: type=gha
cache-to: type=gha,mode=min
- name: Build and push Production
if: github.event_name == 'push'
uses: docker/build-push-action@v4
with:
context: .
push: true
# Push latest image
tags: |
${{ env.IMAGE_REPOSITORY }}:${{ github.sha }}
${{ env.IMAGE_REPOSITORY }}:latest
cache-from: type=gha
cache-to: type=gha,mode=min
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-python@v4
id: setup-python
with:
python-version: 3.11
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.3
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
poetry install --no-interaction --no-root
- name: Format (black)
run: |
source .venv/bin/activate
black --check $(git ls-files -- '*.py' ':!:**/migrations/*.py')
- name: Sort imports (isort)
run: |
source .venv/bin/activate
isort --check-only $(git ls-files -- '*.py' ':!:**/migrations/*.py')
- name: Type Check (mypy)
run: |
source .venv/bin/activate
mypy .
- name: Lint (pylint)
run: |
source .venv/bin/activate
pylint $(git ls-files -- '*.py' ':!:**/migrations/*.py')
- name: Validate templates
run: |
source .venv/bin/activate
./manage.py validate_templates --ignore-app jazzmin
- name: Python Upgrade (pyupgrade)
run: |
source .venv/bin/activate
pyupgrade $(git ls-files -- '*.py' ':!:**/migrations/*.py') --py311-plus
- name: Django Upgrade (django-upgrade)
run: |
source .venv/bin/activate
django-upgrade $(git ls-files -- '*.py' ':!:**/migrations/*.py') --target=4.2
- name: Django Template/Html Lint (djlint)
run: |
source .venv/bin/activate
djlint . --check
test:
name: Test
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
ports: ["5432:5432"]
env:
POSTGRES_DB: django_wtf
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
redis:
image: redis:6
ports: ["6379:6379"]
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-python@v4
id: setup-python
with:
python-version: 3.11
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.3
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
poetry install --no-interaction --no-root
source .venv/bin/activate
- name: Run Migrations
run: |
source .venv/bin/activate
./manage.py migrate
# Some Django checks require migrations to run for full functionality
# Therefore run migrations first before checking for missing migrations
- name: Check for Missing Migrations
if: github.event == 'dont-run'
run: |
source .venv/bin/activate
DJANGO_SETTINGS_MODULE=config.settings.production \
./manage.py makemigrations --check --dry-run
- name: Django Check
run: |
source .venv/bin/activate
DJANGO_SETTINGS_MODULE=config.settings.production \
./manage.py check --deploy --fail-level=WARNING
- name: Test Loading Fixtures
if: github.event == 'dont-run'
run: |
source .venv/bin/activate
./manage.py load_fixtures
- name: Run Pytest
run: |
source .venv/bin/activate
pytest django_wtf --cov django_wtf # --run-concurrent