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

versions:
  github: twpayne/chezmoi/tags
  strip: /v/

provides:
  - bin/chezmoi

build:
  script: |
    go build -v -ldflags="$LDFLAGS"
    mkdir -p "{{ prefix }}"/bin
    mv chezmoi "{{ prefix }}"/bin
  dependencies:
    go.dev: ^1.18
    linux:
      gnu.org/gcc: "*"
      gnu.org/binutils: "*" # for `as`
  env:
    LDFLAGS:
      - -s
      - -w
      - -X main.version={{ version }}
      - -X main.revision=tea
    linux:
      # or segmentation fault
      # fix found here https://github.com/docker-library/golang/issues/402#issuecomment-982204575
      LDFLAGS:
        - -buildmode=pie

test:
  script: |
    export HOME=$(pwd)
    touch .bashrc
    chezmoi -S .chezmoi init
    chezmoi -S .chezmoi add .bashrc
    ls -la .chezmoi
    test -f .chezmoi/empty_dot_bashrc
