Skip to content

Scrape New Races

Scrape New Races #126

Workflow file for this run

name: Scrape New Races
on:
schedule:
- cron: "0 6 * * *" # Daily at 6 AM UTC
workflow_dispatch: # Allow manual trigger
permissions:
contents: write
pull-requests: write
jobs:
scrape:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: 20
- name: Discover new races
run: node scripts/discover-new-races.js
- name: Scrape new races
run: node scripts/scrape-all.js --skip-existing
- name: Check for changes
id: check
run: |
if [ -z "$(git status --porcelain data/ scripts/race-registry.json)" ]; then
echo "No new races found"
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "New races found:"
git status --short data/ scripts/race-registry.json
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
- name: Create pull request
if: steps.check.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH="auto/scrape-$(date +%Y-%m-%d)"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# If the branch already exists, check whether a PR exists too
if git ls-remote --heads origin "$BRANCH" | grep -q .; then
if gh pr view "$BRANCH" > /dev/null 2>&1; then
echo "Branch $BRANCH already exists with a PR, skipping"
exit 0
fi
echo "Branch $BRANCH exists but has no PR, creating one"
else
git checkout -b "$BRANCH"
git add data/ scripts/race-registry.json
git commit -m "feat: add new race results"
git push -u origin "$BRANCH"
fi
# Build PR body
{
echo "## Summary"
echo ""
echo "Automated daily scrape discovered new race results."
echo ""
echo "### New files"
git diff --name-only origin/main..."origin/$BRANCH" -- 'data/*.csv' | while read -r f; do
echo "- \`$f\`"
done
} > /tmp/pr-body.md
gh pr create \
--head "$BRANCH" \
--title "feat: add new race results" \
--body-file /tmp/pr-body.md \
--reviewer rootulp
# Request auto-merge so the PR squash-merges once CI passes,
# instead of piling up as a stale daily backlog.
gh pr merge "$BRANCH" --auto --squash --delete-branch