name: Test
on:
  pull_request:
    branches:
      - "**"
  push:
    branches:
      - master
jobs:
  build:
    name: Test
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-18.04, macos-11, windows-2019]
        node-version: [14.x]
    steps:
      - name: Checkout Release from lens
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Add the current IP address, long hostname and short hostname record to /etc/hosts file
        if: runner.os == 'Linux'
        run: |
          echo -e "$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)\t$(hostname -f) $(hostname -s)" | sudo tee -a /etc/hosts

      - name: Using Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - uses: actions/cache@v2
        id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - uses: nick-invision/retry@v2
        name: Install dependencies
        with:
          timeout_minutes: 10
          max_attempts: 3
          retry_on: error
          command: make node_modules

      - run: make build-npm
        name: Generate npm package

      - uses: nick-invision/retry@v2
        name: Build bundled extensions
        with:
          timeout_minutes: 15
          max_attempts: 3
          retry_on: error
          command: make -j2 build-extensions

      - run: make test
        name: Run tests

      - run: make test-extensions
        name: Run In-tree Extension tests

      - name: Install integration test dependencies
        id: minikube
        uses: medyagh/setup-minikube@5a9a7104d7322fa40424de8855c84685e89cefd7
        if: runner.os == 'Linux'

      - run: xvfb-run --auto-servernum --server-args='-screen 0, 1600x900x24' make integration
        name: Run Linux integration tests
        if: runner.os == 'Linux'

      - run: make integration
        name: Run macOS integration tests
        shell: bash
        env:
          ELECTRON_BUILDER_EXTRA_ARGS: "--x64 --arm64"
        if: runner.os == 'macOS'

      - run: make integration
        name: Run Windows integration tests
        shell: bash
        env:
          ELECTRON_BUILDER_EXTRA_ARGS: "--x64 --ia32"
        if: runner.os == 'Windows'
