version: v1.0
name: Confluent CLI

agent:
  machine:
    type: s1-prod-ubuntu20-04-amd64-1

auto_cancel:
  running:
    when: "branch != 'main'"

execution_time_limit:
  hours: 1

blocks:
  - name: linux/amd64
    dependencies: []
    task:
      jobs:
        - name: linux/amd64
          commands:
            - checkout
            - sem-version go $(cat .go-version)
            - export PATH=$(go env GOPATH)/bin:$PATH
            - make generate-packaging-patch
            - diff -w -u <(git cat-file --filters HEAD:debian/patches/standard_build_layout.patch | awk "{if (NR>3) {print}}") <(cat debian/patches/standard_build_layout.patch | awk "{if (NR>3) {print}}")
            - make lint
            - make test
            - make test-installer
      epilogue:
        always:
          commands:
            - test-results publish . -N "linux/amd64"

  - name: darwin/arm64
    dependencies: []
    task:
      agent:
        machine:
          type: s1-prod-macos-13-5-arm64
      jobs:
        - name: darwin/arm64
          commands:
            - checkout
            - sem-version go $(cat .go-version)
            - export PATH=$(go env GOPATH)/bin:$PATH
            - make test
      epilogue:
        always:
          commands:
            - test-results publish . -N "darwin/arm64"

  - name: windows/amd64
    dependencies: []
    task:
      agent:
        machine:
          type: s1-prod-windows
      jobs:
        - name: windows/amd64
          commands:
            - checkout
            # https://confluentinc.atlassian.net/browse/DP-9532
            # Do not install Go with Chocolatey since it is community maintained and may not have the latest version
            - Invoke-WebRequest -OutFile Go.zip -Uri https://go.dev/dl/go$(Get-Content .go-version).windows-amd64.zip -UseBasicParsing
            - Expand-Archive Go.zip -DestinationPath C:\
            - $Env:PATH = "C:\Go\bin;$Env:PATH"
            - $Env:EXISTING_FLAGS = $(go env CGO_LDFLAGS)
            - go env -w CGO_LDFLAGS="-fstack-protector $Env:EXISTING_FLAGS"
            - $Env:GOCOVERDIR = "test/coverage"
            - New-Item $Env:GOCOVERDIR -ItemType Directory
            - go install gotest.tools/gotestsum@v1.8.2
            - gotestsum --junitfile unit-test-report.xml -- -timeout 0 -v $(go list ./... | Select-String test -NotMatch) -ldflags "-buildmode=exe"
            - gotestsum --junitfile integration-test-report.xml -- -timeout 0 -v $(go list ./... | Select-String test)
            - go tool covdata textfmt -i $Env:GOCOVERDIR -o test/coverage.out
      epilogue:
        always:
          commands:
            - test-results publish . -N "windows/amd64"

after_pipeline:
  task:
    jobs:
      - name: Publish Results
        commands:
          - test-results gen-pipeline-report
