name: Check Generated Modules

on:
  schedule:
    - cron:  '30 3 15 * *'

jobs:
  check-generated-modules:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version:
          - "3.12"
        node-version:
          - "20"

    steps:
      - uses: actions/checkout@v6.0.1
        with:
          fetch-depth: 2
      - name: Set up Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v6
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'
      - name: Generate registry JSON files
        run: |
          npm install
          npm run generate
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v6.1.0
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install Python scripts dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements_scripts.txt
      - name: Run scripts
        run: |
          python ./scripts/generate_multilevel_sensor_constants.py
          python ./scripts/generate_notification_constants.py
      - name: Check for changes
        id: changes
        uses: UnicornGlobal/has-changes-action@v1.0.12
      - name: Create Pull Request
        if: steps.changes.outputs.changed == 1
        uses: peter-evans/create-pull-request@v8.0.0
        with:
          commit-message: "Update auto-generated constants"
          delete-branch: true
          title: "Update auto-generated constants"
          labels: "ci-generated"
