---
version: '3'

tasks:
  bundle:
    deps:
      - docker-pushrm
      - fusion

  docker-pushrm:
    run: once
    tags:
      - update
    cmds:
      - task: install:github
        vars:
          BIN_NAME: docker-pushrm
          PACKAGE: github.com/christian-korneck/docker-pushrm
      - mkdir -p "$HOME/.docker/cli-plugins"
      - |
        if type docker-pushrm &> /dev/null; then
          mv "$(which docker-pushrm)" "$HOME/.docker/cli-plugins/docker-pushrm"
        else
          mv "$HOME/.local/go/bin/docker-pushrm" "$HOME/.docker/cli-plugins/docker-pushrm"
        fi
      - chmod +x "$HOME/.docker/cli-plugins/docker-pushrm"
    status:
      - '[ -f "$HOME/.docker/cli-plugins/docker-pushrm" ]'

  fusion:
    run: once
    tags:
      - update
    cmds:
      - task: install:github
        vars:
          BIN_NAME: fusion
          PACKAGE: github.com/edgelaboratories/fusion

  install:github:
    deps:
      - :install:software:jq
    vars:
      BIN: '{{.BIN_NAME}}'
    run: when_changed
    log:
      error: Failed to acquire GitHub release from `{{.PACKAGE}}`
      start: Acquiring GitHub binary release from `{{.PACKAGE}}`
      success: Installed GitHub release from `{{.PACKAGE}}`, available as `{{.BIN}}`
    cmds:
      - .config/log info "PATH variable --> $PATH"
      - task: :install:go:bin
      - mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/bin"
      - jq '. | .default_path = "./.bin" | .bins = {}' <<< $(echo '{}') > "${XDG_CONFIG_HOME:-$HOME/.config}/bin/config.json"
      - |
        if [ -n "$CI" ]; then echo "*************** GitHub --> {{.BIN}}"; fi
      - |
        if [ -z "$GOPATH" ]; then
          export GOPATH="$HOME/.local/go"
        fi
        export PATH="$PATH:$HOME/.local/go/bin"
        bin install -f {{.PACKAGE}} "$GOPATH/bin/{{.BIN}}"
    status:
      - type {{.BIN}} > /dev/null || [ -n "$NO_INSTALL_HOMEBREW" ]

  sentry:
    run: once
    cmds:
      - task: install:github
        vars:
          BIN_NAME: sentry-cli
          PACKAGE: github.com/getsentry/sentry-cli
