distributable:
  url: https://github.com/mvdan/sh/archive/refs/tags/{{ version.tag }}.tar.gz
  strip-components: 1

versions:
  github: mvdan/sh

provides:
  - bin/shfmt

build:
  dependencies:
    go.dev: ^1.21
  script:
    - go mod download
    - go build -v -trimpath -ldflags="$GO_LDFLAGS" -o '{{prefix}}/bin/shfmt' ./cmd/shfmt
  env:
    GO_LDFLAGS:
      - -s
      - -w
      - -X main.version=v{{version}}
    linux:
      # or segmentation fault
      # fix found here https://github.com/docker-library/golang/issues/402#issuecomment-982204575
      LDFLAGS:
        - -buildmode=pie

test:
  - test "$(shfmt --version)" = "v{{version}}"
  - run: test "$(echo 'echo "hello world"; echo 42' | shfmt)" = "$(cat $FIXTURE)"
    fixture: |
      echo "hello world"
      echo 42
