github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/Makefile (about)

     1  VERSION?="0.3.32"
     2  TEST?=./...
     3  GOFMT_FILES?=$$(find . -not -path "./vendor/*" -type f -name '*.go')
     4  WEBSITE_REPO=github.com/hashicorp/terraform-website
     5  
     6  default: test
     7  
     8  # bin generates the releaseable binaries for Terraform
     9  bin: fmtcheck generate
    10  	@TF_RELEASE=1 sh -c "'$(CURDIR)/scripts/build.sh'"
    11  
    12  # dev creates binaries for testing Terraform locally. These are put
    13  # into ./bin/ as well as $GOPATH/bin
    14  dev: fmtcheck generate
    15  	go install -mod=vendor .
    16  
    17  quickdev: generate
    18  	go install -mod=vendor .
    19  
    20  # Shorthand for building and installing just one plugin for local testing.
    21  # Run as (for example): make plugin-dev PLUGIN=provider-aws
    22  plugin-dev: generate
    23  	go install github.com/hashicorp/terraform/builtin/bins/$(PLUGIN)
    24  	mv $(GOPATH)/bin/$(PLUGIN) $(GOPATH)/bin/terraform-$(PLUGIN)
    25  
    26  # test runs the unit tests
    27  # we run this one package at a time here because running the entire suite in
    28  # one command creates memory usage issues when running in Travis-CI.
    29  test: fmtcheck generate
    30  	go list -mod=vendor $(TEST) | xargs -t -n4 go test $(TESTARGS) -mod=vendor -timeout=2m -parallel=4
    31  
    32  # testacc runs acceptance tests
    33  testacc: fmtcheck generate
    34  	@if [ "$(TEST)" = "./..." ]; then \
    35  		echo "ERROR: Set TEST to a specific package. For example,"; \
    36  		echo "  make testacc TEST=./builtin/providers/test"; \
    37  		exit 1; \
    38  	fi
    39  	TF_ACC=1 go test $(TEST) -v $(TESTARGS) -mod=vendor -timeout 120m
    40  
    41  # e2etest runs the end-to-end tests against a generated Terraform binary
    42  # and a generated terraform-bundle binary.
    43  # The TF_ACC here allows network access, but does not require any special
    44  # credentials.
    45  e2etest: generate
    46  	TF_ACC=1 go test -mod=vendor -v ./command/e2etest
    47  	TF_ACC=1 go test -mod=vendor -v ./tools/terraform-bundle/e2etest
    48  
    49  test-compile: fmtcheck generate
    50  	@if [ "$(TEST)" = "./..." ]; then \
    51  		echo "ERROR: Set TEST to a specific package. For example,"; \
    52  		echo "  make test-compile TEST=./builtin/providers/test"; \
    53  		exit 1; \
    54  	fi
    55  	go test -mod=vendor -c $(TEST) $(TESTARGS)
    56  
    57  # testrace runs the race checker
    58  testrace: fmtcheck generate
    59  	TF_ACC= go test -mod=vendor -race $(TEST) $(TESTARGS)
    60  
    61  cover:
    62  	go test $(TEST) -coverprofile=coverage.out
    63  	go tool cover -html=coverage.out
    64  	rm coverage.out
    65  
    66  # generate runs `go generate` to build the dynamically generated
    67  # source files, except the protobuf stubs which are built instead with
    68  # "make protobuf".
    69  generate:
    70  	GOFLAGS=-mod=vendor go generate ./...
    71  	# go fmt doesn't support -mod=vendor but it still wants to populate the
    72  	# module cache with everything in go.mod even though formatting requires
    73  	# no dependencies, and so we're disabling modules mode for this right
    74  	# now until the "go fmt" behavior is rationalized to either support the
    75  	# -mod= argument or _not_ try to install things.
    76  	GO111MODULE=off go fmt command/internal_plugin_list.go > /dev/null
    77  
    78  # We separate the protobuf generation because most development tasks on
    79  # Terraform do not involve changing protobuf files and protoc is not a
    80  # go-gettable dependency and so getting it installed can be inconvenient.
    81  #
    82  # If you are working on changes to protobuf interfaces you may either use
    83  # this target or run the individual scripts below directly.
    84  protobuf:
    85  	bash scripts/protobuf-check.sh
    86  	bash internal/tfplugin5/generate.sh
    87  	bash plans/internal/planproto/generate.sh
    88  
    89  fmt:
    90  	gofmt -w $(GOFMT_FILES)
    91  
    92  fmtcheck:
    93  	@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
    94  
    95  website:
    96  ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
    97  	echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
    98  	git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
    99  endif
   100  	$(eval WEBSITE_PATH := $(GOPATH)/src/$(WEBSITE_REPO))
   101  	@echo "==> Starting core website in Docker..."
   102  	@docker run \
   103  		--interactive \
   104  		--rm \
   105  		--tty \
   106  		--publish "4567:4567" \
   107  		--publish "35729:35729" \
   108  		--volume "$(shell pwd)/website:/website" \
   109  		--volume "$(shell pwd):/ext/terraform" \
   110  		--volume "$(WEBSITE_PATH)/content:/terraform-website" \
   111  		--volume "$(WEBSITE_PATH)/content/source/assets:/website/docs/assets" \
   112  		--volume "$(WEBSITE_PATH)/content/source/layouts:/website/docs/layouts" \
   113  		--workdir /terraform-website \
   114  		hashicorp/middleman-hashicorp:${VERSION}
   115  
   116  website-test:
   117  ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
   118  	echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
   119  	git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
   120  endif
   121  	$(eval WEBSITE_PATH := $(GOPATH)/src/$(WEBSITE_REPO))
   122  	@echo "==> Testing core website in Docker..."
   123  	-@docker stop "tf-website-core-temp"
   124  	@docker run \
   125  		--detach \
   126  		--rm \
   127  		--name "tf-website-core-temp" \
   128  		--publish "4567:4567" \
   129  		--volume "$(shell pwd)/website:/website" \
   130  		--volume "$(shell pwd):/ext/terraform" \
   131  		--volume "$(WEBSITE_PATH)/content:/terraform-website" \
   132  		--volume "$(WEBSITE_PATH)/content/source/assets:/website/docs/assets" \
   133  		--volume "$(WEBSITE_PATH)/content/source/layouts:/website/docs/layouts" \
   134  		--workdir /terraform-website \
   135  		hashicorp/middleman-hashicorp:${VERSION}
   136  	$(WEBSITE_PATH)/content/scripts/check-links.sh "http://127.0.0.1:4567" "/" "/docs/providers/*"
   137  	@docker stop "tf-website-core-temp"
   138  
   139  # disallow any parallelism (-j) for Make. This is necessary since some
   140  # commands during the build process create temporary files that collide
   141  # under parallel conditions.
   142  .NOTPARALLEL:
   143  
   144  .PHONY: bin cover default dev e2etest fmt fmtcheck generate protobuf plugin-dev quickdev test-compile test testacc testrace vendor-status website website-test