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

versions:
  github: hasura/graphql-engine

provides:
  - bin/hasura

build:
  # I copied the brew formula here --mxcl
  # NOTE there is a `Makefile`, possibly not using it is asking for trouble
  script:
    - working-directory: cli-ext
      run:
        - npm update pkg  # see https://github.com/hasura/graphql-engine/issues/9440
        - |
          npm install --global --build-from-source --prefix={{prefix}}
          npm run prebuild
          node_modules/.bin/pkg ./build/command.js --output ./bin/cli-ext-hasura -t host

    - working-directory: cli
      run: |
        cp ../cli-ext/bin/cli-ext-hasura internal/cliext/static-bin/$PLATFORM/cli-ext
        go build -v -ldflags="$LDFLAGS" -o="{{prefix}}/bin/hasura" ./cmd/hasura

  dependencies:
    go.dev: ^1.16
    npmjs.com: ^8.19.4
    gnu.org/coreutils: '*'
    nodejs.org: ^18  # fails with ^20
  env:
    darwin/aarch64: {PLATFORM: darwin/arm64}
    darwin/x86-64:  {PLATFORM: darwin/amd64}
    linux/aarch64:  {PLATFORM: linux/arm64}
    linux/x86-64:   {PLATFORM: linux/amd64}
    LDFLAGS:
      - -s
      - -w
      - -X github.com/hasura/graphql-engine/cli/v2/version.BuildVersion={{version}}
      - -X github.com/hasura/graphql-engine/cli/v2/plugins.IndexBranchRef=master
    linux:
      # or segmentation fault
      # fix found here https://github.com/docker-library/golang/issues/402#issuecomment-982204575
      LDFLAGS:
      - -buildmode=pie

test: |
  hasura --skip-update-check version | grep {{version}}
  hasura init testdir
