# Copyright 2020 The Knative Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This file is automagically synced here from github.com/knative-sandbox/.github
# repo by knobots: https://github.com/knative-sandbox/knobots and will be overwritten.

name: Test

on:

  push:
    branches: [ 'main', 'master' ]

  pull_request:
    branches: [ 'main', 'master', 'release-*' ]

jobs:

  test:
    name: Unit Tests
    strategy:
      matrix:
        go-version: [1.15.x]
        platform: [ubuntu-latest]

    runs-on: ${{ matrix.platform }}

    steps:

      - name: Set up Go ${{ matrix.go-version }}
        uses: actions/setup-go@v2
        with:
          go-version: ${{ matrix.go-version }}
        id: go

      - name: Check out code
        uses: actions/checkout@v2

      - name: Check for .codecov.yaml
        id: codecov-enabled
        uses: andstor/file-existence-action@v1
        with:
          files: .codecov.yaml

      - if: steps.codecov-enabled.outputs.files_exists == 'true'
        name: Produce Go Coverage
        run: echo 'COVER_OPTS=-coverprofile=coverage.txt -covermode=atomic' >> $GITHUB_ENV

      - name: Test
        run: go test -race $COVER_OPTS ./...

      - if: steps.codecov-enabled.outputs.files_exists == 'true'
        name: Codecov
        uses: codecov/codecov-action@v1
