name: Code Coverage

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - '**'

env:
  GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}

permissions:
  contents: read

jobs:
  publish-code-coverage:
    if: ${{ !contains(github.event.head_commit.message, 'coverage skip') }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3

      - name: Setup Java
        uses: actions/setup-java@16cca5479d7c6b6843f6a6515640ba33c6501543 # tag=v3
        with:
          java-version: 17
          distribution: 'temurin'

      - name: Generate Coverage Report
        uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 # tag=v2
        with:
          arguments: jacocoMergedReport

      - name: Publish Coverage
        if: success()
        uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # tag=v3
