name: Update files

# GitHub events that trigger the workflow:
on:
  workflow_call: # to make the workflow triggerable from other workflows (publish-a-release.yaml)
  workflow_dispatch: # to make the workflow triggerable manually

jobs:
  update_files:
    name: Update schema.json, examples, and entry figures
    runs-on: ubuntu-latest

    permissions:
      contents: write

    steps:
      - uses: actions/checkout@v6

      - name: Install uv
        uses: astral-sh/setup-uv@v7

      - name: Install just
        uses: taiki-e/install-action@just

      - name: Set Git credentials
        run: |
          git config --local user.email "github-actions[bot]@users.noreply.github.com"
          git config --local user.name "GitHub Actions [Bot]"

      - name: Update schema.json
        run: just update-schema

      - name: Update examples folder
        run: just update-examples

      - name: Update entry figures
        run: just update-entry-figures

      - name: Commit and push changes
        run: |
          git add -A
          if git diff --staged --quiet; then
            echo "No changes to commit"
          else
            git commit -m "Update schema.json, examples, and entry figures"
            git push origin HEAD:main
          fi
