version: v1.0
name: Confluent CLI

agent:
  machine:
    type: e1-standard-2
    os_image: ubuntu2004

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

execution_time_limit:
  hours: 1

blocks:
  - name: linux/amd64
    dependencies: []
    task:
      jobs:
        - name: linux/amd64
          commands:
            # Set up Go
            - checkout
            - wget https://go.dev/dl/go$(cat .go-version).linux-amd64.tar.gz
            - sudo tar -xvf go$(cat .go-version).linux-amd64.tar.gz -C /usr/local
            - export GOROOT=/usr/local/go
            - export PATH=$GOROOT/bin:$PATH
            - export PATH=$(go env GOPATH)/bin:$PATH

            # Try to restore cached dependencies
            - cache restore linux-$(checksum go.sum)

            # Run tests
            - make generate-packaging-patch
            - diff --version
            - 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

            # Cache Go dependencies
            - cache store linux-$(checksum go.sum) $(go env GOPATH)/pkg/mod
      epilogue:
        always:
          commands:
            - test-results publish . -N "linux/amd64"

  - name: darwin/amd64
    dependencies: []
    task:
      agent:
        machine:
          type: a1-standard-4
          os_image: macos-xcode14
      jobs:
        - name: darwin/amd64
          commands:
            # Set up Go
            - checkout
            - wget https://go.dev/dl/go$(cat .go-version).darwin-amd64.tar.gz
            - sudo tar -xvf go$(cat .go-version).darwin-amd64.tar.gz -C /usr/local
            - export GOROOT=/usr/local/go
            - export PATH=$GOROOT/bin:$PATH
            - export PATH=$(go env GOPATH)/bin:$PATH

            # Run tests
            - make test

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