name: Codecov
permissions: {}

on:
  pull_request:
    branches: [ "main" ]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  codecov:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
      - name: Setup caches
        uses: ./.github/actions/setup-caches
        timeout-minutes: 5
        continue-on-error: true
        with:
          build-cache-key: codecov
      - name: Check secret
        id: checksecret
        uses: ./.github/actions/exists
        with:
          value: ${{ secrets.CODECOV_TOKEN }}
      - name: Generate Code Coverage Report
        if: steps.checksecret.outputs.result == 'true'
        run: make test
      - name: Upload Report to Codecov
        if: steps.checksecret.outputs.result == 'true'
        uses: codecov/codecov-action@54bcd8715eee62d40e33596ef5e8f0f48dbbccab # v4.1.0
        with:
          file: ./coverage.out
          fail_ci_if_error: true
          verbose: true
