project_name: confluent

builds:
  - id: confluent-alpine-amd64
    binary: confluent
    main: cmd/confluent/main.go
    flags:
      - -tags=musl
    ldflags:
      - -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
    gcflags:
      - all=-trimpath={{.Env.HOME}}/git
    asmflags:
      - all=-trimpath={{.Env.HOME}}/git
    env:
      - CGO_ENABLED=1
      - CC=x86_64-linux-musl-gcc
      - CXX=x86_64-linux-musl-g++
      - CGO_LDFLAGS=${CGO_LDFLAGS} -static
    goos:
      - linux
    goarch:
      - amd64
  - id: confluent-alpine-arm64
    binary: confluent
    main: cmd/confluent/main.go
    flags:
      - -tags=musl
    ldflags:
      - -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
    gcflags:
      - all=-trimpath={{.Env.HOME}}/git
    asmflags:
      - all=-trimpath={{.Env.HOME}}/git
    env:
      - CGO_ENABLED=1
      - CC=aarch64-linux-musl-gcc
      - CXX=aarch64-linux-musl-g++
      - CGO_LDFLAGS=${CGO_LDFLAGS} -static
    goos:
      - linux
    goarch:
      - arm64
  - id: confluent-darwin-amd64
    binary: confluent
    main: cmd/confluent/main.go
    ldflags:
      - -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
    gcflags:
      - all=-trimpath={{.Env.HOME}}/git
    asmflags:
      - all=-trimpath={{.Env.HOME}}/git
    goos:
      - darwin
    goarch:
      - amd64
    hooks:
      post:
        - cmd: make download-licenses
        - cmd: bash scripts/gon_filepath_editor.sh {{ .Path }} amd64
        - cmd: gon dist/gon_confluent_darwin_amd64.hcl
          output: true
  - id: confluent-darwin-amd64-homebrew
    binary: confluent
    main: cmd/confluent/main.go
    flags:
      - -mod=readonly
    ldflags:
      - -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} -X main.disableUpdates=true
    gcflags:
      - all=-trimpath={{.Env.HOME}}/git
    asmflags:
      - all=-trimpath={{.Env.HOME}}/git
    goos:
      - darwin
    goarch:
      - amd64
    hooks:
      post:
        - cmd: bash scripts/gon_filepath_editor.sh {{ .Path }} amd64_homebrew
        - cmd: gon dist/gon_confluent_darwin_amd64_homebrew.hcl
          output: true
  - id: confluent-darwin-arm64
    binary: confluent
    main: cmd/confluent/main.go
    env:
      - CGO_ENABLED=1
    ldflags:
      - -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
    gcflags:
      - all=-trimpath={{.Env.HOME}}/git
    asmflags:
      - all=-trimpath={{.Env.HOME}}/git
    goos:
      - darwin
    goarch:
      - arm64
    hooks:
      post:
        - cmd: bash scripts/gon_filepath_editor.sh {{ .Path }} arm64
        - cmd: gon dist/gon_confluent_darwin_arm64.hcl
          output: true
  - id: confluent-darwin-arm64-homebrew
    binary: confluent
    main: cmd/confluent/main.go
    flags:
      - -mod=readonly
    env:
      - CGO_ENABLED=1
    ldflags:
      - -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} -X main.disableUpdates=true
    gcflags:
      - all=-trimpath={{.Env.HOME}}/git
    asmflags:
      - all=-trimpath={{.Env.HOME}}/git
    goos:
      - darwin
    goarch:
      - arm64
    hooks:
      post:
        - cmd: bash scripts/gon_filepath_editor.sh {{ .Path }} arm64_homebrew
        - cmd: gon dist/gon_confluent_darwin_arm64_homebrew.hcl
          output: true
  - id: confluent-linux
    builder: prebuilt
    goos:
      - linux
    goarch:
      - amd64
      - arm64
    goamd64:
      - v1
    prebuilt:
      path: "prebuilt/confluent-{{ .Os }}-{{ .Arch }}_{{ .Os }}_{{ .Arch }}{{ with .Amd64 }}_{{ . }}{{ end }}/confluent"
  - id: confluent-linux-homebrew
    builder: prebuilt
    goos:
      - linux
    goarch:
      - amd64
      - arm64
    goamd64:
      - v1
    prebuilt:
      path: "prebuilt/confluent-{{ .Os }}-{{ .Arch }}-homebrew_{{ .Os }}_{{ .Arch }}{{ with .Amd64 }}_{{ . }}{{ end }}/confluent"
  - id: confluent-windows-amd64
    binary: confluent
    main: cmd/confluent/main.go
    ldflags:
      - -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} -buildmode=exe  
    gcflags:
      - all=-trimpath={{.Env.HOME}}/git
    asmflags:
      - all=-trimpath={{.Env.HOME}}/git
    env:
      - CGO_ENABLED=1
      - CC=x86_64-w64-mingw32-gcc
      - CXX=x86_64-w64-mingw32-g++
      - CGO_LDFLAGS=${CGO_LDFLAGS} -static
    goos:
      - windows
    goarch:
      - amd64
    hooks:
      pre:
        - cmd: az login
        - cmd: az keyvault secret download --file CLIEVCodeSigningCertificate2.pfx --name CLIEVCodeSigningCertificate2 --subscription cc-prod --vault-name CLICodeSigningKeyVault --encoding base64
        - cmd: xattr -dr com.apple.quarantine ./lib/osslsigncode
      post:
        - cmd: ./lib/osslsigncode sign -n "Confluent CLI" -i "https://confluent.io" -pkcs12 CLIEVCodeSigningCertificate2.pfx -in {{ .Path }} -out {{ .Path }}
        - cmd: rm CLIEVCodeSigningCertificate2.pfx

