-
Notifications
You must be signed in to change notification settings - Fork 66
243 lines (238 loc) · 8.72 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
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: '20'
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:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v4 # not needed for pull_request
if: |
github.event_name == 'push'
- uses: dorny/paths-filter@v3 # 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/**'
info:
name: Output useful information
runs-on: ubuntu-latest
outputs:
is-actor-bot: ${{ steps.gh-context.outputs.is-actor-bot }} # if the actor (user) is a bot
is-fork: ${{ steps.gh-context.outputs.is-fork }} # if the action is running in or from (PR) a fork
repo-head: ${{ steps.gh-context.outputs.repo-head }} # repo where change occurred
repo-origin: ${{ steps.gh-context.outputs.repo-origin }} # origin of codebase
steps:
- name: ℹ️ Output GitHub Context
id: gh-context
run: |
export _REPO_ORIGIN="rackspace/runway";
echo "repo-origin=${_REPO_ORIGIN}" >> "${GITHUB_OUTPUT}";
export _REPO_HEAD="${{ github.event.pull_request.head.repo.full_name || github.repository }}";
echo "repo-head=${_REPO_HEAD}" >> "${GITHUB_OUTPUT}";
if [[ "${_REPO_HEAD}" == "${_REPO_ORIGIN}" ]]; then
echo "is-fork=false" >> "${GITHUB_OUTPUT}";
else
echo "is-fork=true" >> "${GITHUB_OUTPUT}";
fi;
if [[ ${{ github.actor }} == *"[bot]" ]]; then
echo "is-actor-bot=true" >> "${GITHUB_OUTPUT}";
else
echo "is-actor-bot=false" >> "${GITHUB_OUTPUT}";
fi;
deploy-test-infrastructure:
name: Deploy Test Infrastructure
environment: test
concurrency: test-infrastructure
needs:
- changes
- info
if: |
needs.info.outputs.is-fork == 'false' &&
(needs.changes.outputs.infra-test == 'true' || needs.changes.outputs.infra-test-alt == 'true')
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v4
- name: 🏗 Setup Python
uses: finleyfamily/action-setup-python@v1.0.0
with:
poetry-plugins: poetry-dynamic-versioning[plugin]
- 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
- name: 🚀 Deploy to the test environment
run: make deploy test
working-directory: infrastructure
- name: 🚀 Deploy to the test-alt environment
run: make deploy test-alt
working-directory: infrastructure
lint-python:
name: Lint Python
strategy:
fail-fast: false
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: ⤵️ Check out code from GitHub
uses: actions/checkout@v4
- name: 🏗 Setup Node
uses: actions/setup-node@v4
with:
cache: npm
node-version: ${{ env.NODE_VERSION }}
- name: 🏗 Setup Python
uses: finleyfamily/action-setup-python@v1.0.0
with:
poetry-plugins: poetry-dynamic-versioning[plugin]
python-version: ${{ matrix.python-version }}
- name: ⤵️ Install Node Dependencies
run: make setup-npm
- name: 🚀 Run Linters
run: make lint
test-functional:
name: Functional Tests
needs:
- deploy-test-infrastructure
- info
if: |
always() &&
needs.info.outputs.is-fork == 'false' &&
needs.info.outputs.is-actor-bot == 'false' &&
(needs.deploy-test-infrastructure.result == 'success' || needs.deploy-test-infrastructure.result == 'skipped')
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v4
- name: 🏗 Setup Node
uses: actions/setup-node@v4
with:
cache: npm
node-version: ${{ env.NODE_VERSION }}
- name: 🏗 Setup Python
uses: finleyfamily/action-setup-python@v1.0.0
with:
poetry-plugins: poetry-dynamic-versioning[plugin]
python-version: '3.10'
- 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:
fail-fast: false
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: ⤵️ Check out code from GitHub (complete)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🏗 Setup Node
uses: actions/setup-node@v4
with:
cache: npm
node-version: ${{ env.NODE_VERSION }}
- name: 🏗 Setup Python
uses: finleyfamily/action-setup-python@v1.0.0
with:
poetry-plugins: poetry-dynamic-versioning[plugin]
python-version: ${{ matrix.python-version }}
- name: ⤵️ Install Node Dependencies
run: make setup-npm
- name: 🏗 Configure Pagefile # avoid MemoryError during tests
if: runner.os == 'Windows'
uses: al-cheb/configure-pagefile-action@v1.4 # 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@v4.6.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
build-pypi:
name: Build PyPi 📦
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub (complete)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🏗 Setup Python
uses: finleyfamily/action-setup-python@v1.0.0
with:
poetry-install: false
poetry-plugins: poetry-dynamic-versioning[plugin]
# 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
- name: 👷 Build
run: make build
- name: ⤴️ Upload distribution artifact
uses: actions/upload-artifact@v4
with:
name: pypi-dist
path: dist