name: test

# Default to 'contents: read', which grants actions to read commits.
#
# If any permission is set, any permission not included in the list is
# implicitly set to "none".
#
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
permissions:
  contents: read

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

on:
  workflow_dispatch:
  push:
    branches:
      - 'master'
      - '[0-9]+.[0-9]+'
      - '[0-9]+.x'
    tags:
      - 'v*'
  pull_request:

jobs:
  ctn:
    runs-on: ubuntu-24.04
    steps:
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
      -
        name: Test
        uses: docker/bake-action@a66e1c87e2eca0503c343edf1d208c716d54b8a8 # v7.1.0
        with:
          targets: test-coverage
      -
        name: Send to Codecov
        uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v5
        with:
          files: ./build/coverage/coverage.txt
          token: ${{ secrets.CODECOV_TOKEN }}

  host:
    runs-on: ${{ matrix.os }}
    env:
      GOPATH: ${{ github.workspace }}
      GOBIN: ${{ github.workspace }}/bin
      GO111MODULE: auto
    strategy:
      fail-fast: false
      matrix:
        os:
          - macos-14        # macOS 14 on arm64 (Apple Silicon M1)
          - macos-15-intel  # macOS 15 on Intel
          - macos-15        # macOS 15 on arm64 (Apple Silicon M1)
#          - windows-2022 # FIXME: some tests are failing on the Windows runner, as well as on Appveyor since June 24, 2018: https://ci.appveyor.com/project/docker/cli/history
    steps:
      -
        name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
        with:
          path: ${{ env.GOPATH }}/src/github.com/docker/cli
      -
        name: Set up Go
        uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6
        with:
          go-version: "1.26.3"
          cache: false
      -
        name: Test
        run: |
          # run in go modules mode to prevent traversing to nested modules
          ln -s vendor.mod go.mod
          ln -s vendor.sum go.sum
          go test -coverprofile=/tmp/coverage.txt $(go list ./... | grep -vE '^github.com/docker/cli/e2e/')
          go tool cover -func=/tmp/coverage.txt
        working-directory: ${{ env.GOPATH }}/src/github.com/docker/cli
        shell: bash
      -
        name: Send to Codecov
        uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v5
        with:
          files: /tmp/coverage.txt
          working-directory: ${{ env.GOPATH }}/src/github.com/docker/cli
          token: ${{ secrets.CODECOV_TOKEN }}
