---
version: '3'

tasks:
  bin:
    run: once
    cmds:
      - task: install
        vars:
          BIN: bin
          PACKAGE: github.com/marcosnils/bin@latest
    status:
      - type bin &> /dev/null

  get:
    run: when_changed
    log:
      error: Failed to acquire Go package named `{{.PACKAGE}}`
      start: Getting Go package named `{{.PACKAGE}}`
      success: Retrieved Go packaged named `{{.PACKAGE}}`
    cmds:
      - task: :install:software:go
      - go get {{.PACKAGE}}
    status:
      - type {{.BIN}} > /dev/null

  goreleaser:
    run: once
    cmds:
      - task: install
        vars:
          BIN: goreleaser
          PACKAGE: github.com/goreleaser/goreleaser@latest
    status:
      - type goreleaser > /dev/null

  gotestsum:
    run: once
    cmds:
      - task: install
        vars:
          BIN: gotestsum
          PACKAGE: gotest.tools/gotestsum@latest
    status:
      - type gotestsum > /dev/null

  install:
    run: when_changed
    log:
      error: Failed to install `{{.PACKAGE}}` with Go
      start: Installing Go package named `{{.PACKAGE}}`
      success: Successfully installed `{{.PACKAGE}}`
    cmds:
      - task: :install:software:go
      - go install {{.PACKAGE}}
    status:
      - type {{.BIN}} > /dev/null

  nfpm:
    run: once
    cmds:
      - task: install
        vars:
          BIN: nfpm
          PACKAGE: github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
    status:
      - type nfpm > /dev/null
