name: test

on:
  push:
    branches:
      - 'master'
    tags:
      - 'v*'
    paths-ignore:
      - '**.md'
      - '.github/workflows/docs.yml'
      - 'docs/**'
      - 'mkdocs.yml'
  pull_request:
    branches:
      - 'master'
    paths-ignore:
      - '**.md'
      - '.github/workflows/docs.yml'
      - 'docs/**'
      - 'mkdocs.yml'

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v2
      -
        name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.13
      -
        name: Cache Go modules
        uses: actions/cache@v2
        with:
          path: ~/go/pkg/mod
          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-
      -
        name: Go mod
        run: |
          go mod download
      -
        name: Test
        run: |
          go test -coverprofile=coverage.txt -covermode=atomic -race ./...
      -
        name: Upload coverage
        uses: codecov/codecov-action@v1
        if: success()
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          file: ./coverage.txt
