-
Notifications
You must be signed in to change notification settings - Fork 3
325 lines (278 loc) · 10.1 KB
/
deploy-staged.yml
File metadata and controls
325 lines (278 loc) · 10.1 KB
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
name: Release to Modal
on:
push:
branches:
- main
workflow_dispatch:
inputs:
new_app_target:
description: "Where to deploy the newly built worker app"
required: true
default: frontier
type: choice
options:
- frontier
- current
- both
- none
promote_existing_frontier:
description: "Move the existing frontier worker to current before deploying a new frontier"
required: true
default: true
type: boolean
cleanup_target:
description: "Modal app group to stop after updating the manifest"
required: true
default: retired
type: choice
options:
- none
- retired
- frontier
- current
env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
MODAL_WORKSPACE: policyengine
PYTHON_VERSION: "3.13"
concurrency:
group: household-api-modal-release
cancel-in-progress: false
jobs:
lint-and-test:
name: Lint and test
runs-on: ubuntu-latest
if: |
github.repository == 'PolicyEngine/policyengine-household-api' &&
(
github.event_name == 'workflow_dispatch' ||
github.event.head_commit.message == 'Update PolicyEngine Household API'
)
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: make install
- name: Run Ruff format check
run: make format-check
- name: Run tests without auth
run: make test
- name: Run tests with auth
run: make test-with-auth
env:
AUTH__ENABLED: true
AUTH0_ADDRESS_NO_DOMAIN: ${{ secrets.AUTH0_ADDRESS_NO_DOMAIN }}
AUTH0_AUDIENCE_NO_DOMAIN: ${{ secrets.AUTH0_AUDIENCE_NO_DOMAIN }}
AUTH0_TEST_TOKEN_NO_DOMAIN: ${{ secrets.AUTH0_TEST_TOKEN_NO_DOMAIN }}
AUTH0_TEST_TOKEN_SCOPES: ${{ secrets.AUTH0_TEST_TOKEN_SCOPES }}
resolve-modal-release-config:
name: Resolve Modal release config
runs-on: ubuntu-latest
if: |
github.repository == 'PolicyEngine/policyengine-household-api' &&
(
github.event_name == 'workflow_dispatch' ||
github.event.head_commit.message == 'Update PolicyEngine Household API'
)
permissions:
contents: read
pull-requests: read
outputs:
should_deploy: ${{ steps.resolve.outputs.should_deploy }}
source: ${{ steps.resolve.outputs.source }}
deploy_mode: ${{ steps.resolve.outputs.deploy_mode }}
new_app_target: ${{ steps.resolve.outputs.new_app_target }}
promote_existing_frontier: ${{ steps.resolve.outputs.promote_existing_frontier }}
cleanup_target: ${{ steps.resolve.outputs.cleanup_target }}
config_json: ${{ steps.resolve.outputs.config_json }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: pip install -e .
- name: Resolve Modal release config
id: resolve
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python .github/scripts/resolve_modal_release_config.py \
--output-json modal-release-config.json
deploy-modal-staging:
name: Deploy Modal release to staging
runs-on: ubuntu-latest
needs: [lint-and-test, resolve-modal-release-config]
if: needs.resolve-modal-release-config.outputs.should_deploy == 'true'
environment: staging
permissions:
contents: read
env:
MODAL_ENVIRONMENT: staging
MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
ANALYTICS__ENABLED: "true"
USER_ANALYTICS_DB_CONNECTION_NAME: ${{ secrets.USER_ANALYTICS_DB_CONNECTION_NAME }}
USER_ANALYTICS_DB_USERNAME: ${{ secrets.USER_ANALYTICS_DB_USERNAME }}
USER_ANALYTICS_DB_PASSWORD: ${{ secrets.USER_ANALYTICS_DB_PASSWORD }}
steps:
- uses: actions/checkout@v4
- name: Authenticate to Google Cloud for analytics database
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Sync dependencies
run: uv sync --extra dev
- name: Ensure Modal staging environment exists
run: uv run modal environment create staging 2>/dev/null || true
- name: Deploy Modal app set
id: deploy
env:
APP__ENVIRONMENT: staging
AUTH__ENABLED: "true"
AUTH0_ADDRESS_NO_DOMAIN: ${{ secrets.AUTH0_ADDRESS_NO_DOMAIN }}
AUTH0_AUDIENCE_NO_DOMAIN: ${{ secrets.AUTH0_AUDIENCE_NO_DOMAIN }}
AI__ENABLED: "true"
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
GCP_CREDENTIALS_JSON: ${{ secrets.GCP_SA_KEY }}
run: |
bash .github/scripts/modal-deploy-release.sh \
'${{ needs.resolve-modal-release-config.outputs.config_json }}' \
'${{ needs.resolve-modal-release-config.outputs.deploy_mode }}'
integration-tests-staging:
name: Integration tests against Modal staging (${{ matrix.channel }}, ${{ matrix.route_mode }})
runs-on: ubuntu-latest
needs: [deploy-modal-staging]
environment: staging
env:
MODAL_ENVIRONMENT: staging
MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
strategy:
fail-fast: false
matrix:
channel: [current, frontier]
route_mode: [channel, exact]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Sync dependencies
run: uv sync --extra dev
- name: Fetch Auth0 test token
env:
AUTH0_DOMAIN: ${{ secrets.AUTH0_ADDRESS_NO_DOMAIN }}
AUTH0_AUDIENCE: ${{ secrets.AUTH0_AUDIENCE_NO_DOMAIN }}
AUTH0_CLIENT_ID: ${{ secrets.AUTH0_TEST_TOKEN_CLIENT_ID }}
AUTH0_CLIENT_SECRET: ${{ secrets.AUTH0_TEST_TOKEN_CLIENT_SECRET }}
AUTH0_TEST_TOKEN_SCOPES: ${{ secrets.AUTH0_TEST_TOKEN_SCOPES }}
run: python .github/scripts/fetch_auth0_test_token.py
- name: Run deployed integration tests for route
run: |
bash .github/scripts/run-deployed-tests-for-modal-route.sh \
"${{ matrix.channel }}" \
"${{ matrix.route_mode }}"
deploy-modal-production:
name: Deploy Modal release to production
runs-on: ubuntu-latest
needs: [resolve-modal-release-config, integration-tests-staging]
if: needs.resolve-modal-release-config.outputs.should_deploy == 'true'
environment: production
permissions:
contents: read
env:
MODAL_ENVIRONMENT: main
MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
ANALYTICS__ENABLED: "true"
USER_ANALYTICS_DB_CONNECTION_NAME: ${{ secrets.USER_ANALYTICS_DB_CONNECTION_NAME }}
USER_ANALYTICS_DB_USERNAME: ${{ secrets.USER_ANALYTICS_DB_USERNAME }}
USER_ANALYTICS_DB_PASSWORD: ${{ secrets.USER_ANALYTICS_DB_PASSWORD }}
steps:
- uses: actions/checkout@v4
- name: Authenticate to Google Cloud for analytics database
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Sync dependencies
run: uv sync --extra dev
- name: Deploy Modal app set
id: deploy
env:
APP__ENVIRONMENT: production
AUTH__ENABLED: "true"
AUTH0_ADDRESS_NO_DOMAIN: ${{ secrets.AUTH0_ADDRESS_NO_DOMAIN }}
AUTH0_AUDIENCE_NO_DOMAIN: ${{ secrets.AUTH0_AUDIENCE_NO_DOMAIN }}
AI__ENABLED: "true"
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
GCP_CREDENTIALS_JSON: ${{ secrets.GCP_SA_KEY }}
run: |
bash .github/scripts/modal-deploy-release.sh \
'${{ needs.resolve-modal-release-config.outputs.config_json }}' \
'${{ needs.resolve-modal-release-config.outputs.deploy_mode }}'
publish:
name: Publish to PyPI
runs-on: ubuntu-latest
if: |
github.repository == 'PolicyEngine/policyengine-household-api' &&
github.event_name == 'push' &&
github.event.head_commit.message == 'Update PolicyEngine Household API'
needs: [deploy-modal-production]
environment:
name: pypi
url: https://pypi.org/p/policyengine-household-api
permissions:
contents: read
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Build package
run: uv build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
tag-release:
name: Publish git tag
runs-on: ubuntu-latest
if: |
github.repository == 'PolicyEngine/policyengine-household-api' &&
github.event_name == 'push' &&
github.event.head_commit.message == 'Update PolicyEngine Household API'
needs: [publish]
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Publish Git tag
run: bash .github/publish-git-tag.sh