-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (103 loc) · 3.46 KB
/
Copy pathscrape-and-deploy.yml
File metadata and controls
128 lines (103 loc) · 3.46 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
name: Scrape Prices and Deploy
on:
# Run daily at midnight UTC
schedule:
- cron: '0 0 * * *'
# Allow manual trigger for testing
workflow_dispatch:
permissions:
contents: write
pages: write
id-token: write
jobs:
scrape-and-build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Install Chromium for Puppeteer
run: |
npx puppeteer browsers install chrome
- name: Run all scrapers
run: |
node scrapers/run-all.js
continue-on-error: true
env:
# Run in CI mode (headless, no sandbox)
CI: true
- name: Check scraper results
id: scraper-status
run: |
if [ -d "data" ] && [ "$(ls -A data)" ]; then
echo "scrapers_succeeded=true" >> $GITHUB_OUTPUT
echo "✓ Scrapers completed successfully"
else
echo "scrapers_succeeded=false" >> $GITHUB_OUTPUT
echo "⚠️ No scraper data found"
fi
- name: Commit scraper data
if: steps.scraper-status.outputs.scrapers_succeeded == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Add only data directory changes
git add data/
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "No new data to commit"
exit 0
fi
DATE=$(date +%Y-%m-%d)
SOURCE_COUNT=$(find data -name "*.json" | wc -l | tr -d ' ')
git commit -m "chore: update prices for $DATE ($SOURCE_COUNT sources)" -m "Generated with GitHub Actions"
# Try to push, handle concurrent commits
if git push; then
echo "✓ Push succeeded"
else
echo "⚠️ Push failed, attempting to recover..."
# Stash our commit temporarily
git reset --soft HEAD~1
git stash
# Pull latest changes
git pull --rebase
# Try to restore our changes
if git stash pop; then
echo "✓ Stash applied successfully, retrying commit..."
# Re-add and commit
git add data/
if git diff --staged --quiet; then
echo "No new data after merge (likely already committed)"
exit 0
fi
SOURCE_COUNT=$(find data -name "*.json" | wc -l | tr -d ' ')
git commit -m "chore: update prices for $DATE ($SOURCE_COUNT sources)" -m "Generated with GitHub Actions"
git push
else
echo "✗ Conflict detected - scrape data for this day may already exist"
git stash drop || true
exit 1
fi
fi
- name: Build frontend
run: npm run build
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: dist
deploy:
needs: scrape-and-build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4