name: Frontend build and test
on:
  push:
    branches:
      - master
  pull_request_target:
    types: ["opened", "edited", "reopened", "synchronize"]
    paths:
      - "kafka-ui-contract/**"
      - "kafka-ui-react-app/**"
jobs:
  build-and-test:
    env:
      CI: true
      NODE_ENV: dev
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          # Disabling shallow clone is recommended for improving relevancy of reporting
          fetch-depth: 0
          ref: ${{ github.event.pull_request.head.sha }}
      - uses: pnpm/action-setup@v2.2.4
        with:
          version: 7.4.0
      - name: Install node
        uses: actions/setup-node@v3.6.0
        with:
          node-version: "16.15.0"
          cache: "pnpm"
          cache-dependency-path: "./kafka-ui-react-app/pnpm-lock.yaml"
      - name: Install Node dependencies
        run: |
          cd kafka-ui-react-app/
          pnpm install --frozen-lockfile
      - name: Generate sources
        run: |
          cd kafka-ui-react-app/
          pnpm gen:sources
      - name: Linter
        run: |
          cd kafka-ui-react-app/
          pnpm lint:CI
      - name: Tests
        run: |
          cd kafka-ui-react-app/
          pnpm test:CI
      - name: SonarCloud Scan
        uses: workshur/sonarcloud-github-action@improved_basedir
        with:
          projectBaseDir: ./kafka-ui-react-app
          args: -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} -Dsonar.pullrequest.branch=${{ github.head_ref }} -Dsonar.pullrequest.base=${{ github.base_ref }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_FRONTEND }}
