Skip to content

Process new month #1006

Process new month

Process new month #1006

Workflow file for this run

name: Process new month
on:
workflow_dispatch:
inputs:
args:
description: "Args to pass to `ctbk` (default: auto-detect month and run `update`)"
required: false
workflow_run:
workflows: ["Sync tripdata bucket"]
types: [completed]
branches: [main]
permissions:
contents: write
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
jobs:
process:
runs-on: ubuntu-latest
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
ssh-key: ${{ secrets.WWW_DEPLOY_KEY }}
- name: Detect args
id: args
run: |
if [ -n "${{ inputs.args }}" ]; then
echo "args=${{ inputs.args }}" >> "$GITHUB_OUTPUT"
else
# Auto-detect month from most recent tripdata import commit
ym=$(git log -1 --format=%s | sed -n 's/.*\(20[0-9]\{4\}\)-citibike.*/\1/p' | head -1)
if [ -z "$ym" ]; then
echo "No new month detected in recent commits; nothing to do"
exit 0
fi
if [ -f "s3/ctbk/normalized/${ym}.dvc" ]; then
echo "Month $ym already processed; nothing to do"
exit 0
fi
echo "args=update -S -ccda $ym" >> "$GITHUB_OUTPUT"
fi
- uses: astral-sh/setup-uv@v6
if: steps.args.outputs.args
with:
python-version: '3.12'
enable-cache: true
- name: Sync deps + activate venv
if: steps.args.outputs.args
run: |
uv sync --frozen
echo "$GITHUB_WORKSPACE/.venv/bin" >> "$GITHUB_PATH"
- name: Configure Git
if: steps.args.outputs.args
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email 'ryan-williams@users.noreply.github.com'
- name: Pull tripdata
if: steps.args.outputs.args
run: |
# Pull any tripdata zips needed by the command
ym=$(echo "${{ steps.args.outputs.args }}" | grep -oE '20[0-9]{4}' | head -1)
if [ -n "$ym" ]; then
dvc pull s3/tripdata/*${ym}*.dvc || true
fi
- uses: actions/setup-node@v5
if: steps.args.outputs.args
with:
node-version: 20
- name: Install pnpm
if: steps.args.outputs.args
run: npm install -g pnpm
- name: Install Node dependencies
if: steps.args.outputs.args
run: cd www && pnpm install --frozen-lockfile
- name: Run ctbk
if: steps.args.outputs.args
run: ctbk ${{ steps.args.outputs.args }}
- name: Deploy to www branch
if: steps.args.outputs.args
run: git push origin HEAD:www