name: Unit-Test

on:
  push:
    branches:
      - master
      - release-*
  workflow_dispatch: {}
  pull_request:
    branches:
      - master
      - release-*

permissions:
  contents: read

jobs:
  detect-noop:
    permissions:
      actions: write # for fkirc/skip-duplicate-actions to skip or stop workflow runs
    runs-on: ubuntu-22.04
    outputs:
      noop: ${{ steps.noop.outputs.should_skip }}
    steps:
      - name: Detect No-op Changes
        id: noop
        uses: fkirc/skip-duplicate-actions@f75f66ce1886f00957d99748a42c724f4330bdcf
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          paths_ignore: '["**.md", "**.mdx", "**.png", "**.jpg"]'
          do_not_skip: '["workflow_dispatch", "schedule", "push"]'
        continue-on-error: true

  unit-tests:
    runs-on: ubuntu-22.04
    needs: detect-noop
    if: needs.detect-noop.outputs.noop != 'true'

    steps:
      - name: Check out code into the Go module directory
        uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
        with:
          submodules: true

      - name: Setup Env
        uses: ./.github/actions/env-setup

      - name: Setup KinD with Kubernetes
        uses: ./.github/actions/setup-kind-cluster

      - name: Run unit tests
        uses: ./.github/actions/unit-test
        with:
          codecov-enable: true
          codecov-token: ${{ secrets.CODECOV_TOKEN }}
