-
Notifications
You must be signed in to change notification settings - Fork 0
141 lines (110 loc) · 4.59 KB
/
submit-rsv-forecasts.yaml
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
140
141
name: Make RSV Forecast Submission
on:
schedule:
# Every Tuesday at 6pm CET (17:00 UTC)
- cron: '0 17 * * 2'
workflow_dispatch: # Allow manual triggering
jobs:
submit-forecast:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests pandas numpy
- name: Create required directories
run: |
mkdir -p rsv/submissions
mkdir -p rsv/submissions-diagnostics
- name: Run rsv forecasting script
run: python rsv/run-rsv-forecasts.py
env:
PYTHONPATH: ${{ github.workspace }}
- name: Commit forecasts to repository
run: |
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Add all generated files before pulling
git add rsv/submissions/ rsv/submissions-diagnostics/
# Stash any changes if they exist
git stash || true
# Pull latest changes
git pull origin main --rebase
# Pop stashed changes if they exist
git stash pop || true
# Add all generated files again
git add rsv/submissions/ rsv/submissions-diagnostics/
# Only commit if there are changes
if git diff --staged --quiet; then
echo "No new forecasts to commit"
else
git commit -m "Store rsv forecasts $(date +%Y-%m-%d)"
# Try to push, if it fails due to conflicts, pull and push again
git push || (git pull --rebase origin main && git push)
fi
- name: Fork and sync target repository
run: |
# Install GitHub CLI
gh auth login --with-token <<< "${{ secrets.PRIVATE_ACCESS_TOKEN }}"
# Fork the repository (if not already forked)
gh repo fork HopkinsIDD/rsv-forecast-hub --clone=true || true
# Sync the fork with upstream
pushd rsv-forecast-hub
# Add upstream remote if it doesn't exist
git remote add upstream https://github.com/HopkinsIDD/rsv-forecast-hub.git 2>/dev/null || true
# Set the origin remote with authentication token
git remote set-url origin "https://x-access-token:${{ secrets.PRIVATE_ACCESS_TOKEN }}@github.com/${{ github.actor }}/rsv-forecast-hub.git"
# Fetch and sync with upstream
git fetch upstream
git checkout main
git reset --hard upstream/main
git push origin main --force
popd
- name: Copy forecast files
run: |
# Create target directory if it doesn't exist
mkdir -p rsv-forecast-hub/model-output/Metaculus-cp
# Copy new forecasts
cp -r rsv/submissions/* rsv-forecast-hub/model-output/Metaculus-cp/
- name: Create Pull Request
run: |
cd rsv-forecast-hub
# Setup git config
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create a new branch with timestamp to ensure uniqueness
BRANCH_NAME="rsv-forecast-update-$(date +%Y%m%d-%H%M%S)"
git checkout -b $BRANCH_NAME
# Add and commit changes
git add model-output/Metaculus-cp/
# Only commit if there are changes
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
else
git commit -m "Update rsv forecasts $(date +%Y-%m-%d)"
# Set the remote URL with authentication token
git remote set-url origin "https://x-access-token:${{ secrets.PRIVATE_ACCESS_TOKEN }}@github.com/${{ github.actor }}/rsv-forecast-hub.git"
# Force push to fork with the new unique branch
git push -f origin $BRANCH_NAME
# Create PR using gh cli
gh pr create \
--title "Submission Metaculus forecasts $(date +%Y-%m-%d)" \
--body "Automated rsv forecast submission from Metaculus" \
--repo HopkinsIDD/rsv-forecast-hub \
--base main \
--head "${{ github.actor }}:$BRANCH_NAME"
fi
env:
GITHUB_TOKEN: ${{ secrets.PRIVATE_ACCESS_TOKEN }}
GH_TOKEN: ${{ secrets.PRIVATE_ACCESS_TOKEN }}