-
Notifications
You must be signed in to change notification settings - Fork 66
277 lines (272 loc) · 9.77 KB
/
cicd.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
name: CI/CD
on:
pull_request: # any pull request
push:
branches:
- master
defaults:
run:
shell: bash
env:
AWS_DEFAULT_OUTPUT: json
AWS_DEFAULT_REGION: us-east-1
AWS_MAX_ATTEMPTS: 20 # retry attempts for AWS API calls
AWS_RETRY_MODE: adaptive # defaults to "legacy"; this handles more errors
NODE_VERSION: '16'
PYTEST_ADDOPTS: --color=yes
RUNWAY_TEST_NAMESPACE: gh-${{ github.run_id }}
PIPENV_IGNORE_VIRTUALENVS: '1'
jobs:
changes:
runs-on: ubuntu-latest
outputs:
infra-test: ${{ steps.filter.outputs.infrastructure-test }}
infra-test-alt: ${{ steps.filter.outputs.infrastructure-test-alt }}
steps:
- uses: actions/checkout@v4 # not needed for pull_request
if: |
github.event_name == 'push'
- uses: dorny/paths-filter@v2 # cspell:ignore dorny
id: filter
with:
filters: |
infrastructure-test:
- 'infrastructure/blueprints/admin_user.py'
- 'infrastructure/blueprints/cfngin_bucket.py'
- 'infrastructure/blueprints/prevent_privilege_escalation.py'
- 'infrastructure/blueprints/test_runner_boundary.py'
- 'infrastructure/blueprints/test_runner_user.py'
- 'infrastructure/test/common/**'
infrastructure-test-alt:
- 'infrastructure/blueprints/admin_role.py'
- 'infrastructure/blueprints/cfngin_bucket.py'
- 'infrastructure/blueprints/prevent_privilege_escalation.py'
- 'infrastructure/blueprints/test_runner_boundary.py'
- 'infrastructure/test-alt/common/**'
deploy-test-infrastructure:
name: Deploy Test Infrastructure
environment: test
concurrency: test-infrastructure
needs: changes
if: |
github.repository == 'onicagroup/runway' &&
(needs.changes.outputs.infra-test == 'true' || needs.changes.outputs.infra-test-alt == 'true')
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- uses: actions/setup-python@v4
id: setup-python
with:
python-version: 3.9
- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v3
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Ensure Cache Is Healthy
if: runner.os != 'Windows' && steps.cache.outputs.cache-hit == 'true'
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
- run: poetry install --extras docs -vv
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.DEPLOY_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.DEPLOY_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- run: make deploy test
working-directory: infrastructure
- run: make deploy test-alt
working-directory: infrastructure
lint-python:
name: Lint Python
strategy:
matrix:
python-version: [3.9, '3.10', '3.11']
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
# populating AWS creds with fake values
AWS_ACCESS_KEY_ID: test
AWS_SECRET_ACCESS_KEY: test
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- uses: actions/setup-python@v4
id: setup-python
with:
python-version: ${{ matrix.python-version }}
- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v3
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Ensure Cache Is Healthy
if: runner.os != 'Windows' && steps.cache.outputs.cache-hit == 'true'
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
- run: poetry install --extras docs -vv
- name: Install Node Dependencies
run: make npm-ci
- name: Run Linters
run: make lint
pre-commit:
name: pre-commit
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
id: setup-python
with:
python-version: ${{ matrix.python-version }}
- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v3
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Ensure Cache Is Healthy
if: runner.os != 'Windows' && steps.cache.outputs.cache-hit == 'true'
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
- run: poetry install --extras docs -vv
- uses: pre-commit/action@v3.0.0
test-functional:
name: Functional Tests
needs: deploy-test-infrastructure
# will fail if run from forks
if: |
always() &&
github.repository == 'onicagroup/runway' &&
github.actor != 'dependabot[bot]' &&
(needs.deploy-test-infrastructure.result == 'success' || needs.deploy-test-infrastructure.result == 'skipped')
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- uses: actions/setup-python@v4
id: setup-python
with:
python-version: 3.9
- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v3
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Ensure Cache Is Healthy
if: runner.os != 'Windows' && steps.cache.outputs.cache-hit == 'true'
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
- run: poetry install --extras docs -vv
- name: Install Ubuntu Dependencies
run: |
sudo apt update -y
sudo apt install -y default-libmysqlclient-dev libxml2-dev libxmlsec1-dev libxmlsec1-openssl pkg-config
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.TEST_RUNNER_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.TEST_RUNNER_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Run Tests
run: make test-functional
test-python:
name: Test Python
strategy:
matrix:
python-version: [3.9, '3.10', '3.11']
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
# populating AWS creds with fake values
AWS_ACCESS_KEY_ID: test
AWS_SECRET_ACCESS_KEY: test
steps:
- name: Checkout Repo (complete)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- uses: actions/setup-python@v4
id: setup-python
with:
python-version: ${{ matrix.python-version }}
- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v3
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Ensure Cache Is Healthy
if: steps.cache.outputs.cache-hit == 'true'
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
- run: poetry install --extras docs -vv
- name: Install Node Dependencies
run: make npm-install
- name: Configure Pagefile # avoid MemoryError during tests
if: runner.os == 'Windows'
uses: al-cheb/configure-pagefile-action@v1.3 # cspell:ignore cheb
with:
minimum-size: 16GB
maximum-size: 16GB
disk-root: 'C:'
- name: Run Integration & Unit Tests
# assertions assume linux so some fail when run on windows
run: make test cov-xml
- name: Upload to Codecov
uses: codecov/codecov-action@v3.1.4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
fail_ci_if_error: true
build-pypi:
name: Build PyPi 📦
needs:
- pre-commit
runs-on: ubuntu-latest
steps:
- name: Checkout Repo (complete)
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v4
id: setup-python
with:
python-version: 3.9
# Remove apt repos that are known to break from time to time
# See https://github.com/actions/virtual-environments/issues/323
- name: Remove broken apt repos (ubuntu)
run: |
for apt_file in `grep -lr microsoft /etc/apt/sources.list.d/`; do sudo rm $apt_file; done
- name: Install Dependencies (ubuntu)
run: sudo apt-get update && sudo apt-get install sed -y
- uses: Gr1N/setup-poetry@v8
- uses: actions/cache@v3
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Ensure Cache Is Healthy
if: runner.os != 'Windows' && steps.cache.outputs.cache-hit == 'true'
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
- run: poetry install --extras docs -vv
- name: Run Build
run: make build
- name: Upload Distribution Artifact
uses: actions/upload-artifact@v3
with:
name: pypi-dist
path: dist