pulumi/sdk/python/Makefile
Paul Stack 1d3c9edb6c
Ensure that make brew works as expected rather than passing empty version (#6566)
Fixes:#6565

As part of #6460, the logic for determing the version of the build was
moved to be a dependency on pulumictl.

Unfortunately, the homebrew installs use the "make dist" command to
build + install Pulumi to the user maching and as that would have a
dependency on pulumictl and it not existing on the user machine, it
would pass an empty version to the ldflag

This then manifested to the user as:

```
▶ pulumi version
warning: A new version of Pulumi is available. To upgrade from version '0.0.0' to '2.22.0', run
   $ brew upgrade pulumi
or visit https://pulumi.com/docs/reference/install/ for manual instructions and release notes.
```

We are able to mitigate this behaviour by bringing back the get-version
script and using that script as part of the make brew installation

We can see that the versions are the same between the 2 different
installation techniques

```
make dist <------- uses pulumict
DIST:
go install -ldflags "-X github.com/pulumi/pulumi/sdk/v2/go/common/version.Version=2.24.0-alpha.1616029310+787eb70a" github.com/pulumi/pulumi/sdk/v2/dotnet/cmd/pulumi-language-dotnet
DIST:
BUILD:
```

```
make brew <----- uses the legacy script
▶ make brew
BREW:
go install -ldflags "-X github.com/pulumi/pulumi/sdk/v2/go/common/version.Version=v2.24.0-alpha.1616029310+g787eb70a2" github.com/pulumi/pulumi/sdk/v2/dotnet/cmd/pulumi-language-dotnet
BREW:
```

A full post mortem will be carried out to ensure we mitigate these
types of errors going forward and that we are able to better test
these types of situations
2021-03-18 02:07:02 +00:00

74 lines
2.8 KiB
Makefile

PROJECT_NAME := Pulumi Python SDK
LANGHOST_PKG := github.com/pulumi/pulumi/sdk/v2/python/cmd/pulumi-language-python
VERSION := $(shell cd ../../ && pulumictl get version)
PYPI_VERSION := $(shell cd ../../ && pulumictl get version --language python)
PYENV := ./env
PYENVSRC := $(PYENV)/src
PROJECT_PKGS := $(shell go list ./cmd/...)
TESTPARALLELISM := 10
include ../../build/common.mk
ensure::
pipenv install --dev
mkdir -p $(PYENVSRC)
build_package::
rm -rf $(PYENVSRC) && cp -R ./lib/. $(PYENVSRC)/
sed -i.bak "s/\$${VERSION}/$(PYPI_VERSION)/g" $(PYENVSRC)/setup.py && rm $(PYENVSRC)/setup.py.bak
cp ../../README.md $(PYENVSRC)
cd $(PYENVSRC) && pipenv run python setup.py build bdist_wheel --universal
build_plugin::
go install -ldflags "-X github.com/pulumi/pulumi/sdk/v2/go/common/version.Version=${VERSION}" ${LANGHOST_PKG}
build:: build_package build_plugin
lint::
pipenv run mypy ./lib/pulumi --config-file=mypy.ini
pipenv run pylint ./lib/pulumi --rcfile=.pylintrc
install_package:: build_package
cp ./cmd/pulumi-language-python-exec "$(PULUMI_BIN)"
cp ./dist/pulumi-resource-pulumi-python "$(PULUMI_BIN)"
cp ./dist/pulumi-analyzer-policy-python "$(PULUMI_BIN)"
install_plugin:: build_plugin
GOBIN=$(PULUMI_BIN) go install \
-ldflags "-X github.com/pulumi/pulumi/sdk/v2/go/common/version.Version=${VERSION}" ${LANGHOST_PKG}
install:: install_package install_plugin
test_fast:: build
go test -count=1 -cover -parallel ${TESTPARALLELISM} ${PROJECT_PKGS}
pipenv run pip install ./env/src
# TODO the ignored test seems to fail in pytest but not unittest. Need to trackdown why
pipenv run pytest lib/test --ignore lib/test/langhost/resource_thens/test_resource_thens.py
pipenv run python -m unittest lib/test/langhost/resource_thens/test_resource_thens.py
# Using python -m also adds lib/test_with_mocks to sys.path which avoids package resolution issues.
pushd lib/test_with_mocks ; pipenv run python -m pytest ; popd
test_all:: test_fast
dist::
go install -ldflags "-X github.com/pulumi/pulumi/sdk/v2/go/common/version.Version=${VERSION}" ${LANGHOST_PKG}
cp ./cmd/pulumi-language-python-exec "$$(go env GOPATH)"/bin/
cp ./dist/pulumi-resource-pulumi-python "$$(go env GOPATH)"/bin/
cp ./dist/pulumi-analyzer-policy-python "$$(go env GOPATH)"/bin/
brew:: BREW_VERSION := $(shell ../../scripts/get-version HEAD)
brew::
go install -ldflags "-X github.com/pulumi/pulumi/sdk/v2/go/common/version.Version=${BREW_VERSION}" ${LANGHOST_PKG}
cp ./cmd/pulumi-language-python-exec "$$(go env GOPATH)"/bin/
cp ./dist/pulumi-resource-pulumi-python "$$(go env GOPATH)"/bin/
cp ./dist/pulumi-analyzer-policy-python "$$(go env GOPATH)"/bin/
publish:: build_package
twine upload \
-u pulumi -p "${PYPI_PASSWORD}" \
"env/src/dist"/*.whl \
--skip-existing \
--verbose