archives:
  - id: archive
    format: tar.gz
    builds:
      - confluent-darwin-amd64
      - confluent-darwin-arm64
      - confluent-linux
      - confluent-windows-amd64
    name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
    format_overrides:
      - goos: windows
        format: zip
    wrap_in_directory: "{{ .ProjectName }}"
    files:
      - LICENSE
      - legal/**/*
  - id: archive-alpine
    format: tar.gz
    builds:
      - confluent-alpine-amd64
      - confluent-alpine-arm64
    name_template: "{{ .ProjectName }}_{{ .Version }}_alpine_{{ .Arch }}"
    wrap_in_directory: "{{ .ProjectName }}"
    files:
      - LICENSE
      - legal/**/*
  - id: archive-homebrew
    format: tar.gz
    builds:
      - confluent-darwin-amd64-homebrew
      - confluent-darwin-arm64-homebrew
      - confluent-linux-homebrew
    name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}_homebrew"
    wrap_in_directory: "{{ .ProjectName }}"
    files:
      - LICENSE
      - legal/**/*
  - id: binary
    format: binary
    builds:
      - confluent-darwin-amd64
      - confluent-darwin-arm64
      - confluent-linux
      - confluent-windows-amd64
    name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
  - id: binary-alpine
    format: binary
    builds:
      - confluent-alpine-amd64
      - confluent-alpine-arm64
    name_template: "{{ .ProjectName }}_{{ .Version }}_alpine_{{ .Arch }}"
    
dockers:
  - ids:
      - confluent-alpine-amd64
    goarch: amd64
    image_templates:
      - "confluentinc/confluent-cli:{{ .Version }}-amd64"
      - "confluentinc/confluent-cli:latest-amd64"
    dockerfile: "docker/Dockerfile"
    build_flag_templates:
      - --platform=linux/amd64
  - ids:
      - confluent-alpine-arm64
    goarch: arm64
    image_templates:
      - "confluentinc/confluent-cli:{{ .Version }}-arm64"
      - "confluentinc/confluent-cli:latest-arm64"
    dockerfile: "docker/Dockerfile"
    build_flag_templates:
      - --platform=linux/arm64

docker_manifests:
  - name_template: "confluentinc/confluent-cli:{{ .Version }}"
    image_templates:
      - "confluentinc/confluent-cli:{{ .Version }}-amd64"
      - "confluentinc/confluent-cli:{{ .Version }}-arm64"
    skip_push: "{{ .Env.DRY_RUN }}"
  - name_template: "confluentinc/confluent-cli:latest"
    image_templates:
      - "confluentinc/confluent-cli:latest-amd64"
      - "confluentinc/confluent-cli:latest-arm64"
    skip_push: "{{ .Env.DRY_RUN }}"

release:
  ids:
    - archive
    - archive-alpine
    - binary
    - binary-alpine
  disable: "{{.Env.DRY_RUN}}"

blobs:
  - ids:
    - binary
    - binary-alpine
    provider: s3
    bucket: confluent.cloud
    region: us-west-2
    folder: "{{ .Env.S3FOLDER }}/binaries/{{ .Version }}"
    disable: "{{ .Env.DRY_RUN }}"
  - ids:
    - archive
    - archive-alpine
    - archive-homebrew
    provider: s3
    bucket: confluent.cloud
    region: us-west-2
    folder: "{{ .Env.S3FOLDER }}/archives/{{ .Version }}"
    disable: "{{ .Env.DRY_RUN }}"

brews:
  - name: cli
    ids:
      - archive-homebrew
    repository:
      owner: confluentinc
      name: homebrew-tap
      branch: "cli-{{ .Version }}"
      pull_request:
        enabled: true
        base:
          owner: confluentinc
          name: homebrew-tap
          branch: master
    url_template: "https://s3-us-west-2.amazonaws.com/confluent.cloud/confluent-cli/archives/{{ .Version }}/{{ .ArtifactName }}"
    homepage: https://docs.confluent.io/confluent-cli/current/overview.html
    description: CLI for Confluent Cloud and Confluent Platform
    skip_upload: "{{ .Env.DRY_RUN }}"
    test: system "#{bin}/confluent version"