forked from looker-open-source/sdk-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
286 lines (255 loc) · 9.49 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
name: Python CI
on:
pull_request:
paths:
- python/**
push:
branches:
- main
paths:
- python/**
workflow_dispatch:
env:
LOOKERSDK_BASE_URL: https://localhost:20000
LOOKERSDK_VERIFY_SSL: false
TOX_JUNIT_OUTPUT_DIR: results
jobs:
typecheck:
name: Mypy
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: python/
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.9.9
- run: pip install -e .
- run: pip install mypy types-requests
- run: mypy looker_sdk/
unit:
needs: typecheck
name: Unit - ${{ matrix.os }} / py${{ matrix.python-version }}
env:
TOX_JUNIT_OUTPUT_NAME: ${{ matrix.os }}.py${{ matrix.python-version }}
runs-on: ${{ matrix.os }}-latest
defaults:
run:
shell: bash
working-directory: python/
strategy:
# run all supported python versions on ubuntu
# run only latest supported python version on windows/mac
matrix:
os:
- ubuntu
- macos
- windows
python-version:
- '3.9.9'
include:
- python-version: '3.6'
os: ubuntu
- python-version: '3.7'
os: ubuntu
- python-version: '3.8'
os: ubuntu
steps:
- name: Repo Checkout
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install Tox and any other packages
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run Unit Tests
run: tox -e unit
- name: Upload pytest test results
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: python-test-results
path: python/results/
integration:
needs: unit
name: Integration - ${{ matrix.os }} / Looker.${{ matrix.looker }}
env:
TOX_JUNIT_OUTPUT_NAME: ${{ matrix.os }}.Looker-${{ matrix.looker }}.py3.x
runs-on: ${{ matrix.os }}-latest
defaults:
run:
shell: bash
working-directory: python/
strategy:
matrix:
os:
- ubuntu
looker:
- '21_18'
- '21_20'
- '22_0'
- '22_2'
# TODO uncomment `include:` when either macos or windows works to satisfaction.
#include:
# TODO: macos matrix leg is functional but it takes ~20 minutes (compared
# to ~4 minutes for ubuntu) because docker install takes ~5 minutes
# and docker pull takes ~10 minutes. We can probably figure out how to
# cache the docker install but hopefully github will soon have docker
# available pre-installed on macos so not worth the effort now.
# Regarding docker pull ... it would be nice if there's a way to cache
# only some layers of the image on the runner but we don't want to cache
# the final layer(s) with Looker IP. This would speed up docker pull on
# all OSs.
#- os: macos
# python-version: 3.9
# looker: '7_20'
# TODO: currently can't run linux containers on windows.
# Pending new windows server version
# https://github.com/actions/virtual-environments/issues/1143#issuecomment-698797524
#- os: windows
# python-version: 3.9
# looker: '7_20'
steps:
- name: Repo Checkout
uses: actions/checkout@v2
- name: Set up Cloud SDK
uses: google-github-actions/[email protected]
with:
project_id: ${{ secrets.GCP_PROJECT_ID }}
service_account_key: ${{ secrets.GCP_AR_READER_SA_KEY }}
export_default_credentials: true
- name: Authenticate Artifact Repository
run: gcloud auth configure-docker us-west1-docker.pkg.dev --quiet
- name: Install docker on macos
if: ${{ matrix.os == 'macos' }}
uses: docker-practice/actions-setup-docker@v1
with:
docker_channel: stable
docker_buildx: false
docker_cli_experimental: disabled
- name: Bump docker for mac memory
if: ${{ matrix.os == 'macos' }}
run: |
osascript -e 'quit app "Docker"'
sed -i'.original' -e's/ "memoryMiB" : 2048/ "memoryMiB" : 8192/' ~/Library/Group\ Containers/group.com.docker/settings.json
open -g /Applications/Docker.app
# re-run docker startup logic from docker-practice/actions-setup-docker action
sleep 60
i=0
while ! docker system info &>/dev/null; do
(( i++ == 0 )) && printf %s '-- Waiting for Docker to finish starting up...' || printf '.'
sleep 1
done
(( i )) && printf '\n'
echo "-- Docker is ready."
- name: Pull and run Looker docker image
# TODO: can we cache some layers of the image for faster download?
# we probably don't want to cache the final image for IP security...
run: |
docker pull --quiet us-west1-docker.pkg.dev/cloud-looker-sdk-codegen-cicd/looker/${{ matrix.looker }}
# set $LOOKER_OPTS to --no-ssl if we want to turn off ssl
docker run --name looker-sdk-codegen-ci -d -p 10000:9999 -p 20000:19999 us-west1-docker.pkg.dev/cloud-looker-sdk-codegen-cicd/looker/${{ matrix.looker }}
docker logs -f looker-sdk-codegen-ci --until=30s &
- name: Install Tox and any other packages
run: |
python -m pip install --upgrade pip
pip install tox
- name: Determine credentials version
# Prior to 21_18, each version had different credentials and a
# different secret. 21_20 and later all use the same credentials
# as 21_18. The parse_version.sh script parses the version and
# yields 21_12, 21_14, 21_16 etc for those versions but 21_18 for
# anything 21_18, 21_20, 22_0, etc.
#
# This can be factored out entirely once 21_18 is the earliest
# supported looker version.
run: |
echo "CREDENTIALS_VERSION=$(${{ github.workspace }}/.github/scripts/parse_version.sh <<< ${{ matrix.looker }})" >> $GITHUB_ENV
- name: Set up Looker credentials
# Load the correct credentials based on the version from
# the prior step.
run: |
echo "LOOKERSDK_CLIENT_ID=${{ secrets[format('LOOKERSDK_CLIENT_ID__{0}', env.CREDENTIALS_VERSION )] }}" >> $GITHUB_ENV
echo "LOOKERSDK_CLIENT_SECRET=${{ secrets[format('LOOKERSDK_CLIENT_SECRET__{0}', env.CREDENTIALS_VERSION )] }}" >> $GITHUB_ENV
- name: Check that Looker is ready
run: |
${{ github.workspace }}/.github/scripts/wait_for_looker.sh
- name: Run Integration Tests
run: tox -e integration
- name: Upload pytest test results
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: python-test-results
path: python/results/
twine:
needs: integration
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: python/
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.9.9
- name: Twine upload check
run: |
pip install wheel twine
python setup.py sdist bdist_wheel
twine check dist/*
publish-test-results:
needs: [unit, integration, twine]
if: success() || failure()
runs-on: ubuntu-latest
steps:
- name: Download Artifacts
uses: actions/download-artifact@v2
with:
path: artifacts
# If there are no test result files the test is reported as passing!
# That allows for some weird failure modes, where an early failure
# is not distinguished from a pass.
- name: Check Results Files Exist
id: check-results-exist
run: |
if [[ $(ls -l artifacts/python-test-results/*.xml 2> /dev/null | wc -l) -ge "1" ]]; then
exit 0
else
curl --request POST \
--url https://api.github.com/repos/looker-open-source/sdk-codegen/check-runs \
--header "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
--header "content-type: application/json" \
--header "Accept: application/vnd.github.v3+json" \
--data '{
"name": "Python Tests",
"head_sha": "${{ github.event.pull_request.head.sha || github.sha }}",
"conclusion": "failure"
}' \
--fail \
-o /dev/null \
--silent
exit 1
fi
- name: Publish Unit Test Results
if: steps.check-results-exist.outcome == 'success'
uses: EnricoMi/[email protected]
with:
# Cosmetic issue with `check_name` being associated to the wrong
# workflow: https://github.com/EnricoMi/publish-unit-test-result-action/issues/12
check_name: Python Tests
github_token: ${{ secrets.GITHUB_TOKEN }}
report_individual_runs: true
hide_comments: orphaned commits
check_run_annotations_branch: '*'
files: 'artifacts/python-test-results/*.xml'