Refresh Data #105
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Automated daily data refresh — HDB + URA | |
| # | |
| # Runs at 03:00 Singapore time (SGT = UTC+8) every day. | |
| # To switch to weekly (Monday 03:00 SGT), change the cron to: '0 19 * * 0' | |
| # | |
| # Required repo secrets (Settings → Secrets and variables → Actions): | |
| # URA_API_ACCESS_KEY — URA API access key (copy from .env) | |
| # FLY_API_TOKEN — Fly ORG token: | |
| # fly tokens create org | |
| # Must be an org token, NOT `fly tokens create deploy` — | |
| # deploy tokens cannot issue the SSH certs that the | |
| # `fly ssh sftp` / `fly ssh console` steps below need. | |
| # (default expiry ~1 year — calendar-remind yourself to renew) | |
| name: Refresh Data | |
| on: | |
| schedule: | |
| - cron: '0 19 * * *' # 19:00 UTC = 03:00 SGT daily | |
| workflow_dispatch: # allow manual trigger from the Actions tab | |
| # Prevent two runs overlapping and corrupting a concurrent DB upload | |
| concurrency: | |
| group: refresh-data | |
| cancel-in-progress: false | |
| jobs: | |
| refresh: | |
| name: Download & Deploy resale.db | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '24' | |
| cache: 'npm' | |
| - name: Install Node dependencies | |
| run: npm ci | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.x' | |
| - name: Install flyctl | |
| uses: superfly/flyctl-actions/setup-flyctl@v1 | |
| - name: Alias flyctl as fly | |
| run: sudo ln -sf $(which flyctl) /usr/local/bin/fly | |
| # ── Build ───────────────────────────────────────────────────────────── | |
| # Runs download_data.py (HDB) then download_ura_data.py (URA). | |
| # Produces server/db/resale.db (~100 MB) on the runner's disk. | |
| - name: Download HDB + URA data | |
| run: npm run download | |
| env: | |
| URA_API_ACCESS_KEY: ${{ secrets.URA_API_ACCESS_KEY }} | |
| # ── Deploy ──────────────────────────────────────────────────────────── | |
| # WAL-checkpoints, SFTPs the DB to Fly volume, swaps it in, restarts. | |
| # Matches the existing manual: npm run deploy:data | |
| - name: Deploy resale.db to Fly | |
| run: npm run deploy:data | |
| env: | |
| FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} |