# This script will run tests anytime a pull request is added
name: Session Test

on:
  pull_request:
    branches:
      - clearnet

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [windows-2016, macos-latest, ubuntu-18.04]
    env:
      SIGNAL_ENV: production
      GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - run: git config --global core.autocrlf false

      - name: Checkout git repo
        uses: actions/checkout@v2

      - name: Pull git submodules
        run: git submodule update --init

      - name: Install node
        uses: actions/setup-node@v1
        with:
          node-version: 10.19.0

      - name: Chocolatey Install Action
        if: runner.os == 'Windows'
        uses: crazy-max/ghaction-chocolatey@v1.4.2
        with:
          args: install python2 visualcpp-build-tools -y

      #Not having this will break the windows build because the PATH won't be set by msbuild.
      - name: Add msbuild to PATH
        uses: microsoft/setup-msbuild@v1.0.2
        if: runner.os == 'Windows'

      - name: Setup node for windows
        if: runner.os == 'Windows'
        run: |
          npm install --global node-gyp@latest
          npm config set python python2.7
          npm config set msvs_version 2017

      - uses: actions/cache@v2
        id: yarn-cache
        if: runner.os != 'Windows'
        with:
          path: '**/node_modules'
          key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

      - name: Install Dependencies #skipped if step before set variable to true
        if: |
          steps.yarn-cache.outputs.cache-hit != 'true'
        run: yarn install --frozen-lockfile --network-timeout 600000

      - name: Generate and concat files
        run: yarn generate

      - name: Lint Files
        if: runner.os != 'Windows'
        run: |
          yarn format-full
          yarn eslint
          yarn tslint

      - name: Make linux use en_US locale
        if: runner.os == 'Linux'
        run: |
          sudo apt-get install -y hunspell-en-us
          sudo locale-gen en_US.UTF-8
          sudo dpkg-reconfigure locales
          echo "::stop-commands::`echo -n ${{ github.token }} | sha256sum | head -c 64`"
          echo ::set-env name=DISPLAY:::9.0
          echo ::set-env name=LANG::en_US.UTF-8
          echo "::`echo -n ${{ github.token }} | sha256sum | head -c 64`::"

      - name: Test
        uses: GabrielBB/xvfb-action@v1.0
        with:
          run: yarn test
