forked from getmoto/moto
-
Notifications
You must be signed in to change notification settings - Fork 0
382 lines (369 loc) · 12.4 KB
/
build.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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
name: TestNDeploy
on: [push, pull_request]
jobs:
# Install and cache dependencies
terraformcache:
name: Caching Terraform dependencies
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.8 ]
steps:
- name: Checkout Terraform Tests repo
uses: actions/checkout@v2
with:
repository: localstack/localstack-terraform-test
ref: build
path: moto-terraform-tests
submodules: 'true'
- uses: actions/setup-go@v2
with:
go-version: '^1.16.0'
- run: go version
- name: cache
id: terraformcache
uses: actions/cache@v2
with:
path: '~/.cache'
key: 'terraformcache_download2'
- name: Download
env:
DOWNLOAD_TEST_BIN: 1
TEST_BIN_URL: "https://moto-terraform-test.s3.amazonaws.com/aws.test"
if: ${{ steps.terraformcache.outputs.cache-hit != 'true' }}
run: |
cd moto-terraform-tests
bin/install-aws-test
cd ..
cache:
name: Caching
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.6, 3.7, 3.8, 3.9, "3.10" ]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Get pip cache dir
id: pip-cache-dir
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: pip cache
id: pip-cache
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache-dir.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}-4
- name: Update pip
if: ${{ steps.pip-cache.outputs.cache-hit != 'true' }}
run: |
python -m pip install --upgrade pip
- name: Install project dependencies
if: ${{ steps.pip-cache.outputs.cache-hit != 'true' }}
run: |
pip install -r requirements-dev.txt
lint:
name: Linting
runs-on: ubuntu-latest
needs: cache
strategy:
matrix:
python-version: [3.7]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
# Retrieve the previously cached dependencies
- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: pip cache
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}-4
# Update PIP
- name: Update pip
run: |
python -m pip install --upgrade pip
# Still need to properly install the dependencies - it will only skip the download part
- name: Install project dependencies
run: |
pip install -r requirements-dev.txt
- name: Lint with flake8
run:
make lint
test:
name: Unit test
runs-on: ubuntu-latest
needs: lint
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: pip cache
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}-4
- name: Update pip
run: |
python -m pip install --upgrade pip
- name: Install project dependencies
run: |
pip install -r requirements-dev.txt
pip install pytest-cov
pip install pytest-github-actions-annotate-failures
# https://github.com/aws/aws-xray-sdk-python/issues/196
pip install "coverage<=4.5.4"
- name: Test with pytest
run: |
make test-only
- name: "Upload coverage to Codecov"
if: ${{ github.repository == 'spulec/moto'}}
uses: codecov/codecov-action@v1
with:
fail_ci_if_error: false
flags: unittests
testserver:
name: Unit tests in Server Mode
runs-on: ubuntu-latest
needs: lint
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Start MotoServer
run: |
python setup.py sdist
docker run --rm -t --name motoserver -e TEST_SERVER_MODE=true -e AWS_SECRET_ACCESS_KEY=server_secret -e AWS_ACCESS_KEY_ID=server_key -v `pwd`:/moto -p 5000:5000 -v /var/run/docker.sock:/var/run/docker.sock python:3.7-buster /moto/scripts/ci_moto_server.sh &
python scripts/ci_wait_for_server.py
- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: pip cache
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}-4
- name: Update pip
run: |
python -m pip install --upgrade pip
- name: Install project dependencies
run: |
pip install -r requirements-dev.txt
pip install "coverage<=4.5.4"
- name: Test ServerMode/Coverage
env:
TEST_SERVER_MODE: ${{ true }}
run: |
make test-only
- name: "Upload coverage to Codecov"
if: ${{ github.repository == 'spulec/moto'}}
uses: codecov/codecov-action@v1
with:
fail_ci_if_error: false
flags: servertests
- name: "Stop MotoServer"
if: always()
run: |
mkdir serverlogs
pwd
ls -la
cp server_output.log serverlogs/server_output.log
docker stop motoserver
- name: Archive TF logs
if: always()
uses: actions/upload-artifact@v2
with:
name: motoserver-${{ matrix.python-version }}
path: |
serverlogs/*
terraform:
name: Terraform Tests
runs-on: ubuntu-latest
needs: terraformcache
strategy:
fail-fast: false
matrix:
python-version: [ 3.8 ]
part: ["aa", "ab", "ac", "ad", "ae", "af", "ag"]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Checkout Terraform Tests repo
uses: actions/checkout@v2
with:
repository: localstack/localstack-terraform-test
ref: build
path: moto-terraform-tests
submodules: 'true'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: cache
uses: actions/cache@v2
with:
path: '~/.cache'
key: 'terraformcache_download2'
- name: Start MotoServer
run: |
python setup.py sdist
docker run --rm -t --name motoserver -e TEST_SERVER_MODE=true -e MOTO_PORT=4566 -e AWS_SECRET_ACCESS_KEY=server_secret -e AWS_ACCESS_KEY_ID=server_key -v `pwd`:/moto -p 4566:4566 -v /var/run/docker.sock:/var/run/docker.sock python:3.7-buster /moto/scripts/ci_moto_server.sh &
MOTO_PORT=4566 python scripts/ci_wait_for_server.py
# Poor man's parallelization
# Running them sequentially takes too much time
# And using the build in parallel-argument does not help with reducing runtime
# So we simply split the list of tests, and ask our CI for separate VM's to run them in parallel
- name: Get list of tests
run: |
cd moto-terraform-tests
bin/list-tests -i ../tests/terraform-tests.success.txt -e ../tests/terraform-tests.failures.txt > tftestlist.txt
split -n l/7 tftestlist.txt tf-split-
cd ..
- name: Run Terraform Tests
run: |
cd moto-terraform-tests
echo "Copying random zipfile that is missing for SSM tests..."
cp terraform-provider-aws/aws/test-fixtures/lambda_elb.zip terraform-provider-aws/aws/test-fixtures/ssm-doc-acc-test.zip
AWS_DEFAULT_REGION=us-east-1 AWS_ALTERNATE_REGION=eu-west-1 bin/run-tests -t -i tf-split-${{ matrix.part }} -e ../tests/terraform-tests.failures.txt
cd ..
- name: "Create report"
run: |
ls -la
cp server_output.log moto-terraform-tests/build/server_output.log
cd moto-terraform-tests
bin/create-report
bin/create-report-cli
cd ..
- name: Archive TF logs
if: always()
uses: actions/upload-artifact@v2
with:
name: buildfolder-${{ matrix.part }}
path: |
moto-terraform-tests/build/*
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: [test, testserver, terraform ]
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'spulec/moto' }}
strategy:
matrix:
python-version: [3.8]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Update & Build
run: |
pip install wheel packaging
python update_version_from_git.py
python setup.py sdist bdist_wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Build Docker release
run: |
docker build -t motoserver/moto . --tag moto:latest
# Required to get the correct Digest
# See https://github.com/docker/build-push-action/issues/461
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
push: true
tags: motoserver/moto:latest
- name: Get version number
run: |
version=$(grep -oP '(?<=__version__ = ")[0-9.a-z]+(?=")' moto/__init__.py)
echo "moto_version=$version" >> $GITHUB_ENV
- uses: octokit/[email protected]
name: Get PR info
id: get_pr
with:
query: |
query get_pr($owner:String!,$repo:String!,$commit:GitObjectID) {
repository(owner:$owner,name:$repo) {
object(oid:$commit) {
... on Commit {
associatedPullRequests(last: 1){
edges {
node {
baseRepository {
nameWithOwner
}
merged
number
}
}
}
}
}
}
}
owner: ${{ github.event.repository.owner.name }}
repo: ${{ github.event.repository.name }}
commit: "${{ github.sha }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get PR number
run: |
nr="${{ fromJSON(steps.get_pr.outputs.data).repository.object.associatedPullRequests.edges[0].node.number }}"
repo="${{ fromJSON(steps.get_pr.outputs.data).repository.object.associatedPullRequests.edges[0].node.baseRepository.nameWithOwner }}"
if [ -z "$nr" ]
then
echo "PR nr not found in $msg"
echo "pr_found=false" >> $GITHUB_ENV
else
echo "PR NR: $nr"
echo "pr_nr=$nr" >> $GITHUB_ENV
echo "pr_repo=$repo" >> $GITHUB_ENV
echo "pr_found=true" >> $GITHUB_ENV
fi
- name: Leave PR comment with Moto version
uses: peter-evans/create-or-update-comment@v1
if: env.pr_found == 'true' && env.pr_repo == 'spulec/moto'
with:
issue-number: ${{ env.pr_nr }}
body: |
This is now part of moto >= ${{ env.moto_version }}