distributable:
  url: https://github.com/jesseduffield/horcrux/archive/refs/tags/v{{version.raw}}.tar.gz
  strip-components: 1

versions:
  github: jesseduffield/horcrux/tags
  strip: /^v/

provides:
  - bin/horcrux

build:
  dependencies:
    go.dev: ^1.14
  script:
    - go mod download
    # Bug in split.go that prevents it from splitting
    - run: |
        sed -i.bak 's/Split(path, path, total, threshold)/Split(path, filepath.Dir(path), total, threshold)/' split.go
        rm split.go.bak
      working-directory: pkg/commands
    - go build -v -trimpath -ldflags="$LDFLAGS" -o $BUILDLOC .
  env:
    GOPROXY: https://proxy.golang.org,direct
    GOSUMDB: sum.golang.org
    GO111MODULE: on
    CGO_ENABLED: 0
    BUILDLOC: '{{prefix}}/bin/horcrux'
    LDFLAGS:
      - -s
      - -w
    linux:
      # or segmentation fault
      # fix found here https://github.com/docker-library/golang/issues/402#issuecomment-982204575
      LDFLAGS:
        - -buildmode=pie

test:
  fixture: packages by tea
  script:
    - cp $FIXTURE tea.txt
    - horcrux -t 3 -n 5 split tea.txt
    - rm tea.txt tea_1_of_5.horcrux tea_4_of_5.horcrux
    - horcrux bind
    - cmp tea.txt $FIXTURE
