Skip to content

Compute Course Stats #204

Compute Course Stats

Compute Course Stats #204

name: Compute Course Stats
on:
# Run twice daily at 6am and 6pm UTC
schedule:
- cron: '0 6,18 * * *'
# Allow manual trigger
workflow_dispatch:
jobs:
compute-stats:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: |
npm install -g tsx
npm install @supabase/supabase-js
- name: Compute course stats
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_SERVICE_KEY: ${{ secrets.SUPABASE_SERVICE_KEY }}
run: npx tsx scripts/compute-course-stats.ts
- name: Compute global stats
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_SERVICE_KEY: ${{ secrets.SUPABASE_SERVICE_KEY }}
run: npx tsx scripts/compute-global-stats.ts
- name: Commit and push if changed
run: |
git config user.name 'Christian Tran'
git config user.email 'ctran4347@gmail.com'
git add static/course-stats.json static/global-stats.json
if git diff --staged --quiet; then
echo "No changes to commit"
else
TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%SZ)
git commit -m "Update course stats $TIMESTAMP"
git push
fi