name: JobSpy Scraper Workflow

on:
  workflow_dispatch:  # Allows manual trigger from GitHub or Power Automate
  # Remove or comment out the schedule to prevent auto-runs
  # schedule:
  #   - cron: '0 */6 * * *'  # Runs every 6 hours (DISABLED)

permissions:
  actions: read
  contents: read
  id-token: write

jobs:
  scrape_jobs:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.10'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt

      - name: Run JobSpy Scraper
        run: python job_scraper_exact_match.py

      - name: Debug - Check if jobspy_output.csv exists
        run: |
          if [ ! -f jobspy_output.csv ]; then
            echo "❌ ERROR: jobspy_output.csv not found!"
            exit 1
          else
            echo "✅ jobspy_output.csv found, proceeding to upload..."
          fi

      - name: Upload JobSpy Output as Artifact
        uses: actions/upload-artifact@v4  # Explicitly using latest version
        with:
          name: jobspy-results
          path: jobspy_output.csv