name: Update Config Json Schema

on:
  push:
    branches:
      - dev
  workflow_dispatch:

permissions:
  contents: write
jobs:
  changelog:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Miniconda
        uses: conda-incubator/setup-miniconda@v3
        with:
          python-version: ${{ matrix.python-version }}

      - name: Initialize Conda
        run: |
          conda init bash

      - name: Create conda environment
        run: |
          conda env create -f environment.yml
          source ~/.bashrc
          conda activate Paidiverpy
          pip install -e .


      - name: Generate Json Schema
        run: |
          source ~/.bashrc
          conda activate Paidiverpy
          python src/paidiverpy/utils/schema_json_handler.py src/paidiverpy/configuration-schema.json

      - name: Commit and push changes (if any)
        run: |
          git config --global user.name "github-actions[bot]"
          git config --global user.email "github-actions[bot]@users.noreply.github.com"

          git add src/paidiverpy/configuration-schema.json

          if git diff --cached --quiet; then
            echo "No changes to commit."
            exit 0
          fi

          git commit -m "chore: update json schema"

          # Make sure we are up to date
          git pull --rebase origin dev
          git push origin dev
