name: Build
run-name: Running Lint Check and Licence checker on Pull Request
on: [pull_request]

jobs:
  Build-and-ng-test:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 20

      - name: Install Google Chrome
        run: |
          wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
          echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
          apt-get update
          apt-get install -y google-chrome-stable xvfb

      - name: Write .npmrc file
        run: echo "$NPMRC" > client/.npmrc
        shell: bash
        env:
          NPMRC: ${{ secrets.NPMRC}}

      - name: Lint check
        run: npm run lint:check

      - name: Install dependencies
        run: |
          cd client
          npm ci
          # Decrypt and Install sheet
          echo ${{ secrets.SHEET_PWD }} | gpg --batch --yes --passphrase-fd 0 ./libraries/sheet-crypto.tgz.gpg
          npm i ./libraries/sheet-crypto.tgz
          # End

      - name: Licence checker
        run: |
          cd client
          npm run license-checker

      - name: Angular Tests
        run: |
          cd client
          npm run test:headless

      - name: Production Build
        run: |
          cd client
          npm run build