distributable:
  url: git+https://github.com/pulumi/pulumi.git
  ref: ${{version.tag}}

versions:
  github: pulumi/pulumi
  strip: /v/

provides:
  - bin/pulumi
  - bin/pulumi-analyzer-policy
  - bin/pulumi-analyzer-policy-python
  - bin/pulumi-language-dotnet
  - bin/pulumi-language-go
  - bin/pulumi-language-java
  - bin/pulumi-language-nodejs
  - bin/pulumi-language-python
  - bin/pulumi-language-python-exec
  - bin/pulumi-language-yaml
  - bin/pulumi-resource-pulumi-nodejs
  - bin/pulumi-resource-pulumi-python
  - bin/pulumi-watch

dependencies:
  curl.se/ca-certs: '*'

build:
  dependencies:
    go.dev: ^1.20
    classic.yarnpkg.com: '*'
    nodejs.org: '*'
  script:
    - run: go mod download
      working-directory: sdk

    - run: go mod download
      working-directory: pkg

    # needs this fix to prevent segfaults
    - run: sed -i 's/-ldflags "/-ldflags "-buildmode=pie /' */Makefile
      working-directory: sdk

    - run: |
        for DIR in go nodejs python; do
          make -C $DIR install_plugin PULUMI_BIN={{prefix}}/bin
        done
      working-directory: sdk

    # The next steps are modified from scripts/brew.sh
    - run: go build
        -ldflags "$GO_LDFLAGS"
        -o {{prefix}}/bin/pulumi ./cmd/pulumi
      working-directory: pkg

    - ./scripts/prep-for-goreleaser.sh "local"
    - cp -a bin/$(go env GOOS)*/* {{prefix}}/bin/

    # - mkdir -p {{prefix}}/bin
    # - mv build/bin/pulumi* {{prefix}}/bin/

    # Install shell completions
    # TODO: Doesn't work for zsh. Should it be left up to user?
    # {{prefix}}/bin/pulumi gen-completion $SHELL
  env:
    GOPATH: '$PWD/build'
    GO_LDFLAGS:
      - -X github.com/pulumi/pulumi/pkg/v3/version.Version={{version}}
    linux:
      GO_LDFLAGS:
        - -buildmode=pie

test:
  script:
    - pulumi new aws-typescript --generate-only --force -y
    - test -e Pulumi.yaml
  env:
    PULUMI_ACCESS_TOKEN: local://
    PULUMI_TEMPLATE_PATH: '$PWD/templates'
