name: "Build"
on:
    push:
        branches:
            - "1.x"
        tags:
            - v1*
        paths-ignore:
            - "docs/**"
            - "assets/**"
            - "**.md"
    pull_request:
        branches:
            - "1.x"
        types: [opened, reopened, synchronize]
        paths-ignore:
            - "docs/**"
            - "assets/**"
            - "**.md"
jobs:
    lint:
        runs-on: ubuntu-latest
        env:
            TEST: "build_and_lint"
            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        steps:
            - uses: actions/setup-node@v1
              with:
                  node-version: 12

            - uses: actions/checkout@v2

            - uses: actions/cache@v2
              id: cache-deps
              with:
                  path: |
                      node_modules
                      */*/node_modules
                  key: ${{ runner.os }}-node12-${{ hashFiles('**/package-lock.json') }}

            - run: npm ci
              if: steps.cache-deps.outputs.cache-hit != 'true'

            - run: bash ./scripts/ci.sh
    unit:
        runs-on: ubuntu-latest
        strategy:
            matrix:
                node: [8, 10, 11, 12, 13]
        env:
            TEST: "unit"
        steps:
            - uses: actions/setup-node@v1
              with:
                  node-version: ${{ matrix.node }}

            - uses: actions/checkout@v2

            - uses: actions/cache@v2
              id: cache-deps
              with:
                  path: |
                      node_modules
                      */*/node_modules
                  key: ${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}

            - run: npm ci
              if: steps.cache-deps.outputs.cache-hit != 'true'

            - run: bash ./scripts/ci.sh
    e2e:
        runs-on: ubuntu-latest
        strategy:
            fail-fast: false
            matrix:
                testCmd:
                    [
                        'unit_and_e2e_clients',
                        'e2e_browsers',
                        'e2e_ganache',
                        'e2e_mosaic',
                        'e2e_gnosis_dex',
                    ]
        env:
            TEST: ${{ matrix.testCmd }}
            INFURA_HTTP: ${{ secrets.INFURA_HTTP }}
        steps:
            - uses: actions/setup-node@v1
              with:
                  node-version: 12
            - uses: actions/checkout@v2

            - uses: actions/cache@v2
              id: cache-deps
              if: env.TEST == 'unit_and_e2e_clients' || env.TEST == 'e2e_browsers'
              with:
                  path: |
                      node_modules
                      */*/node_modules
                  key: ${{ runner.os }}-node12-${{ hashFiles('**/package-lock.json') }}

            - run: npm ci
              if: (env.TEST == 'unit_and_e2e_clients' || env.TEST == 'e2e_browsers') && steps.cache-deps.outputs.cache-hit != 'true'

            - run: bash ./scripts/ci.sh

            - name: Send coverage reports to Coveralls
              if: env.TEST == 'unit_and_e2e_clients'
              uses: coverallsapp/github-action@master
              with:
                  github-token: ${{ secrets.GITHUB_TOKEN }}
    e2e_windows:
        runs-on: windows-latest
        env:
            TEST: "e2e_windows"
            INFURA_HTTP: ${{ secrets.INFURA_HTTP }}
            INFURA_WSS: ${{ secrets.INFURA_WSS }}
        steps:
            - uses: actions/setup-node@v1
              with:
                  node-version: 12
            - uses: actions/checkout@v2
            - run: bash ./scripts/ci.sh
    eth2:
        runs-on: ubuntu-latest
        strategy:
            matrix:
                node: [10, 11, 12, 13]
        env:
            TEST: "eth2"
        steps:
            - uses: actions/setup-node@v1
              with:
                  node-version: ${{ matrix.node }}

            - uses: actions/checkout@v2

            - uses: actions/cache@v2
              id: cache-deps
              with:
                  path: |
                      node_modules
                      */*/node_modules
                  key: ${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}

            - run: npm ci
              if: steps.cache-deps.outputs.cache-hit != 'true'

            - run: bash ./scripts/ci.sh
