Repository navigation
Expand file tree
/
Copy pathsetup-github-actions.sh
More file actions
executable file
·215 lines (186 loc) · 6.78 KB
/
Copy pathsetup-github-actions.sh
File metadata and controls
executable file
·215 lines (186 loc) · 6.78 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/bash
# setup-github-actions.sh
# Quick setup script for GitHub Actions
set -e
echo "🚀 GitHub Actions Setup for trading-web2"
echo "========================================"
echo ""
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
# Check if we're in the right directory
if [ ! -f "package.json" ]; then
echo -e "${RED}❌ Error: package.json not found${NC}"
echo "Please run this script from the root of your trading-web2 directory"
exit 1
fi
if [ ! -f "auto-capture.sh" ]; then
echo -e "${RED}❌ Error: auto-capture.sh not found${NC}"
echo "Please ensure auto-capture.sh exists in your project root"
exit 1
fi
echo -e "${BLUE}Step 1: Creating .github/workflows directory${NC}"
mkdir -p .github/workflows
echo -e "${BLUE}Step 2: Creating workflow file${NC}"
cat > .github/workflows/market-data-capture.yml << 'EOF'
# This file was auto-generated by setup-github-actions.sh
# You can customize it as needed
name: Market Data Auto-Capture
on:
schedule:
# Every minute during market hours (9:15 AM - 3:30 PM IST = 3:45 AM - 10:00 AM UTC)
- cron: '*/1 3-10 * * 1-5'
workflow_dispatch:
inputs:
capture_type:
description: 'Type of capture'
required: false
type: choice
default: 'all'
options:
- all
- market-data
- option-chain
- stock-snapshots
- breakouts
- pcr
- eod
env:
VERCEL_URL: ${{ secrets.VERCEL_URL || 'https://trading-web2.vercel.app' }}
jobs:
trigger-captures:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Determine tasks to run
id: tasks
run: |
MINUTE=$(date +%M)
HOUR=$(date +%H)
CAPTURE_TYPE="${{ github.event.inputs.capture_type || 'all' }}"
# Market data: every minute
if [ "$CAPTURE_TYPE" = "all" ] || [ "$CAPTURE_TYPE" = "market-data" ]; then
echo "run_market=true" >> $GITHUB_OUTPUT
fi
# OI data: every 3 minutes
if [ $((MINUTE % 3)) -eq 0 ]; then
if [ "$CAPTURE_TYPE" = "all" ] || [ "$CAPTURE_TYPE" = "option-chain" ]; then
echo "run_oi=true" >> $GITHUB_OUTPUT
fi
fi
# Stock snapshots: every 3 minutes
if [ $((MINUTE % 3)) -eq 0 ]; then
if [ "$CAPTURE_TYPE" = "all" ] || [ "$CAPTURE_TYPE" = "stock-snapshots" ]; then
echo "run_snapshots=true" >> $GITHUB_OUTPUT
fi
fi
# Breakout snapshots: every 3 minutes
if [ $((MINUTE % 3)) -eq 0 ]; then
if [ "$CAPTURE_TYPE" = "all" ] || [ "$CAPTURE_TYPE" = "breakouts" ]; then
echo "run_breakouts=true" >> $GITHUB_OUTPUT
fi
fi
# PCR: every minute
if [ "$CAPTURE_TYPE" = "all" ] || [ "$CAPTURE_TYPE" = "pcr" ]; then
echo "run_pcr=true" >> $GITHUB_OUTPUT
fi
- name: 📊 Capture market data
if: steps.tasks.outputs.run_market == 'true'
run: |
curl -X GET "${{ env.VERCEL_URL }}/api/cron/capture-market-data" \
-H "Authorization: Bearer ${{ secrets.CRON_SECRET }}" \
--max-time 30 \
--retry 2 \
-f -v
- name: 📈 Capture option chain OI
if: steps.tasks.outputs.run_oi == 'true'
continue-on-error: true
run: |
curl -X GET "${{ env.VERCEL_URL }}/api/option-chain/cron" \
-H "Authorization: Bearer ${{ secrets.CRON_SECRET }}" \
--max-time 30 \
-f -v
- name: 📸 Update stock snapshots
if: steps.tasks.outputs.run_snapshots == 'true'
continue-on-error: true
run: |
curl -X GET "${{ env.VERCEL_URL }}/api/cron/update-stock-snapshots" \
-H "Authorization: Bearer ${{ secrets.CRON_SECRET }}" \
--max-time 30 \
-f -v
- name: 🎯 Update breakout snapshots
if: steps.tasks.outputs.run_breakouts == 'true'
continue-on-error: true
run: |
curl -X GET "${{ env.VERCEL_URL }}/api/cron/update-breakout-snapshots" \
-H "Authorization: Bearer ${{ secrets.CRON_SECRET }}" \
--max-time 30 \
-f -v
- name: �� Calculate PCR
if: steps.tasks.outputs.run_pcr == 'true'
continue-on-error: true
run: |
curl -X GET "${{ env.VERCEL_URL }}/api/cron/calculate-pcr" \
-H "Authorization: Bearer ${{ secrets.CRON_SECRET }}" \
--max-time 30 \
-f -v
EOF
echo -e "${GREEN}✅ Workflow file created${NC}"
echo ""
echo -e "${BLUE}Step 3: Checking secrets needed${NC}"
echo ""
echo "You need to configure these secrets in GitHub:"
echo ""
echo "Required secrets:"
echo " • CRON_SECRET - Your cron authentication token"
echo ""
echo "Optional secrets:"
echo " • VERCEL_URL - Your Vercel deployment URL (defaults to trading-web2.vercel.app)"
echo ""
# Check if .env.local exists
if [ -f ".env.local" ]; then
echo -e "${YELLOW}📋 Found .env.local - checking for CRON_SECRET${NC}"
if grep -q "CRON_SECRET" .env.local; then
CRON_SECRET=$(grep CRON_SECRET .env.local | cut -d '=' -f2 | tr -d '"' | tr -d "'")
if [ ! -z "$CRON_SECRET" ]; then
echo -e "${GREEN}✅ CRON_SECRET found in .env.local: ${CRON_SECRET:0:10}...${NC}"
echo ""
echo "Copy this value and add it to GitHub:"
echo -e "${BLUE}https://github.com/kumarasantosh/trading-web2/settings/secrets/actions/new${NC}"
fi
else
echo -e "${YELLOW}⚠️ CRON_SECRET not found in .env.local${NC}"
echo "Make sure to add it to GitHub Secrets"
fi
else
echo -e "${YELLOW}⚠️ .env.local not found${NC}"
fi
echo ""
echo -e "${BLUE}Step 4: Ready to commit${NC}"
echo ""
echo "Run these commands to push to GitHub:"
echo ""
echo -e "${GREEN}git add .github/workflows/market-data-capture.yml${NC}"
echo -e "${GREEN}git commit -m \"Add GitHub Actions workflow for market data capture\"${NC}"
echo -e "${GREEN}git push origin main${NC}"
echo ""
echo -e "${BLUE}Step 5: After pushing${NC}"
echo ""
echo "1. Go to: https://github.com/kumarasantosh/trading-web2/settings/secrets/actions"
echo "2. Add your CRON_SECRET"
echo "3. Go to: https://github.com/kumarasantosh/trading-web2/actions"
echo "4. Enable workflows if needed"
echo "5. Click 'Market Data Auto-Capture' → 'Run workflow' to test"
echo ""
echo -e "${GREEN}✅ Setup complete!${NC}"
echo ""
echo "Next steps:"
echo "1. Review the workflow file: .github/workflows/market-data-capture.yml"
echo "2. Configure GitHub Secrets"
echo "3. Push to GitHub"
echo "4. Test the workflow manually"
echo ""
echo "For detailed instructions, see the deployment guide."