name: coverage

on:
  push:
    branches:
      - master

jobs:
  coverage:
    if: "!contains(github.event.commits[0].message, '[skip ci]')"
    runs-on: ubuntu-latest
    timeout-minutes: 10

    steps:
    - uses: actions/checkout@v1

    - name: Install npm dependencies
      run: yarn install

    - name: fix istanbul-reports
      run: sed -i.bak 's/const meta = branchMap\[key\];/const meta = branchMap[key]; if (!meta) return;/g' node_modules/istanbul-reports/lib/lcovonly/index.js

    - name: Build
      run: yarn build

    - name: Prepare src folder for generating coverage report
      run: yarn nyc:instrument

    - name: Run Cypress tests, generate coverage report and publish it to codeclimate.com
      uses: paambaati/codeclimate-action@v2.4.0
      env:
        CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
      with:
        coverageCommand: yarn cy:run:headless
