-
Notifications
You must be signed in to change notification settings - Fork 20
299 lines (292 loc) · 11.5 KB
/
Copy pathci.yml
File metadata and controls
299 lines (292 loc) · 11.5 KB
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
---
name: CI Build
on:
push:
branches: ['master', 'prod']
pull_request:
branches: ['master']
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_ORGANIZATION: ${{ github.repository_owner }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
django-tests:
name: "Django tests"
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
include:
# Blocking: current production stack (.python-version + constraints-production.txt)
- python_version: current
django_version: current
experimental: false
# Non-blocking: track upcoming Python/Django compatibility
- python_version: "3.14"
django_version: "6"
experimental: true
env:
PYTHON_VERSION: ${{ matrix.python_version }}
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v7
with:
fetch-depth: 2
- name: "Login to Githhub Container Registry"
run: ./scripts/docker_login_github.py
- if: matrix.django_version != 'latest' && matrix.django_version != 'current' && matrix.django_version != '6'
run: |
echo "DJANGO_VERSION=${DJANGO_VERSION}" | tee "${GITHUB_ENV}";
env:
DJANGO_VERSION: ${{ matrix.django_version }}
- if: matrix.django_version == 'latest'
run: |
latest_version=$(curl 'https://pypi.org/pypi/django/json' | jq .info.version -r)
echo "DJANGO_VERSION=${latest_version}" | tee "${GITHUB_ENV}";
- if: matrix.django_version == '6'
run: |
latest_version=$(
curl -s 'https://pypi.org/pypi/django/json' | jq -r '
[.releases | keys[] | select(test("^6\\.[0-9]+\\.[0-9]+$"))]
| sort_by(split(".") | map(tonumber)) | last
'
)
echo "DJANGO_VERSION=${latest_version}" | tee "${GITHUB_ENV}";
- name: "Log test matrix versions"
run: |
echo "Python: ${PYTHON_VERSION}"
echo "Django: ${DJANGO_VERSION:-current (from constraints)}"
echo "Experimental (non-blocking): ${{ matrix.experimental }}"
env:
DJANGO_VERSION: ${{ env.DJANGO_VERSION }}
- name: "Copy .env.example to .env"
run: cp .env.example .env
- name: "Build CI image"
run: ./scripts/manage_image.py build --image-type ci
- name: "Verify CI image"
run: ./scripts/manage_image.py verify --image-type ci
- name: Pull images
run: PYTHONUNBUFFERED=1 ./scripts/pull_images.py
- name: "Run tests"
run: ./run_test.sh
- name: "Check missing migrations"
run: docker compose run web makemigrations --check -v 3
- name: "Checks the entire Django project for potential problems"
run: docker compose run web check --fail-level DEBUG -v 3
- name: "Upload coverage"
if: ${{ !matrix.experimental }}
uses: codecov/codecov-action@v7.0.0
with:
files: coverage.xml
disable_search: true
fail_ci_if_error: false
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload test results to Codecov
if: ${{ !matrix.experimental && !cancelled() }}
uses: codecov/codecov-action@v7.0.0
with:
report_type: test_results
files: junit.xml
disable_search: true
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
- name: "Push CI image (push)"
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && !matrix.experimental
run: |
./scripts/manage_image.py push --image-type ci
# Push cache
./scripts/manage_image.py build --image-type ci --prepare-buildx-cache
- name: Show logs on fail
if: ${{ failure() }}
run: docker compose logs
static-checks:
name: "Static checks"
runs-on: ubuntu-latest
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v7
- name: "Setup Python"
uses: actions/setup-python@v7
with:
python-version-file: '.python-version'
- name: "Setup Python dependencies"
run: pip install -U pip wheel setuptools virtualenv pre-commit
- name: "Use pre-commit environment cache"
uses: actions/cache@v6
with:
path: ~/.cache/pre-commit
key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: "Run static checks"
run: pre-commit run --show-diff-on-failure --color=always --all-files
bi-validate:
name: "BI Validate"
runs-on: ubuntu-latest
needs: [django-tests, static-checks]
env:
COMPOSE_FILE: "docker-compose.yaml:docker-compose.dbt.yaml:docker-compose.dbt-local.yaml"
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v7
with:
fetch-depth: 2
- name: "Setup Python"
uses: actions/setup-python@v7
with:
python-version-file: '.python-version'
- name: "Login to Githhub Container Registry"
run: ./scripts/docker_login_github.py
- name: "Copy .env.example to .env"
run: cp .env.example .env
- name: "Build CI image"
run: ./scripts/manage_image.py build --image-type ci
- name: "Verify CI image"
run: ./scripts/manage_image.py verify --image-type ci
- name: "Build BI image"
run: ./scripts/manage_image.py build --image-type bi
- name: "Verify BI image"
run: ./scripts/manage_image.py verify --image-type bi
- name: Pull images
run: PYTHONUNBUFFERED=1 ./scripts/pull_images.py
- run: docker compose config
# We dont have a cache for self-management image and we dont need to need it, so we exclude it.
- run: docker compose config --services | grep -v self-management | xargs docker compose up -d
- run: ./run_manage.sh migrate
- run: ./run_manage.sh populate_db
- run: ./run_dbt.sh dbt deps
- run: ./run_dbt.sh dbt build
- name: "Push BI image (push)"
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: |
./scripts/manage_image.py push --image-type bi
# Push cache
./scripts/manage_image.py build --image-type bi --prepare-buildx-cache
prod-image:
name: "Build Prod Image"
runs-on: ubuntu-latest
needs: [django-tests, static-checks]
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v7
- name: "Login to GitHhub Container Registry"
run: ./scripts/docker_login_github.py
- name: "Set image tag"
if: github.event_name == 'push'
run: |
set -x;
APP_NAME="$(./scripts/detect_app_name.py)";
echo "APP_NAME=${APP_NAME}"
echo "IMAGE_TAG=${APP_NAME}" >> $GITHUB_ENV;
echo "HEROKU_APP=${APP_NAME}" >> $GITHUB_ENV;
- name: "Build PROD image"
run: ./scripts/manage_image.py build --image-type prod
- name: "Verify PROD image"
run: ./scripts/manage_image.py verify --image-type prod
- name: "Push PROD image (push)"
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: |
./scripts/manage_image.py push --image-type prod
# Push cache
./scripts/manage_image.py build --image-type prod --prepare-buildx-cache
deploy-app:
name: "Deploy app (push) - ${{ github.ref }}"
runs-on: ubuntu-latest
needs: [prod-image, bi-validate]
if: github.event_name == 'push'
permissions:
contents: read
deployments: write
packages: write
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v7
- name: "Login to Githhub Container Registry"
run: ./scripts/docker_login_github.py
- name: "Login to Heroku Docker Registry"
run: ./scripts/docker_login_heroku.py
- name: "Install Heroku CLI"
run: "curl https://cli-assets.heroku.com/install.sh | sh"
- name: "Set environment env variable"
run: |
APP_NAME="$(./scripts/detect_app_name.py)";
echo "APP_NAME=${APP_NAME}"
echo "HEROKU_APP=${APP_NAME}" >> $GITHUB_ENV;
echo "HEROKU_DOMAIN=$(./scripts/fetch_domain.py "${APP_NAME}")" >> $GITHUB_ENV;
- uses: chrnorm/deployment-action@v2
name: Create GitHub deployment
id: deployment
with:
token: "${{ github.token }}"
environment-url: "https://${{ env.HEROKU_DOMAIN }}"
initial-status: in_progress
environment: "${{ env.HEROKU_APP }}"
- name: "Build PROD image"
run: ./scripts/manage_image.py build --image-type prod
- name: "Deploy"
run: './scripts/deploy.sh "${HEROKU_APP}"'
- name: Update deployment status (success)
if: success()
uses: chrnorm/deployment-status@v2
with:
token: "${{ github.token }}"
state: "success"
environment-url: "https://${{ env.HEROKU_DOMAIN }}"
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
- name: Update deployment status (failure)
if: failure()
uses: chrnorm/deployment-status@v2
with:
token: "${{ github.token }}"
state: "failure"
environment-url: "https://${{ env.HEROKU_DOMAIN }}"
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
deploy-bi:
name: "Deploy BI (push) - ${{ github.ref }}"
runs-on: ubuntu-latest
needs: [prod-image, bi-validate]
if: github.event_name == 'push'
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
COMPOSE_FILE: "docker-compose.dbt.yaml"
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v7
with:
fetch-depth: 2
- name: "Setup Python"
uses: actions/setup-python@v7
with:
python-version-file: '.python-version'
- name: "Login to Githhub Container Registry"
run: ./scripts/docker_login_github.py
- name: "Build BI image"
run: ./scripts/manage_image.py build --image-type bi
- name: "Verify BI image"
run: ./scripts/manage_image.py verify --image-type bi
- run: pip install django-environ
- name: "Install Heroku CLI"
run: |
curl https://cli-assets.heroku.com/install-ubuntu.sh | sh
echo "export PATH=$PATH:/usr/local/bin" >> $HOME/.bashrc
source $HOME/.bashrc
heroku --version
- name: "Authenticate Heroku CLI"
run: |
echo "$HEROKU_API_KEY" | heroku auth:token
- name: "Set environment env variable"
if: github.ref == 'refs/heads/prod'
run: |
source <(python ./pola-bi/dev.py --environment prod)
printenv | grep POLA_APP | cut -d "=" -f 2- | xargs -n 1 -I {} echo "::add-mask::{}"
printenv | grep POLA_APP >> $GITHUB_ENV;
- name: "Set environment env variable"
if: github.ref == 'refs/heads/master'
run: |
source <(python ./pola-bi/dev.py --environment staging)
printenv | grep POLA_APP | cut -d "=" -f 2- | xargs -n 1 -I {} echo "::add-mask::{}"
printenv | grep POLA_APP >> $GITHUB_ENV;
- run: ./run_dbt.sh dbt deps
- run: ./run_dbt.sh dbt build