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

versions:
  github: encoredev/encore

provides:
  - bin/encore
  - bin/git-remote-encore

runtime:
  env:
    ENCORE_RUNTIME_PATH: ${{prefix}}/runtime
    # https://github.com/encoredev/encore/pull/894
    ENCORE_RUNTIMES_PATH: ${{prefix}}/runtimes

dependencies:
  encore.dev/go: ^1.21

build:
  script:
    - go mod download
    - go build $ARGS -ldflags="$LDFLAGS" -o "{{prefix}}"/bin/encore ./cli/cmd/encore
    - go build $ARGS -ldflags="$LDFLAGS" -o "{{prefix}}"/bin/git-remote-encore ./cli/cmd/git-remote-encore
    - run: cp -a runtime "{{prefix}}"
      if: <1.28.0
    - run: |
        cp -a runtimes "{{prefix}}"
        ln -s runtimes/go "{{prefix}}/runtime"
      if: '>=1.28.0'
  env:
    GO111MODULE: on
    ARGS:
      - -v
      - -trimpath
    LDFLAGS:
      - -s
      - -w
      - -X 'encr.dev/internal/version.Version={{version}}'
    linux:
      # or segmentation fault
      # fix found here https://github.com/docker-library/golang/issues/402#issuecomment-982204575
      LDFLAGS:
      - -buildmode=pie

test:
  # test errors checking update api; looks like it still runs fine.
  - (encore version || true) | grep {{version}}
