forked from sebthedev/PrincetonCourses
-
Notifications
You must be signed in to change notification settings - Fork 3
321 lines (313 loc) · 10.9 KB
/
imports.yml
File metadata and controls
321 lines (313 loc) · 10.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
name: PrincetonCourses Imports
on:
workflow_dispatch:
inputs:
run_import_courses:
description: "Run course import (OIT + registrar details)"
type: boolean
default: true
run_import_departments:
description: "Run departments import (OIT)"
type: boolean
default: true
run_import_evals:
description: "Run evaluations scraper (requires PHPSESSID)"
type: boolean
default: true
run_backfill:
description: "Run backfill for missing Quality of Course"
type: boolean
default: false
run_setnew:
description: "Run setNewCourseFlag"
type: boolean
default: false
restart_heroku:
description: "Restart Heroku dynos at end (refresh dept cache)"
type: boolean
default: false
term:
description: "Target term code (e.g., 1252)"
type: string
required: false
subject:
description: "Target subject code (e.g., COS). Leave blank for all"
type: string
required: false
php_sessid:
description: "Registrar PHPSESSID cookie (required for evals)"
type: string
required: false
registrar_fe_api_token:
description: "Registrar FE API token (paste per run; overrides scrape)"
type: string
required: false
concurrency:
group: imports-${{ github.ref }}
cancel-in-progress: false
jobs:
import_courses:
if: ${{ inputs.run_import_courses }}
runs-on: ubuntu-latest
timeout-minutes: 180
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Python deps
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
- name: Install Node deps
run: npm ci
- name: Load Heroku config vars
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
run: |
echo "::add-mask::${HEROKU_API_KEY}"
cfg=$(curl -sS \
-H "Authorization: Bearer ${HEROKU_API_KEY}" \
-H "Accept: application/vnd.heroku+json; version=3" \
https://api.heroku.com/apps/${HEROKU_APP_NAME}/config-vars)
echo "$cfg" > heroku_config.json
for key in MONGODB_URI CONSUMER_KEY CONSUMER_SECRET CHATBOT_API_KEY HOST PORT; do
val=$(node -e "const o=require('./heroku_config.json'); const k='${key}'; if (o[k]) console.log(o[k]);")
if [ -n "$val" ]; then
echo "::add-mask::${val}"
echo "$key=$val" >> $GITHUB_ENV
fi
done
- name: Build query arg
id: q
run: |
q=""
if [ -n "${{ inputs.term }}" ] && [ -n "${{ inputs.subject }}" ]; then
q="term=${{ inputs.term }}&subject=${{ inputs.subject }}"
elif [ -n "${{ inputs.term }}" ]; then
q="term=${{ inputs.term }}&subject=all"
fi
echo "query=${q}" >> $GITHUB_OUTPUT
- name: Run course importer
env:
REGISTRAR_FE_API_TOKEN: ${{ inputs.registrar_fe_api_token }}
run: |
if [ -n "${{ inputs.registrar_fe_api_token }}" ]; then echo "::add-mask::${{ inputs.registrar_fe_api_token }}"; fi
if [ -n "${{ steps.q.outputs.query }}" ]; then
node importers/importBasicCourseDetails.js "${{ steps.q.outputs.query }}"
else
node importers/importBasicCourseDetails.js
fi
import_departments:
if: ${{ inputs.run_import_departments }}
needs: [import_courses]
runs-on: ubuntu-latest
timeout-minutes: 60
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Python deps
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
- name: Install Node deps
run: npm ci
- name: Load Heroku config vars
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
run: |
echo "::add-mask::${HEROKU_API_KEY}"
cfg=$(curl -sS \
-H "Authorization: Bearer ${HEROKU_API_KEY}" \
-H "Accept: application/vnd.heroku+json; version=3" \
https://api.heroku.com/apps/${HEROKU_APP_NAME}/config-vars)
echo "$cfg" > heroku_config.json
for key in MONGODB_URI CONSUMER_KEY CONSUMER_SECRET; do
val=$(node -e "const o=require('./heroku_config.json'); const k='${key}'; if (o[k]) console.log(o[k]);")
if [ -n "$val" ]; then
echo "::add-mask::${val}"
echo "$key=$val" >> $GITHUB_ENV
fi
done
- name: Run departments importer
run: node importers/importDepartments.js
scrape_evals:
if: ${{ inputs.run_import_evals }}
needs: [import_courses]
runs-on: ubuntu-latest
timeout-minutes: 240
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Python deps
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
- name: Install Node deps
run: npm ci
- name: Load Heroku config vars
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
run: |
echo "::add-mask::${HEROKU_API_KEY}"
cfg=$(curl -sS \
-H "Authorization: Bearer ${HEROKU_API_KEY}" \
-H "Accept: application/vnd.heroku+json; version=3" \
https://api.heroku.com/apps/${HEROKU_APP_NAME}/config-vars)
echo "$cfg" > heroku_config.json
for key in MONGODB_URI; do
val=$(node -e "const o=require('./heroku_config.json'); const k='${key}'; if (o[k]) console.log(o[k]);")
if [ -n "$val" ]; then
echo "::add-mask::${val}"
echo "$key=$val" >> $GITHUB_ENV
fi
done
- name: Run evaluation scraper (non-interactive)
env:
EVAL_SCRAPE_DELAY_MS: "600"
EVAL_SCRAPE_MAX_RETRIES: "3"
EVAL_SCRAPE_RETRY_BACKOFF_MS: "1000"
EVAL_RANDOMIZE_ORDER: "true"
INPUT_TERM: ${{ inputs.term }}
INPUT_SUBJECT: ${{ inputs.subject }}
PHPSESSID: ${{ inputs.php_sessid }}
run: |
if [ -z "${PHPSESSID}" ]; then
echo "php_sessid input is required to run evaluations" >&2
exit 1
fi
echo "::add-mask::${PHPSESSID}"
export EVAL_QUERY=$(node -e '
const term = process.env.INPUT_TERM;
const subj = process.env.INPUT_SUBJECT;
const q = { "scores.Quality of Course": { "$exists": false } };
if (term) q.semester = Number(term);
if (subj) q.department = String(subj).toUpperCase();
console.log(JSON.stringify(q));
')
node importers/scrapeEvaluations.js --skip
backfill_scores:
if: ${{ inputs.run_backfill }}
needs: [scrape_evals]
runs-on: ubuntu-latest
timeout-minutes: 60
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install Node deps
run: npm ci
- name: Load Heroku config vars
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
run: |
echo "::add-mask::${HEROKU_API_KEY}"
cfg=$(curl -sS \
-H "Authorization: Bearer ${HEROKU_API_KEY}" \
-H "Accept: application/vnd.heroku+json; version=3" \
https://api.heroku.com/apps/${HEROKU_APP_NAME}/config-vars)
echo "$cfg" > heroku_config.json
val=$(node -e "const o=require('./heroku_config.json'); const k='MONGODB_URI'; if (o[k]) console.log(o[k]);")
if [ -n "$val" ]; then
echo "::add-mask::${val}"
echo "MONGODB_URI=$val" >> $GITHUB_ENV
fi
- name: Run backfill
run: |
if [ -n "${{ inputs.term }}" ]; then
node importers/insertMostRecentScoreIntoUnevaluatedSemesters.js "${{ inputs.term }}"
else
node importers/insertMostRecentScoreIntoUnevaluatedSemesters.js
fi
set_new_flag:
if: ${{ inputs.run_setnew }}
needs: [scrape_evals]
runs-on: ubuntu-latest
timeout-minutes: 30
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install Node deps
run: npm ci
- name: Load Heroku config vars
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
run: |
echo "::add-mask::${HEROKU_API_KEY}"
cfg=$(curl -sS \
-H "Authorization: Bearer ${HEROKU_API_KEY}" \
-H "Accept: application/vnd.heroku+json; version=3" \
https://api.heroku.com/apps/${HEROKU_APP_NAME}/config-vars)
echo "$cfg" > heroku_config.json
val=$(node -e "const o=require('./heroku_config.json'); const k='MONGODB_URI'; if (o[k]) console.log(o[k]);")
if [ -n "$val" ]; then
echo "::add-mask::${val}"
echo "MONGODB_URI=$val" >> $GITHUB_ENV
fi
- name: Run setNewCourseFlag
run: node importers/setNewCourseFlag.js
restart_heroku:
if: ${{ inputs.restart_heroku && always() }}
needs: [import_departments]
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Restart Heroku dynos
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
run: |
echo "::add-mask::${HEROKU_API_KEY}"
curl -sS -X DELETE \
-H "Accept: application/vnd.heroku+json; version=3" \
-H "Authorization: Bearer ${HEROKU_API_KEY}" \
"https://api.heroku.com/apps/${HEROKU_APP_NAME}/dynos"