name: Run unittests

on:
  push:
    branches:
      - master
      - v2
      - v3
  pull_request:

env:
  DISABLE_GA: "true"

jobs:
  py-httprunner:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      max-parallel: 12
      matrix:
        python-version: ['3.7', '3.8', '3.9', '3.10']
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
        architecture: x64
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install poetry
        poetry --version
        poetry install -vv
    - name: Run unittest for httprunner
      run: |
        poetry run httprunner
        poetry run hmake
        poetry run hrun
        poetry run coverage run --source=httprunner -m pytest httprunner
    - name: coverage report
      run: |
        poetry run coverage xml
        poetry run coverage report -m
    - name: Codecov
      uses: codecov/codecov-action@v1.0.5
      with:
        # User defined upload name. Visible in Codecov UI
        name: httprunner
        # Repository upload token - get it from codecov.io
        token: ${{ secrets.CODECOV_TOKEN }}
        # Path to coverage file to upload
        file: ./coverage.xml
        # Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome)
        flags: unittests
        # Specify whether or not CI build should fail if Codecov runs into an error during upload
        fail_ci_if_error: true

  go-hrp:
    strategy:
      fail-fast: false
      matrix:
        go-version:
          - 1.16.x
          - 1.17.x
          - 1.18.x
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Install Go
        uses: actions/setup-go@v2
        with:
          go-version: ${{ matrix.go-version }}
      - name: Install Python plugin dependencies
        run: python3 -m pip install funppy
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Run coverage
        run: go test -coverprofile="cover.out" -covermode=atomic -race ./...
      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v2
        with:
          name: hrp (HttpRunner+) # User defined upload name. Visible in Codecov UI
          token: ${{ secrets.CODECOV_TOKEN }} # Repository upload token
          file: ./cover.out # Path to coverage file to upload
          flags: unittests # Flag upload to group coverage metrics
          fail_ci_if_error: true # Specify whether or not CI build should fail if Codecov runs into an error during upload
          verbose: true
