name: Tests (govc)

permissions:
  contents: read
  actions: read

on:
  push:
    branches: main
  pull_request:
    branches: main

concurrency:
  group: govmomi-govc-tests-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  govc-tests:
    name: Run govc Tests
    strategy:
      fail-fast: false
      matrix:
        go-version: ["1.23"]
        platform: [ubuntu-latest]
        cmd: [govc-test]
        experimental: [false]
        timeout: [20]

    runs-on: ${{ matrix.platform }}
    continue-on-error: ${{ matrix.experimental }}
    timeout-minutes: ${{ matrix.timeout }}

    steps:
      - name: Check Repository
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

      - name: Setup Go ${{ matrix.go-version }}
        uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
        with:
          go-version: ${{ matrix.go-version }}
        id: go

      - name: Restore Go Cache
        uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
        with:
          path: |
            ~/.cache/go-build
            ~/go/pkg/mod
          key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-${{ matrix.go-version }}-

      - name: Run ${{ matrix.cmd }}
        run: |
          make ${{ matrix.cmd }}

      - name: Debug on Failure
        if: ${{ failure() }}
        uses: mxschmitt/action-tmate@7b6a61a73bbb9793cb80ad69b8dd8ac19261834c # v3.22

  govc-docs:
    name: Verify Updated Docs
    strategy:
      matrix:
        go-version: ["1.23"]
        platform: [ubuntu-latest]
    runs-on: ${{ matrix.platform }}
    timeout-minutes: 3
    steps:
      - name: Check Repository
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

      - name: Setup Go ${{ matrix.go-version }}
        uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
        with:
          go-version: ${{ matrix.go-version }}
        id: go

      - name: Restore Go Cache
        uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
        with:
          path: |
            ~/.cache/go-build
            ~/go/pkg/mod
          key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-${{ matrix.go-version }}-

      - name: Run "make doc"
        run: |
          make doc
          if [ -z "$(git status --porcelain)" ]; then
            echo "govc/USAGE.md is up2date..."
          else
            echo "dirty working directory (diff):"
            git --no-pager diff
            echo "::error file=govc/USAGE.md::Run make doc to update USAGE.md"
            exit 1
          fi
