name: Codecov

on:
  pull_request:
    branches: [ master ]
    types:
      - closed

jobs:

  build:
    name: Build
    if: github.event.pull_request.merged == true
    strategy:
      matrix:
        go-version: [1.21.x]
        platform: [ubuntu-latest]
        tags: 
          - ""
          - "-tags bounds"
          - "-tags noasm"
          - "-tags safe"

    runs-on: ${{ matrix.platform }}
    env:
        GO111MODULE: on
        GOPATH: ${{ github.workspace }}
        TAGS: ${{ matrix.tags }}
    defaults:
        run:
            working-directory: ${{ env.GOPATH }}/src/gonum.org/v1/gonum

    steps:
    - name: Install Go
      uses: actions/setup-go@v2
      with:
        go-version: ${{ matrix.go-version }}

    - name: Checkout code
      uses: actions/checkout@v2
      with:
        path: ${{ env.GOPATH }}/src/gonum.org/v1/gonum

    - name: Cache-Go
      uses: actions/cache@v2
      with:
        # In order:
        # * Module download cache
        # * Build cache (Linux)
        # * Build cache (Mac)
        # * Build cache (Windows)
        path: |
          ~/go/pkg/mod
          ~/.cache/go-build
          ~/Library/Caches/go-build
          '%LocalAppData%\go-build'
        key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
        restore-keys: |
          ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

    - name: Coverage
      if: matrix.platform == 'ubuntu-latest'
      run: |
        ./.github/workflows/script.d/test-coverage.sh

    - name: Upload-Coverage
      if: matrix.platform == 'ubuntu-latest'
      uses: codecov/codecov-action@v1
      with:
        override_pr: ${{ github.event.pull_request.number }}
        override_commit: ${{ github.event.pull_request.merge_commit_sha }}
        override_branch: "refs/heads/master"
