# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
version: 2

project_name: dtctl

before:
  hooks:
    - go mod tidy
    - go build -o /tmp/dtctl-completions-helper .
    - sh -c "mkdir -p completions && /tmp/dtctl-completions-helper completion bash > completions/dtctl.bash"
    - sh -c "/tmp/dtctl-completions-helper completion zsh > completions/dtctl.zsh"
    - sh -c "/tmp/dtctl-completions-helper completion fish > completions/dtctl.fish"

builds:
  - env:
      - CGO_ENABLED=0
    goos:
      - linux
      - darwin
      - windows
    goarch:
      - amd64
      - arm64
    ldflags:
      - -s -w
      - -X github.com/dynatrace-oss/dtctl/pkg/version.Version={{.Version}}
      - -X github.com/dynatrace-oss/dtctl/pkg/version.Commit={{.ShortCommit}}
      - -X github.com/dynatrace-oss/dtctl/pkg/version.Date={{.Date}}

archives:
  - formats:
      - tar.gz
    name_template: >-
      {{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}
    files:
      - LICENSE*
      - README*
      - src: completions/*
        dst: completions
    format_overrides:
      - goos: windows
        formats:
          - zip

checksum:
  name_template: 'checksums.txt'

signs:
  - cmd: cosign
    artifacts: checksum
    args:
      - "sign-blob"
      - "--yes"
      - "--output-signature=${signature}"
      - "--output-certificate=${certificate}"
      - "${artifact}"

sboms:
  - artifacts: archive
    cmd: syft
    args:
      - "${artifact}"
      - "--output"
      - "spdx-json=${document}"

snapshot:
  version_template: "{{ incpatch .Version }}-next"

homebrew_casks:
  - repository:
      owner: dynatrace-oss
      name: homebrew-tap
      token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
    homepage: https://github.com/dynatrace-oss/dtctl
    description: "kubectl-inspired CLI for Dynatrace - manage workflows, dashboards, SLOs, queries, and more from your terminal"
    skip_upload: auto
    completions:
      bash: completions/dtctl.bash
      zsh: completions/dtctl.zsh
      fish: completions/dtctl.fish
    hooks:
      post:
        install: |
          if OS.mac?
            system_command "/usr/bin/xattr", args: ["-dr", "com.apple.quarantine", "#{staged_path}/dtctl"]
          end

# Release notes are written by release-please (GitHub Release body) and GoReleaser
# runs with `release.mode: keep-existing` to preserve them, so GoReleaser does not
# generate its own changelog.
changelog:
  disable: true

# release-please creates the GitHub Release (with notes) when the release PR is
# merged; GoReleaser only attaches the build artifacts to that existing release
# and must not overwrite its notes.
release:
  mode: keep-existing
