distributable:
  url: https://gitlab.com/gitlab-org/cli/-/archive/v{{version}}/cli-v{{version}}.tar.gz
  strip-components: 1

versions:
  gitlab: gitlab-org/cli/tags

provides:
  - bin/glab

build:
  script: |
    go mod download
    mkdir -p "{{ prefix }}"/bin
    go build -v -trimpath -ldflags="$LDFLAGS" -o $BUILDLOC ./cmd/glab
  dependencies:
    go.dev: ^1.18
  env:
    GO111MODULE: 'on'
    BUILDLOC: '{{prefix}}/bin/glab'
    LDFLAGS:
      - -s
      - -w
      - -X main.version={{version}}
      - -X main.debugMode=false

    linux:
      # or segmentation fault
      # fix found here https://github.com/docker-library/golang/issues/402#issuecomment-982204575
      LDFLAGS:
      - -buildmode=pie

test:
  dependencies:
    git-scm.org: '*'
  script: |
    git clone https://gitlab.com/cli-automated-testing/homebrew-testing.git
    cd homebrew-testing
    glab repo contributors | grep "Matt Nohr"
    glab issue list --all | grep "This is a test issue"
    glab --version | grep "glab version {{version}}"
