-
Notifications
You must be signed in to change notification settings - Fork 0
350 lines (310 loc) · 11.9 KB
/
generate-homeval.yaml
File metadata and controls
350 lines (310 loc) · 11.9 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
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
name: generate-homeval
on:
workflow_dispatch:
inputs:
year:
type: string
description: >
Assessment year: Use values and comps from the final model for this year.
Leave blank if you are supplying a run ID instead
required: false
default: ""
run_id:
type: string
description: >
Run ID: The model run whose comps should be used. Leave blank if you are supplying
an assessment year instead
required: false
default: ""
pins:
type: string
description: >
PINs: One or more space‑separated Cook County PINs. Leave blank to
generate reports for all PINs in the County, or if you are supplying
township codes
required: false
default: ""
townships:
type: string
description: >
Township codes: One or more space-separated township codes. Leave blank to
generate reports for all PINs in the County, or if you are supplying PINs
required: false
default: ""
environment:
type: choice
description: >
Environment: Choose where to upload the reports
options:
- Development bucket
- Production bucket
default: Development bucket
required: true
deploy-assets:
type: boolean
description: >
Deploy static assets like favicons and error pages in addition
to reports
required: false
default: false
hugo-build-by-nbhd:
type: boolean
description: >
Build reports by neighborhood: Slower, but uses less memory
required: false
default: false
eligible-only:
type: boolean
description: >
Only generate reports for PINs that are eligible for reports (i.e. no error pages)
required: false
default: false
env:
PYTHONUNBUFFERED: "1"
UV_SYSTEM_PYTHON: 1
AWS_REGION: us-east-1
AWS_ATHENA_S3_STAGING_DIR: s3://ccao-athena-results-us-east-1/
HUGO_VERSION: "0.147.5"
defaults:
run:
# Always use builtin bash shell to take advantage of automatic -eo pipefail.
# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#defaultsrunshell
shell: bash
jobs:
###############################################################################
# Setup
###############################################################################
setup:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
outputs:
matrix: ${{ steps.resolve-metadata.outputs.matrix }}
count: ${{ steps.resolve-metadata.outputs.count }}
assessment-year: ${{ steps.resolve-metadata.outputs.assessment-year }}
run-id: ${{ steps.resolve-metadata.outputs.run-id }}
triad: ${{ steps.resolve-metadata.outputs.triad }}
bucket: ${{ steps.resolve-aws.outputs.bucket }}
distribution-id: ${{ steps.resolve-aws.outputs.distribution-id }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Mask sensitive information
run: echo "::add-mask::${{ secrets.AWS_ACCOUNT_ID }}"
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: scripts/generate_homeval/uv.lock
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: scripts/generate_homeval/.python-version
- name: Install Python requirements
run: uv pip install .
working-directory: scripts/generate_homeval
- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_IAM_ROLE_TO_ASSUME_ARN }}
aws-region: us-east-1
- name: Resolve model metadata
id: resolve-metadata
run: |
# Parse PIN and township lists to array so we can safely pass them
# into this script, which accepts multiple space-delimited values for
# both arguments
read -ra PINS <<< "${{ inputs.pins }}"
read -ra TOWNSHIPS <<< "${{ inputs.townships }}"
ELIG_FLAG=""
if [ "${{ inputs.eligible-only }}" = "true" ]; then
ELIG_FLAG="--eligible-only"
fi
python3 scripts/generate_homeval/resolve_model_metadata.py \
--year "${{ inputs.year }}" \
--run-id "${{ inputs.run_id }}" \
--pin "${PINS[@]}" \
--township "${TOWNSHIPS[@]}" \
--write-github-output \
$ELIG_FLAG
- name: Resolve AWS resources
id: resolve-aws
run: |
if [[ "${{ inputs.environment }}" == 'Development bucket' ]]; then
BUCKET="${{ vars.AWS_S3_BUCKET_PINVAL_STAGING }}"
DISTRIBUTION_ID="${{ vars.AWS_CLOUDFRONT_DISTRIBUTION_ID_STAGING }}"
else
BUCKET="${{ vars.AWS_S3_BUCKET_PINVAL_PROD }}"
DISTRIBUTION_ID="${{ vars.AWS_CLOUDFRONT_DISTRIBUTION_ID_PROD }}"
fi
BUCKET_STR="bucket=${BUCKET}"
echo "$BUCKET_STR"
echo "$BUCKET_STR" >> "$GITHUB_OUTPUT"
DISTRIBUTION_ID_STR="distribution-id=${DISTRIBUTION_ID}"
echo "$DISTRIBUTION_ID_STR"
echo "$DISTRIBUTION_ID_STR" >> "$GITHUB_OUTPUT"
###############################################################################
# Generate HomeVal reports for a triad or explicit PINs
###############################################################################
generate-homeval:
needs: setup
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
max-parallel: ${{ fromJson(needs.setup.outputs.count) }}
env:
TOWNSHIP: ${{ matrix.township }}
permissions:
id-token: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Mask sensitive information
run: echo "::add-mask::${{ secrets.AWS_ACCOUNT_ID }}"
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: scripts/generate_homeval/uv.lock
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: scripts/generate_homeval/.python-version
- name: Install Python requirements
run: uv pip install .
working-directory: scripts/generate_homeval
- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_IAM_ROLE_TO_ASSUME_ARN }}
aws-region: us-east-1
role-duration-seconds: 7200
- name: Cache Hugo package
id: cache-hugo
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/hugo.deb
key: hugo-deb-${{ env.HUGO_VERSION }}
- name: Download Hugo
if: steps.cache-hugo.outputs.cache-hit != 'true'
run: |
wget -O ${{ runner.temp }}/hugo.deb \
https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb
- name: Install Hugo
run: sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Generate Hugo content files and build reports
env:
RUN_ID: ${{ needs.setup.outputs.run-id }}
ENV_CODE: ${{ inputs.environment == 'Production bucket' && 'prod' || 'dev' }}
run: |
read -ra PINS <<< "${{ inputs.pins }}"
NBHD_FLAG=""
if [ "${{ inputs.hugo-build-by-nbhd }}" = "true" ]; then
NBHD_FLAG="--build-by-neighborhood"
fi
ELIG_FLAG=""
if [ "${{ inputs.eligible-only }}" = "true" ]; then
ELIG_FLAG="--eligible-only"
fi
# Unquoted neighborhood flag is intentional in this call, since we
# want this to expand to nothing (rather than an empty string) if
# the variable is empty
python3 scripts/generate_homeval/generate_homeval.py \
--run-id "$RUN_ID" \
--township "$TOWNSHIP" \
--pin "${PINS[@]}" \
--environment "$ENV_CODE" \
$NBHD_FLAG \
$ELIG_FLAG
- name: Sync reports to S3
env:
TARGET_BUCKET: ${{ needs.setup.outputs.bucket }}
YEAR: ${{ needs.setup.outputs.assessment-year }}
run: |
LOCAL="hugo/public"
REMOTE="${TARGET_BUCKET%/}"
if [[ "${{ inputs.deploy-assets }}" == 'true' ]]; then
echo "Deploying static assets in addition to reports"
else
echo "Skipping static assets and deploying reports only"
LOCAL="${LOCAL}/${YEAR}"
REMOTE="${REMOTE}/${YEAR}"
fi
aws s3 sync "${LOCAL}/" "${REMOTE}/" --no-progress
###############################################################################
# Invalidate cache and notify
###############################################################################
notify:
needs:
- setup
- generate-homeval
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_IAM_ROLE_TO_ASSUME_ARN }}
aws-region: us-east-1
- name: Mask AWS identifiers
run: |
echo "::add-mask::${{ secrets.AWS_ACCOUNT_ID }}"
echo "::add-mask::${{ secrets.AWS_SNS_NOTIFICATION_TOPIC_ARN }}"
- name: Invalidate cache
env:
YEAR: ${{ needs.setup.outputs.assessment-year }}
TARGET_DISTRIBUTION_ID: ${{ needs.setup.outputs.distribution-id }}
run: |
# If the user passed in PINs, we want to only invalidate the cache
# for those PINs, and preserve the cache for everything else to
# improve performance for unrelated reports
read -ra PINS <<< "${{ inputs.pins }}"
INVALIDATION_PATHS=()
if (( ${#PINS[@]} > 0 )); then
for pin in "${PINS[@]:-}"; do
INVALIDATION_PATHS+=("/${YEAR}/${pin}.html")
done
else
# If the user didn't pass in PINs, we must have updated the whole
# tri, so invalidate everything in this year
INVALIDATION_PATHS+=("/${YEAR}/*.html")
fi
# If the user is deploying static assets, also invalidate those
# assets
if [[ "${{ inputs.deploy-assets }}" == 'true' ]]; then
# This pattern will exclude robots.txt, since that file must live at
# the root, but this is fine since we rarely if ever expect that file
# to change
INVALIDATION_PATHS+=("/static/*")
fi
aws cloudfront create-invalidation \
--distribution-id "${TARGET_DISTRIBUTION_ID}" \
--paths "${INVALIDATION_PATHS[@]}"
- name: Publish SNS notification
env:
RUN_ID: ${{ needs.setup.outputs.run-id }}
YEAR: ${{ needs.setup.outputs.assessment-year }}
TRIAD: ${{ needs.setup.outputs.triad }}
ENV_LABEL: ${{ inputs.environment }}
BUCKET: ${{ needs.setup.outputs.bucket }}
run: |
read -ra PINS <<< "${{ inputs.pins }}"
SUBJECT="HomeVal reports ready for run-id $RUN_ID"
MESSAGE=$(cat <<EOF
Your requested HomeVal reports have been generated.
Assessment year: $YEAR
Run-ID: $RUN_ID
Triad: $TRIAD
PIN list: ${PINS[@]}
Environment: $ENV_LABEL
You can browse or download the reports at the following S3 path:
$BUCKET/$YEAR/
EOF
)
aws sns publish \
--topic-arn "${{ secrets.AWS_SNS_NOTIFICATION_TOPIC_ARN }}" \
--subject "$SUBJECT" \
--message "$MESSAGE"