From b78b5f48a143ff9d056a4314c3d530f5c9119984 Mon Sep 17 00:00:00 2001
From: Michael Kriese <michael.kriese@visualon.de>
Date: Fri, 28 Feb 2020 10:51:08 +0100
Subject: [PATCH] chore(ci): refactor tests (#5589)

---
 .github/workflows/test.yml | 92 ++++++++++++++++++++++++++++++--------
 1 file changed, 74 insertions(+), 18 deletions(-)

diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 1b603f8361..f780e1470b 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -17,10 +17,9 @@ jobs:
     runs-on: ${{ matrix.os }}
 
     # tests shouldn't nee more than 10 min
-    timeout-minutes: 15
+    timeout-minutes: 10
 
     strategy:
-      max-parallel: 6
       matrix:
         os: [ubuntu-latest, macos-latest, windows-latest]
         node-version: [10, 12]
@@ -30,6 +29,8 @@ jobs:
           - os: windows-latest
             node-version: 10
 
+    env:
+      coverage: ${{ matrix.os == 'ubuntu-latest' && matrix.node-version == 12 && github.ref != 'refs/heads/master' }}
     steps:
       - name: Set up Node.js ${{ matrix.node-version }}
         uses: actions/setup-node@v1
@@ -49,7 +50,8 @@ jobs:
 
       - name: Skip Java tests
         if: matrix.node-version != 12 || github.ref == 'refs/heads/master'
-        run: echo "::set-env name=SKIP_JAVA_TESTS::true"
+        run: |
+          echo "::set-env name=SKIP_JAVA_TESTS::true"
 
       - name: Init platform
         id: init
@@ -104,35 +106,89 @@ jobs:
         run: python -c "from pip._internal.locations import USER_CACHE_DIR; from shutil import rmtree; rmtree(USER_CACHE_DIR, ignore_errors=True)"
 
       - name: Installing dependencies
-        shell: bash
         run: |
           python -m pip install --upgrade pip
           yarn install --frozen-lockfile --link-duplicates
           pip install --user -r requirements.txt
 
-      - name: Lint
-        if: matrix.os == 'ubuntu-latest' && matrix.node-version == 12
-        run: yarn lint
-
-      - name: Test schema
-        if: matrix.os == 'ubuntu-latest' && matrix.node-version == 12
-        run: yarn test-schema
-
-      - name: Type check
-        if: matrix.os == 'ubuntu-latest' && matrix.node-version == 12
-        run: yarn type-check
-
       - name: Build
         run: yarn build
 
       - name: Unit tests
-        run: yarn jest --maxWorkers=2 --ci
+        run: yarn jest --maxWorkers=2 --ci --coverage ${{ env.coverage }}
 
       - name: Codecov
-        if: always() && matrix.os == 'ubuntu-latest' && matrix.node-version == 12
+        if: always() && env.coverage == 'true'
+        shell: bash
         run: bash <(curl -s https://codecov.io/bash) || echo 'Codecov failed to upload'
         env:
           CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
 
       - name: E2E Test
         run: yarn test-e2e
+
+  lint:
+    runs-on: ${{ matrix.os }}
+
+    # tests shouldn't nee more than 10 min
+    timeout-minutes: 10
+
+    strategy:
+      matrix:
+        os: [ubuntu-latest]
+        node-version: [12]
+
+    steps:
+      - name: Set up Node.js ${{ matrix.node-version }}
+        uses: actions/setup-node@v1
+        with:
+          node-version: ${{ matrix.node-version }}
+
+      - name: Init platform
+        id: init
+        shell: bash
+        run: |
+          echo "::set-output name=yarn_cache::$(yarn cache dir)"
+          git config --global core.autocrlf false
+          git config --global core.symlinks true
+          git config --global user.email 'bot@renovateapp.com'
+          git config --global user.name  'Renovate Bot'
+          node --version
+          python --version
+          yarn --version
+
+      - uses: actions/checkout@v2
+
+      - name: Cache Yarn packages
+        id: yarn_cache_packages
+        uses: actions/cache@v1
+        with:
+          path: ${{ steps.init.outputs.yarn_cache }}
+          key: v1-${{ runner.os }}-yarn_cache-${{ hashFiles('**/yarn.lock') }}
+          restore-keys: |
+            v1-${{ runner.os }}-yarn_cache-
+
+      - name: Cache node_modules
+        uses: actions/cache@v1
+        with:
+          path: node_modules
+          key: ${{ runner.os }}-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}
+          restore-keys: |
+            ${{ runner.os }}-${{ matrix.node-version }}-yarn-
+
+      # Clear caches on cache miss, otherwise they will grow indefinitely
+      - name: Clear yarn cache
+        if: steps.yarn_cache_packages.outputs.cache-hit != 'true'
+        run: yarn cache clean
+
+      - name: Installing dependencies
+        run: yarn install --frozen-lockfile --link-duplicates
+
+      - name: Lint
+        run: yarn lint
+
+      - name: Test schema
+        run: yarn test-schema
+
+      - name: Type check
+        run: yarn type-check
-- 
GitLab