# AI Radar — runs radar.mjs every morning on GitHub's free servers.
# Change the time: edit the cron line (it's in UTC). "0 7 * * *" = 07:00 UTC every day.
# Run it now: GitHub → Actions → "AI Radar" → "Run workflow".
name: AI Radar

on:
  schedule:
    - cron: "0 7 * * *"
  workflow_dispatch: {}

permissions:
  contents: write # lets the job save digests/ and state/seen.json back to your repo

concurrency:
  group: ai-radar
  cancel-in-progress: false

jobs:
  radar:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v7

      - uses: actions/setup-node@v7
        with:
          node-version: 22

      - name: Scan, score and send the digest
        run: node radar.mjs
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
          TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
          RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}
          EMAIL_TO: ${{ secrets.EMAIL_TO }}
          EMAIL_FROM: ${{ secrets.EMAIL_FROM }}

      - name: Save digest + memory to the repo
        if: always()
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
          mkdir -p digests state
          git add digests state
          git diff --staged --quiet || (git commit -m "radar: digest $(date -u +%F)" && git push)
