-
Notifications
You must be signed in to change notification settings - Fork 6
347 lines (327 loc) · 12.7 KB
/
python-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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
name: Python CI
# 1. Run linting and static code checks
# 2. Test python syncing script
# 3. Build and publish docker container
# 4. Test published docker container
on:
pull_request:
types: ['opened', 'reopened', 'synchronize']
workflow_dispatch:
inputs:
numChaos:
description: 'Number of items the chaos monkey should manipulate during test'
required: false
default: '4'
CREATE_REMINDERS:
description: Create reminders for birthdays and deceased days?
required: false
type: boolean
default: true
DELETE_ON_SYNC:
description: Delete Monica contact if the corresponding Google contact has been deleted?
required: false
type: boolean
default: true
STREET_REVERSAL:
description: Do a street reversal in address sync if the first character is a number?
required: false
type: boolean
default: false
FIELDS:
description: What fields should be synced? (both directions)
required: false
default: career,address,phone,email,labels,notes
GOOGLE_LABELS_INCLUDE:
description: Define Google contact labels/tags/groups you want to include in sync
required: false
default:
GOOGLE_LABELS_EXCLUDE:
description: Define Google contact labels/tags/groups you want to exclude from sync
required: false
default:
MONICA_LABELS_INCLUDE:
description: Define Monica contact labels/tags/groups you want to include in sync
required: false
default:
MONICA_LABELS_EXCLUDE:
description: Define Monica contact labels/tags/groups you want to exclude from sync
required: false
default:
# 1. Run linting and static code checks
jobs:
black_formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: psf/black@stable
with:
options: "-l 105 --check --diff"
src: "."
codespell_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: codespell-project/actions-codespell@master
with:
check_filenames: true
skip: .*,*.csv
bandit_security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: jpetrucciani/bandit-check@master
with:
path: '.'
bandit_flags: '--recursive --skip B403,B101,B301'
flake8_lint:
runs-on: ubuntu-latest
steps:
- name: Check out source repository
uses: actions/checkout@v4
- name: Setup Python environment
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: flake8 Lint
uses: py-actions/flake8@v2
with:
ignore: "E203,W503,E231,E402"
max-line-length: "105"
path: "."
args: '--count --show-source --statistics'
isort_check:
runs-on: ubuntu-latest
steps:
- name: Check out source repository
uses: actions/checkout@v4
- name: Setup Python environment
uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: isort/isort-action@master
with:
configuration: "--check-only --profile black"
mypy_typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: jpetrucciani/mypy-check@master
with:
path: '.'
mypy_flags: '--install-types --non-interactive'
# 2. Test python syncing script
python_test:
runs-on: ubuntu-latest
needs: [black_formatting, codespell_check, bandit_security, flake8_lint, isort_check, mypy_typecheck]
env:
TEST_RUNNER: python
steps:
# Setup environment
- name: Check out source repository
uses: actions/checkout@v4
- name: Setup python environment
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Setup testing environment
uses: ./.github/actions/setup-environment
with:
GOOGLE_TOKEN: ${{ secrets.GOOGLE_TOKEN }}
CREATE_REMINDERS: ${{ github.event.inputs.CREATE_REMINDERS }}
DELETE_ON_SYNC: ${{ github.event.inputs.DELETE_ON_SYNC }}
STREET_REVERSAL: ${{ github.event.inputs.STREET_REVERSAL }}
FIELDS: ${{ github.event.inputs.FIELDS }}
GOOGLE_LABELS_INCLUDE: ${{ github.event.inputs.GOOGLE_LABELS_INCLUDE }}
GOOGLE_LABELS_EXCLUDE: ${{ github.event.inputs.GOOGLE_LABELS_EXCLUDE }}
MONICA_LABELS_INCLUDE: ${{ github.event.inputs.MONICA_LABELS_INCLUDE }}
MONICA_LABELS_EXCLUDE: ${{ github.event.inputs.MONICA_LABELS_EXCLUDE }}
# Test initial sync
- name: Prepare initial sync
run: python test/ChaosMonkey.py --initial --num ${{ github.event.inputs.numChaos || 4 }}
- name: Run initial sync
run: python GMSync.py --initial
timeout-minutes: 5
- name: Check initial sync results
if: always()
run: |
mv logs/sync.log logs/${{ env.TEST_RUNNER }}_sync_initial.log && \
[[ -z "$(grep -e ERROR -e WARNING logs/${{ env.TEST_RUNNER }}_sync_initial.log)" ]]
# Test delta sync
- name: Prepare delta sync
run: python test/ChaosMonkey.py --delta --num ${{ github.event.inputs.numChaos || 4 }}
- name: Run delta sync
run: python GMSync.py --delta
timeout-minutes: 5
- name: Check delta sync results
if: always()
run: |
mv logs/sync.log logs/${{ env.TEST_RUNNER }}_sync_delta.log && \
[[ -z "$(grep -e ERROR -e WARNING logs/${{ env.TEST_RUNNER }}_sync_delta.log)" ]]
# Test full sync
- name: Prepare full sync
run: python test/ChaosMonkey.py --full --num ${{ github.event.inputs.numChaos || 4 }}
- name: Run full sync
run: python GMSync.py --full
timeout-minutes: 5
- name: Check full sync results
if: always()
run: |
mv logs/sync.log logs/${{ env.TEST_RUNNER }}_sync_full.log && \
[[ -z "$(grep -e ERROR -e WARNING logs/${{ env.TEST_RUNNER }}_sync_full.log)" ]]
# Test sync back
- name: Prepare sync back
run: python test/ChaosMonkey.py --syncback --num ${{ github.event.inputs.numChaos || 4 }}
- name: Run sync back
run: python GMSync.py --syncback
timeout-minutes: 5
- name: Check sync back results
if: always()
run: |
mv logs/sync.log logs/${{ env.TEST_RUNNER }}_sync_syncback.log && \
[[ -z "$(grep -e ERROR -e WARNING logs/${{ env.TEST_RUNNER }}_sync_syncback.log)" ]]
# Test database check
- name: Prepare database check
run: python test/ChaosMonkey.py --check --num ${{ github.event.inputs.numChaos || 4 }}
- name: Run database check
run: python GMSync.py --check
timeout-minutes: 5
- name: Check database check results
if: always()
run: |
mv logs/sync.log logs/${{ env.TEST_RUNNER }}_sync_databasecheck.log && \
[[ -z "$(grep -e ERROR -e WARNING logs/${{ env.TEST_RUNNER }}_sync_databasecheck.log)" ]]
# End testing
- name: Cleanup testing environment
uses: ./.github/actions/cleanup-environment
if: always()
with:
TEST_RUNNER: ${{ env.TEST_RUNNER }}
REPO_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
- name: Upload log files
if: always()
uses: actions/upload-artifact@v3
with:
name: logs
path: |
logs/
data/${{ env.TEST_RUNNER }}_syncState.db
# 3. Build and publish docker container
docker_build:
runs-on: ubuntu-latest
needs: python_test
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
no-cache: true
push: true
tags: antonplagemann/google-monica-sync:next
# 4. Test published docker container
docker_test:
runs-on: ubuntu-latest
needs: docker_build
env:
TEST_RUNNER: docker
steps:
# Setup environment
- name: Check out source repository
uses: actions/checkout@v4
- name: Setup python environment
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Setup testing environment
uses: ./.github/actions/setup-environment
with:
GOOGLE_TOKEN: ${{ secrets.GOOGLE_TOKEN }}
CREATE_REMINDERS: ${{ github.event.inputs.CREATE_REMINDERS }}
DELETE_ON_SYNC: ${{ github.event.inputs.DELETE_ON_SYNC }}
STREET_REVERSAL: ${{ github.event.inputs.STREET_REVERSAL }}
FIELDS: ${{ github.event.inputs.FIELDS }}
GOOGLE_LABELS_INCLUDE: ${{ github.event.inputs.GOOGLE_LABELS_INCLUDE }}
GOOGLE_LABELS_EXCLUDE: ${{ github.event.inputs.GOOGLE_LABELS_EXCLUDE }}
MONICA_LABELS_INCLUDE: ${{ github.event.inputs.MONICA_LABELS_INCLUDE }}
MONICA_LABELS_EXCLUDE: ${{ github.event.inputs.MONICA_LABELS_EXCLUDE }}
# Test initial sync
- name: Prepare initial sync
run: python test/ChaosMonkey.py --initial --num ${{ github.event.inputs.numChaos || 4 }}
- name: Run initial sync
run: docker-compose -f test/docker-compose-sync.yml -f test/docker-compose-sync-initial.yml --env-file .env up
timeout-minutes: 5
- name: Check initial sync results
if: always()
run: |
mv logs/sync.log logs/${{ env.TEST_RUNNER }}_sync_initial.log && \
[[ -z "$(grep -e ERROR -e WARNING logs/${{ env.TEST_RUNNER }}_sync_initial.log)" ]]
# Test delta sync
- name: Prepare delta sync
run: python test/ChaosMonkey.py --delta --num ${{ github.event.inputs.numChaos || 4 }}
- name: Run delta sync
run: docker-compose -f test/docker-compose-sync.yml -f test/docker-compose-sync-delta.yml --env-file .env up
timeout-minutes: 5
- name: Check delta sync results
if: always()
run: |
mv logs/sync.log logs/${{ env.TEST_RUNNER }}_sync_delta.log && \
[[ -z "$(grep -e ERROR -e WARNING logs/${{ env.TEST_RUNNER }}_sync_delta.log)" ]]
# Test full sync
- name: Prepare full sync
run: python test/ChaosMonkey.py --full --num ${{ github.event.inputs.numChaos || 4 }}
- name: Run full sync
run: docker-compose -f test/docker-compose-sync.yml -f test/docker-compose-sync-full.yml --env-file .env up
timeout-minutes: 5
- name: Check full sync results
if: always()
run: |
mv logs/sync.log logs/${{ env.TEST_RUNNER }}_sync_full.log && \
[[ -z "$(grep -e ERROR -e WARNING logs/${{ env.TEST_RUNNER }}_sync_full.log)" ]]
# Test sync back
- name: Prepare sync back
run: python test/ChaosMonkey.py --syncback --num ${{ github.event.inputs.numChaos || 4 }}
- name: Run sync back
run: docker-compose -f test/docker-compose-sync.yml -f test/docker-compose-sync-syncback.yml --env-file .env up
timeout-minutes: 5
- name: Check sync back results
if: always()
run: |
mv logs/sync.log logs/${{ env.TEST_RUNNER }}_sync_syncback.log && \
[[ -z "$(grep -e ERROR -e WARNING logs/${{ env.TEST_RUNNER }}_sync_syncback.log)" ]]
# Test database check
- name: Prepare database check
run: python test/ChaosMonkey.py --check --num ${{ github.event.inputs.numChaos || 4 }}
- name: Run database check
run: docker-compose -f test/docker-compose-sync.yml -f test/docker-compose-sync-check.yml --env-file .env up
timeout-minutes: 5
- name: Check database check results
if: always()
run: |
mv logs/sync.log logs/${{ env.TEST_RUNNER }}_sync_databasecheck.log && \
[[ -z "$(grep -e ERROR -e WARNING logs/${{ env.TEST_RUNNER }}_sync_databasecheck.log)" ]]
# End testing
- name: Cleanup testing environment
uses: ./.github/actions/cleanup-environment
if: always()
with:
TEST_RUNNER: ${{ env.TEST_RUNNER }}
REPO_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
- name: Upload log files
if: always()
uses: actions/upload-artifact@v3
with:
name: logs
path: |
logs/
data/${{ env.TEST_RUNNER }}_syncState.db