Forecast • 20260223-191840-pst-my-forecast-run #50
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
| name: Forecast Request | |
| run-name: Forecast • ${{ inputs.slug }} | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| slug: | |
| description: "Output slug for forecast page" | |
| required: true | |
| use_m5: | |
| description: "Use Nixtla datasetsforecast M5 sample" | |
| required: false | |
| default: false | |
| type: boolean | |
| m5_series_count: | |
| description: "How many M5 series to sample (small for cost/speed)" | |
| required: false | |
| default: "3" | |
| payload: | |
| description: "Forecast request JSON (ignored for series values when use_m5=true)" | |
| required: false | |
| default: "{}" | |
| backtest_windows: | |
| description: "Rolling backtest windows" | |
| required: false | |
| default: "3" | |
| permissions: | |
| contents: write | |
| deployments: write | |
| jobs: | |
| forecast: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install package | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install . | |
| - name: Generate forecast artifacts | |
| run: | | |
| python scripts/run_forecast.py \ | |
| --slug "${{ inputs.slug }}" \ | |
| --payload '${{ inputs.payload }}' \ | |
| --repo "${{ github.repository }}" \ | |
| --run-id "${{ github.run_id }}" \ | |
| --actor "${{ github.actor }}" \ | |
| --sha "${{ github.sha }}" \ | |
| ${{ inputs.use_m5 && '--use-m5' || '' }} \ | |
| --m5-series-count "${{ inputs.m5_series_count }}" \ | |
| --backtest-windows "${{ inputs.backtest_windows }}" | |
| - name: Commit output (retry-safe for concurrent runs) | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add site/src/data/forecasts | |
| git commit -m "Add forecast ${{ inputs.slug }}" || echo "No changes" | |
| # Concurrent workflow runs can race on push. Retry with rebase. | |
| for i in 1 2 3 4 5; do | |
| echo "Push attempt $i..." | |
| git fetch origin main | |
| git rebase origin/main || { git rebase --abort; } | |
| if git push origin HEAD:main; then | |
| echo "Push succeeded on attempt $i" | |
| break | |
| fi | |
| if [ "$i" -eq 5 ]; then | |
| echo "Push failed after 5 attempts" | |
| exit 1 | |
| fi | |
| sleep $((RANDOM % 5 + 2)) | |
| done | |
| - name: Setup Node for site build | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| cache-dependency-path: site/package-lock.json | |
| - name: Build Astro site | |
| working-directory: site | |
| run: | | |
| npm ci | |
| npm run build | |
| - name: Deploy to Cloudflare Pages | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| workingDirectory: site | |
| command: pages deploy dist --project-name forecastingapi --branch main |