name: Code Coverage

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

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@v3

      - name: Setup Java
        uses: actions/setup-java@v3
        with:
          java-version: 17
          distribution: 'temurin'

      - name: Generate Coverage Report
        uses: gradle/gradle-build-action@v2
        with:
          arguments: jacocoMergedReport

      - name: Publish Coverage
        if: success()
        uses: codecov/codecov-action@v3
