-
Notifications
You must be signed in to change notification settings - Fork 0
139 lines (124 loc) · 4.16 KB
/
forecast-request.yml
File metadata and controls
139 lines (124 loc) · 4.16 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
name: Forecast Request
run-name: ${{ github.event_name == 'workflow_dispatch' && format('Forecast • {0}', inputs.slug) || format('Deploy • {0}', github.sha) }}
on:
push:
branches:
- main
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:
if: github.event_name == 'workflow_dispatch'
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
deploy:
if: github.event_name == 'push'
runs-on: ubuntu-latest
concurrency:
group: deploy-main
cancel-in-progress: true
steps:
- name: Checkout
uses: actions/checkout@v4
- 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