Skip to content

Scrape Epic Games and Deploy to GitHub Pages #547

Scrape Epic Games and Deploy to GitHub Pages

Scrape Epic Games and Deploy to GitHub Pages #547

name: Scrape Epic Games and Deploy to GitHub Pages
on:
schedule:
# 4pm UK daily - GitHub Actions uses UTC. Run at both times so it's correct
# when UK switches clocks: 15:00 UTC = 4pm BST (summer), 16:00 UTC = 4pm GMT (winter)
- cron: '0 15 * * *'
- cron: '0 16 * * *'
workflow_dispatch:
push:
branches: [main]
permissions:
contents: write
pages: write
id-token: write
# Cancel in-progress runs when a new one starts (saves free-tier minutes)
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
# Lightweight check: fetch API and compare hash. Skip full scrape when unchanged.
check-api:
runs-on: ubuntu-22.04
outputs:
api_unchanged: ${{ steps.check.outputs.api_unchanged }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Check if API response changed
id: check
run: |
API_URL="https://store-site-backend-static-ipv4.ak.epicgames.com/freeGamesPromotions?locale=en-GB&country=GB&allowCountries=GB"
current_hash=$(curl -sL "$API_URL" | python3 -c "
import json, sys, hashlib
data = json.load(sys.stdin)
print(hashlib.sha256(json.dumps(data, sort_keys=True).encode()).hexdigest())
")
prev_hash=$(cat output/.api_hash 2>/dev/null || echo "")
if [ -n "$prev_hash" ] && [ "$current_hash" = "$prev_hash" ]; then
echo "api_unchanged=true" >> $GITHUB_OUTPUT
echo "✓ API unchanged - skipping scrape"
else
echo "api_unchanged=false" >> $GITHUB_OUTPUT
echo "API changed - running full scrape"
fi
- if: always()
run: |
echo "### 🎮 Epic Games Scraper" >> $GITHUB_STEP_SUMMARY
echo "- **API unchanged**: ${{ steps.check.outputs.api_unchanged == 'true' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Skipped scrape**: ${{ steps.check.outputs.api_unchanged == 'true' }}" >> $GITHUB_STEP_SUMMARY
scrape-and-build:
needs: check-api
if: needs.check-api.outputs.api_unchanged != 'true'
runs-on: ubuntu-22.04
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Scrape
id: scrape
run: |
pip install -q -r requirements.txt
python3 scrape_epic_games.py
- name: Check changes
id: changes
run: |
# Only build/deploy when db or images changed - skip if only .api_hash changed
if git diff --quiet output/epic_games.db output/images/ 2>/dev/null; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Build and commit
if: steps.changes.outputs.changed == 'true'
run: |
python3 generate_website.py
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add output/epic_games.db output/images/ output/.api_hash
git diff --staged --quiet || (git commit -m "Update database and images - $(date -u +"%Y-%m-%d %H:%M UTC")" && git push)
- name: Commit .api_hash only (when no db/images changes)
if: steps.changes.outputs.changed == 'false'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add output/.api_hash
git diff --staged --quiet || (git commit -m "Update API hash - $(date -u +"%Y-%m-%d %H:%M UTC")" && git push)
- if: steps.changes.outputs.changed == 'true'
uses: actions/configure-pages@v4
- if: steps.changes.outputs.changed == 'true'
uses: actions/upload-pages-artifact@v3
with:
path: './website'
- if: steps.changes.outputs.changed == 'true'
uses: actions/deploy-pages@v4
- if: always()
run: |
echo "### 🎮 Epic Games Scraper" >> $GITHUB_STEP_SUMMARY
echo "- **Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY
echo "- **Deployed**: ${{ steps.changes.outputs.changed == 'true' }}" >> $GITHUB_STEP_SUMMARY