-
Notifications
You must be signed in to change notification settings - Fork 4
279 lines (274 loc) · 8.54 KB
/
partaj-ci.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
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
name: Partaj CI
on:
push:
branches: [ main, production ]
pull_request:
branches: [ main ]
env:
DJANGO_CONFIGURATION: "Test"
DJANGO_PARTAJ_PRIMARY_LOCATION: "https://partaj"
DJANGO_SECRET_KEY: "TestSecretKey"
DJANGO_SETTINGS_MODULE: "partaj.settings"
DJANGO_SUPERUSER_USERNAME: "admin"
DJANGO_SUPERUSER_EMAIL: "admin@example.com"
DJANGO_SUPERUSER_PASSWORD: "admin"
jobs:
################
# BACKEND JOBS #
################
lint-back-black:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/backend
container: python:3.9.16
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install system dependencies
run: apt-get update && apt-get install -y gettext
- name: Install python dependencies
run: pip install .[dev]
- name: Run black in check mode
run: black --check partaj
lint-back-flake8:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/backend
container: python:3.9.16
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install system dependencies
run: apt-get update && apt-get install -y gettext
- name: Install python dependencies
run: pip install .[dev]
- name: Run flake8
run: flake8
lint-back-pylint:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/backend
container: python:3.9.16
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install system dependencies
run: apt-get update && apt-get install -y gettext
- name: Install python dependencies
run: pip install .[dev]
- name: Run pylint
run: pylint --rcfile=.pylintrc partaj
lint-back-isort:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/backend
container: python:3.9.16
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install system dependencies
run: apt-get update && apt-get install -y gettext
- name: Install python dependencies
run: pip install .[dev]
- name: Run isort in check mode
run: isort --check-only partaj
test-back:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/backend
container: python:3.9.16
services:
postgres:
image: postgres:12.1
env:
POSTGRES_DB: partaj
POSTGRES_PASSWORD: admin
POSTGRES_USER: admin
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.0
env:
discovery.type: single-node
options: >-
--health-cmd "curl http://localhost:9200/_cluster/health"
--health-interval 10s
--health-timeout 5s
--health-retries 10
ports:
# <port on host>:<port on container>
- 9200:9200
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install system dependencies
run: apt-get update && apt-get install -y gettext
- name: Install python dependencies
run: pip install .[dev]
- name: Get translations
run: python manage.py compilemessages
- name: Run our test suite
run: pytest
env:
POSTGRES_HOST: postgres
#################
# FRONTEND JOBS #
#################
build-front:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/frontend
container: node:22.4.0
steps:
- name: Checkout code
uses: actions/checkout@v2
### CACHE ###
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Restore yarn cache
uses: actions/cache@v1
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn
### END CACHE ###
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build with Typescript
run: yarn build
lint-front-prettier:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/frontend
container: node:22.4.0
steps:
- name: Checkout code
uses: actions/checkout@v2
### CACHE ###
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Restore yarn cache
uses: actions/cache@v1
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
### END CACHE ###
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run prettier as a linter
run: yarn prettier --list-different "js/**/*.+(ts|tsx|json|js|jsx)" "*.+(ts|tsx|json|js|jsx)"
test-front:
runs-on: ubuntu-latest
defaults:
run:
working-directory: src/frontend
container: node:22.4.0
steps:
- name: Checkout code
uses: actions/checkout@v2
### CACHE ###
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Restore yarn cache
uses: actions/cache@v1
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
### END CACHE ###
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run tests
run: yarn test
##############
# DEPLOYMENT #
##############
deploy:
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/production'
needs: [lint-back-black, lint-back-flake8, lint-back-pylint, lint-back-isort, test-back, build-front, lint-front-prettier, test-front]
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install system dependencies
run: sudo apt-get update && sudo apt-get install -y gettext
- name: Setup Node.js environment
uses: actions/setup-node@v1.4.4
with:
node-version: '14'
- uses: actions/setup-python@v2
with:
python-version: '3.9.16'
### CACHE ###
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Restore yarn cache
uses: actions/cache@v1
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
### END CACHE ###
- name: Install frontend deps & run the build
run: |
cd src/frontend
yarn install --frozen-lockfile
yarn build
yarn build-css
- name: Generate binary localization files for backend strings
run: |
cd src/backend
pip install .[dev]
python manage.py compilemessages
- name: Create the deployment directory and copy the Partaj git repository there
run: |
mkdir ../deployment
cp -R .git ../deployment
- name: Checkout the deployment branch (before copying files to avoid conflicts)
run: |
cd ../deployment
git fetch
git checkout ${{ github.ref == 'refs/heads/production' && 'deployment-production' || 'deployment-staging' }}
- name: Copy the actual Partaj source files (and frontend build results) to the deployment directory
run: |
rm -rf ../deployment/*
cp -R src/backend/* ../deployment
cp docker/files/usr/local/etc/gunicorn/partaj.py ../deployment/partaj-gunicorn.py
- name: Generate a requirements.txt file from setup.cfg
run: python requirements.py
- name: Deploy the build artifact to Scalingo
run: |
cd ../deployment
git config user.email "contact.partaj@ecologie.gouv.fr"
git config user.name "Partaj Bot"
git add --all
git commit --allow-empty -m "Deploy to ${{ github.ref == 'refs/heads/production' && 'production' || 'staging' }}"
git push origin ${{ github.ref == 'refs/heads/production' && 'deployment-production' || 'deployment-staging' }}