name: Go

on:
  pull_request:
    branches:
    - master

# This ensures that previous jobs for the PR are canceled when the PR is
# updated.
concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref }}
  cancel-in-progress: true

jobs:
  build:
    name: Test on Go ${{ matrix.go-version }} and ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    env:
      GO111MODULE: on
    strategy:
      matrix:
        go-version: [1.18.x, 1.19.x]
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
      - name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }}
        uses: actions/setup-go@v1
        with:
          go-version: ${{ matrix.go-version }}
        id: go

      - name: Check out code into the Go module directory
        uses: actions/checkout@v1

      - name: Build on ${{ matrix.os }}
        if: matrix.os == 'windows-latest'
        run: |
          go build --ldflags="-s -w" -o %GOPATH%\bin\mc.exe
          go test -v -race --timeout 30m ./...
      - name: Build on ${{ matrix.os }}
        if: matrix.os == 'macos-latest'
        run: |
          go build --ldflags="-s -w" -o %GOPATH%\bin\mc
          go test -v -race --timeout 30m ./...
      - name: Build on ${{ matrix.os }}
        if: matrix.os == 'ubuntu-latest'
        env:
          ACCESS_KEY: minioadmin
          SECRET_KEY: minioadmin
          ENABLE_HTTPS: 1
          MINIO_CI_CD: 1
          SERVER_ENDPOINT: localhost:9000
        run: |
          wget https://dl.min.io/server/minio/release/linux-amd64/minio && chmod +x minio
          mkdir -p ~/.minio/certs/ && cp testdata/localhost.crt ~/.minio/certs/public.crt && cp testdata/localhost.key ~/.minio/certs/private.key
          sudo cp testdata/localhost.crt /usr/local/share/ca-certificates/ && sudo update-ca-certificates
          ./minio server /tmp/test-xl/{1...4}/ & sleep 10
          make
          make test-race
          make verify
          make crosscompile
  vetchecks: # Run vet checks against one version.
    env:
      CGO_ENABLED: 0
    runs-on: ubuntu-latest
    steps:
      - name: Set up Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.19.x

      - name: Checkout code
        uses: actions/checkout@v2

      - name: Test 386
        run: GOOS=linux GOARCH=386 go test -short ./...
