name: Generate daily quizzes # Run daily and allow manual runs on: schedule: # Runs daily at 01:00 UTC (adjust cron if you want a different time) - cron: '0 1 * * *' workflow_dispatch: {} permissions: contents: write # required so the workflow can push changes back jobs: generate: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 with: # allow push using the provided GITHUB_TOKEN persist-credentials: true fetch-depth: 0 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' cache: 'npm' - name: Install dependencies run: | npm ci - name: Run quiz generator # run the combined project generator script; adjust path if you use a different file name run: | node mathematicsnerd_combined_project.js generate --force=false - name: Show diff (debug) run: | git --no-pager status --porcelain git --no-pager diff --name-only || true - name: Commit and push generated quizzes if changed # Only commit if public/quizzes.json changed run: | # configure git user git config user.name "github-actions[bot]" git config user.email "actions@github.com" # Check if file changed if git status --porcelain | grep -q "public/quizzes.json"; then git add public/quizzes.json git commit -m "chore: daily quizzes: $(date -u +'%Y-%m-%d')" git push echo "Committed and pushed updated public/quizzes.json" else echo "No changes to public/quizzes.json — nothing to commit" fi