-
Notifications
You must be signed in to change notification settings - Fork 3
278 lines (268 loc) · 9.5 KB
/
cicd.yaml
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
# CI/CD workflow for the groundlight-sdk-python repository. We lint, test, deploy docs, and publish
# to pypi.
name: cicd
on:
push:
env:
PYTHON_VERSION: "3.10"
POETRY_VERSION: "1.5.1"
jobs:
# Run our linter on every push to the repository.
lint:
runs-on: ubuntu-latest
steps:
- name: get code
uses: actions/checkout@v3
- name: install python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: install poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
- name: show python version ${{ env.PYTHON_VERSION }}
run: |
poetry run python --version
- name: install linter dependencies
run: |
make install-lint
- name: lint
run: |
make lint
# Run integration tests against the API. For efficiency, we only run one version of python on
# non-main branches.
test-simple:
runs-on: ubuntu-latest
steps:
- name: get code
uses: actions/checkout@v3
- name: install python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: install poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
- name: show python version ${{ env.PYTHON_VERSION }}
run: |
poetry run python --version
- name: install dependencies (without extras)
run: make install
# TODO: Should we run all tests against the prod API?
- name: run tests
env:
# This is associated with the "sdk-integ-test" user, credentials on 1password
GROUNDLIGHT_API_TOKEN: ${{ secrets.GROUNDLIGHT_API_TOKEN }}
run: make test-integ
- name: run docs tests
run: make test-docs
env:
# This is associated with the "sdk-test-prod" user, credentials on 1password
GROUNDLIGHT_API_TOKEN: ${{ secrets.GROUNDLIGHT_API_TOKEN_PROD }}
# Check that the docs build. (No broken links, etc.)
test-docs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: docs/
steps:
- name: Get code
uses: actions/checkout@v3
- name: Setup npm
uses: actions/setup-node@v3
with:
node-version: 18
cache: npm
- name: Install dependencies
run: npm install
- name: Build website
run: npm run build
# Checks that the API reference docs built with shpinx build
test-api-reference-docs:
runs-on: ubuntu-latest
steps:
- name: get code
uses: actions/checkout@v3
- name: install python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: install poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
- name: Install dependencies
run: make install-sphinx-deps
- name: Build API documentation
run: |
make apidocs
# Run integration tests against the API (only on the main branch, though). The comprehensive
# version runs a matrix of python versions for better coverage.
test-comprehensive:
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
needs:
- test-simple
- test-docs
runs-on: ubuntu-latest
strategy:
# It's totally debatable which is better here: fail-fast or not.
# Failing fast will use fewer cloud resources, in theory.
# But if the tests are slightly flaky (fail to pip install something)
# Then one flaky install kills lots of jobs that need to be redone.
# So the efficiency argument has its limits
# Failing slow is clearer about what's going on.
# This is pretty unambiguous, so we're going with it for now.
fail-fast: false
matrix:
python-version: [
#"3.6", # Default on Ubuntu18.04 but openapi-generator fails
"3.7",
"3.8",
"3.9",
"3.10",
"3.11",
]
install_extras: [true, false]
steps:
- name: get code
uses: actions/checkout@v3
- name: install python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: install poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
- name: show python version ${{ matrix.python-version }}
run: |
poetry run python --version
- name: install dependencies
run: make install
- name: install extras
if: matrix.install_extras
run: make install-extras
# TODO: Should we run all tests against the prod API?
- name: run tests
env:
# This is associated with the "sdk-integ-test" user, credentials on 1password
GROUNDLIGHT_API_TOKEN: ${{ secrets.GROUNDLIGHT_API_TOKEN }}
run: make test-integ
- name: run docs tests
run: make test-docs
env:
# This is associated with the "sdk-test-prod" user, credentials on 1password
GROUNDLIGHT_API_TOKEN: ${{ secrets.GROUNDLIGHT_API_TOKEN_PROD }}
# Run the auto-formatter when we're not on the main branch or creating a release. This will push a
# new commit to the PR branch if needed.
format:
if: startsWith(github.ref, 'refs/heads/') && github.ref != 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: get code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: install python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: install poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
- name: show python version ${{ env.PYTHON_VERSION }}
run: |
poetry run python --version
- name: install linter dependencies
run: |
make install-lint
- name: run formatter
run: |
make format
- name: check for modified files
id: git-check
run: |
git status
echo ::set-output name=modified::$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)
- name: push changes (if needed)
if: steps.git-check.outputs.modified == 'true'
run: |
git config --global user.name 'Auto-format Bot'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git commit -am "Automatically reformatting code"
git push
# Build and deploy the docs on all pushes to the `main` branch. Note that we don't require a code
# release -- we don't want to couple documentation updates with code releases.
# TODO: We'd like to build on pushes on any branch when docs/** changes. But then only deploy if
# we are on the `main` branch and docs/** has changes.
deploy-docs:
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
needs:
- test-comprehensive
- test-api-reference-docs
runs-on: ubuntu-latest
defaults:
run:
working-directory: docs/
steps:
- name: Get code
uses: actions/checkout@v3
- name: Setup npm
uses: actions/setup-node@v3
with:
node-version: 18
cache: npm
- name: Install dependencies
run: npm install
- name: Build website
run: |
cd ..
make docs-comprehensive
- name: Deploy website (if on main branch)
# Docs: https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/build
# Someday we might want to set the destination to a staging dir for PR's
#destination_dir: staging
# The following lines assign commit authorship to the official
# GH-Actions bot for deploys to `gh-pages` branch:
# https://github.com/actions/checkout/issues/13#issuecomment-724415212
# The GH actions bot is used by default if you didn't specify the two fields.
# You can swap them out with your own user credentials.
user_name: github-actions[bot]
user_email: 41898282+github-actions[bot]@users.noreply.github.com
# When a release is created on github (and comprehensive tests passed), publish the groundlight
# package to public pypi.
publish-python-package:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
needs:
- test-comprehensive
# For now, we'll require the comprehensive tests to succeed, but not the linter checks.
# - lint
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_PUBLISH_TOKEN }}
steps:
- name: get code
uses: actions/checkout@v3
- name: install python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: install poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
- name: show python version ${{ env.PYTHON_VERSION }}
run: |
poetry run python --version
- name: build package
run: poetry build
- name: configure poetry and publish
run: poetry publish