name: Dataset Update

on:
  schedule:
    - cron: "0 3 * * *" # every day at 03:00 UTC
  workflow_dispatch:

jobs:
  update-dataset:
    runs-on: ubuntu-latest

    permissions:
      contents: write

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

      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.14"

      - name: Install ossatrisk
        run: pip install ossatrisk

      - name: Run ossatrisk build
        working-directory: src
        run: ossatrisk build-data --ecosystem php

      - name: Commit and push changes
        run: |
          if [[ -n "$(git status --porcelain data/)" ]]; then
            git config user.name "github-actions[bot]"
            git config user.email "github-actions[bot]@users.noreply.github.com"
            git add data/
            git commit -m "dataset update - $(date -u +"%Y-%m-%d %H:%M:%S UTC")"
            git pull --rebase origin main
            git push
          else
            echo "No changes to commit"
          fi
