name: Sonar
on:
  push:
    branches:
      - master
      - develop
      - cleanup_code
jobs:
  sonarcloud:
    name: SonarCloud
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Update ubuntu
        run: sudo apt update -y
      - name: Install missing library
        run: sudo apt-get install libnotify4 libsdl1.2debian libsdl2.2 wxpython-tools -y
      - name: Install xorg
        run: sudo apt-get install -y xorg openbox
      - name: Install Xvfb
        run: sudo apt-get install xvfb -y
      - name: Setup Python
        uses: actions/setup-python@v3
        with:
          python-version: ${{ matrix.python }}
      - name: Install invoke and any other packages
        run: pip install coverage invoke pytest
      - name: Install RIDE dependencies
        run: |
             git submodule update --init --recursive
             python -m pip install -U pip
             pip install -r requirements-dev.txt
             pip install robotframework
      - name: Run Xvfb
        run: Xvfb :1 -noreset &
      - name: Test Install RIDE
        run: |
             git submodule update --init --recursive
             pip install -r requirements-dev.txt
             pip install robotframework
             pip install .
      - name: Run RIDE unit-tests
        run: |
          export DISPLAY=:1
          git submodule update --init --recursive
          invoke test-ci
      - name: Analyze with SonarCloud
        uses: sonarsource/sonarqube-scan-action@master
        with:
          projectBaseDir: ${{ github.workspace }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          DISPLAY: :1

