github.com/SamarSidharth/kpt@v0.0.0-20231122062228-c7d747ae3ace/Makefile (about)

     1  # Copyright 2019 The kpt Authors
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #      http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  GOLANG_VERSION         := 1.21.1
    16  GORELEASER_CONFIG      = release/tag/goreleaser.yaml
    17  GORELEASER_IMAGE       := ghcr.io/goreleaser/goreleaser-cross:v$(GOLANG_VERSION)
    18  
    19  .PHONY: docs license fix vet fmt lint test build tidy release release-ci
    20  
    21  GOBIN := $(shell go env GOPATH)/bin
    22  GIT_COMMIT := $(shell git rev-parse --short HEAD)
    23  
    24  LDFLAGS := -ldflags "-X github.com/GoogleContainerTools/kpt/run.version=${GIT_COMMIT}
    25  ifeq ($(OS),Windows_NT)
    26  	# Do nothing
    27  else
    28      UNAME := $(shell uname -s)
    29      ifeq ($(UNAME),Linux)
    30          LDFLAGS += -extldflags '-z noexecstack'
    31      endif
    32  endif
    33  LDFLAGS += "
    34  
    35  # T refers to an e2e test case matcher. This enables running e2e tests
    36  # selectively.  For example,
    37  # To invoke e2e tests related to fnconfig, run:
    38  # make test-fn-render T=fnconfig
    39  # make test-fn-eval T=fnconfig
    40  # By default, make test-fn-render/test-fn-eval will run all tests.
    41  T ?= ".*"
    42  
    43  all: generate license fix vet fmt lint license-check test build tidy
    44  
    45  build:
    46  	go build ${LDFLAGS} -o $(GOBIN)/kpt -v .
    47  
    48  update-deps-to-head:
    49  	go get sigs.k8s.io/cli-utils@master
    50  	go get sigs.k8s.io/kustomize/kyaml@master
    51  
    52  .PHONY: install-mdrip
    53  install-mdrip:
    54  	go install github.com/monopole/mdrip@v1.0.2
    55  
    56  .PHONY: install-kind
    57  install-kind:
    58  	go install sigs.k8s.io/kind@v0.13.0
    59  
    60  .PHONY: install-golangci-lint
    61  install-golangci-lint:
    62  	go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2
    63  
    64  .PHONY: install-go-licenses
    65  install-go-licenses:
    66  	go install github.com/google/go-licenses@v1.2.0
    67  
    68  .PHONY: install-swagger
    69  install-swagger:
    70  	go install github.com/go-swagger/go-swagger/cmd/swagger@v0.27.0
    71  
    72  .PHONY: install-mdtogo
    73  install-mdtogo:
    74  	go install ./mdtogo
    75  
    76  fix:
    77  	go fix ./...
    78  
    79  fmt:
    80  	go fmt ./...
    81  
    82  schema:
    83  	GOBIN=$(GOBIN) scripts/generate-schema.sh
    84  
    85  generate: install-mdtogo
    86  	rm -rf internal/docs/generated
    87  	mkdir internal/docs/generated
    88  	GOBIN=$(GOBIN) go generate ./...
    89  	go fmt ./internal/docs/generated/...
    90  
    91  tidy:
    92  	go mod tidy
    93  
    94  license:
    95  	scripts/update-license.sh
    96  
    97  lint: install-golangci-lint
    98  	$(GOBIN)/golangci-lint run ./...
    99  
   100  license-check: install-go-licenses
   101  	$(GOBIN)/go-licenses check github.com/GoogleContainerTools/kpt
   102  
   103  test:
   104  	go test -cover ${LDFLAGS} ./...
   105  
   106  # This target is used to run Go tests that require docker runtime.
   107  # Some tests, like pipeline tests, need to have docker available to run.
   108  # KPT_FN_RUNTIME can be set to select the desired function runtime.
   109  # If unspecified, the default function runtime will be used.
   110  test-docker: build
   111  	PATH=$(GOBIN):$(PATH) go test -cover --tags=docker ./...
   112  
   113  # KPT_E2E_UPDATE_EXPECTED=true (if expected output to be updated)
   114  # target to run e2e tests for "kpt fn render" command
   115  # KPT_FN_RUNTIME can be set to select the desired function runtime.
   116  # If unspecified, the default function runtime will be used.
   117  test-fn-render: build
   118  	PATH=$(GOBIN):$(PATH) go test -v --tags=docker --run=TestFnRender/testdata/fn-render/$(T) ./e2e/
   119  
   120  # target to run e2e tests for "kpt fn eval" command
   121  # KPT_FN_RUNTIME can be set to select the desired function runtime.
   122  # If unspecified, the default function runtime will be used.
   123  test-fn-eval: build
   124  	PATH=$(GOBIN):$(PATH) go test -v --tags=docker --run=TestFnEval/testdata/fn-eval/$(T)  ./e2e/
   125  
   126  # target to run e2e tests for "kpt live apply" command
   127  test-live-apply: build
   128  	PATH=$(GOBIN):$(PATH) go test -v -timeout=20m --tags=kind -p 2 --run=TestLiveApply/testdata/live-apply/$(T)  ./e2e/
   129  
   130  # target to run e2e tests for "kpt live plan" command
   131  test-live-plan: build
   132  	PATH=$(GOBIN):$(PATH) go test -v -timeout=20m --tags=kind -p 2 --run=TestLivePlan/testdata/live-plan/$(T)  ./e2e/
   133  
   134  test-porch: build
   135  	PATH=$(GOBIN):$(PATH) go test -v --count=1 --tags=porch ./e2e/
   136  
   137  vet:
   138  	go vet ./...
   139  
   140  docker:
   141  	docker build .
   142  
   143  lintdocs:
   144  	(cd site && npm run lint-fix)
   145  
   146  site-generate:
   147  	go run ./scripts/generate_site_sidebar > site/sidebar.md
   148  	(cd site && find . -iname "00.md" -execdir ln -sf {} README.md \; && sed -i.bak s/00.md//g sidebar.md && rm sidebar.md.bak)
   149  
   150  site-map:
   151  	make site-run-server
   152  	./scripts/generate-sitemap.sh
   153  
   154  site-run-server:
   155  	make site-generate
   156  	./scripts/run-site.sh
   157  
   158  site-check:
   159  	make site-run-server
   160  	./scripts/check-site.sh
   161  
   162  site-verify-examples: install-mdrip install-kind
   163  	./scripts/verifyExamples.sh
   164  
   165  release-dry-run:
   166  	@docker run \
   167  		--rm \
   168  		--privileged \
   169  		-v /var/run/docker.sock:/var/run/docker.sock \
   170  		-v `pwd`:/go/src/github.com/GoogleContainerTools/kpt \
   171  		-w /go/src/github.com/GoogleContainerTools/kpt \
   172  		$(GORELEASER_IMAGE) \
   173  		-f "$(GORELEASER_CONFIG)" \
   174  		--skip-validate --skip-publish
   175  
   176  release:
   177  	@if [ ! -f ".release-env" ]; then \
   178  		echo "\033[91m.release-env is required for release\033[0m";\
   179  		exit 1;\
   180  	fi
   181  	docker run \
   182  		--rm \
   183  		--privileged \
   184  		--env-file .release-env \
   185  		-v /var/run/docker.sock:/var/run/docker.sock \
   186  		-v `pwd`:/go/src/github.com/GoogleContainerTools/kpt \
   187  		-w /go/src/github.com/GoogleContainerTools/kpt \
   188  		$(GORELEASER_IMAGE) \
   189  		-f "$(GORELEASER_CONFIG)" release \
   190  		--skip-validate
   191  
   192  release-ci:
   193  	@if [ ! -f ".release-env" ]; then \
   194  		echo "\033[91m.release-env is required for release\033[0m";\
   195  		exit 1;\
   196  	fi
   197  	docker run \
   198  		--rm \
   199  		--privileged \
   200  		--env-file .release-env \
   201  		-v ${HOME}/.docker/config.json:/root/.docker/config.json \
   202  		-v /var/run/docker.sock:/var/run/docker.sock \
   203  		-v `pwd`:/go/src/github.com/GoogleContainerTools/kpt \
   204  		-w /go/src/github.com/GoogleContainerTools/kpt \
   205  		$(GORELEASER_IMAGE) \
   206  		-f "$(GORELEASER_CONFIG)" release \
   207  		--skip-validate
   208  
   209  .PHONY: vulncheck
   210  vulncheck: build
   211  	# Scan the source
   212  	GOFLAGS= go run golang.org/x/vuln/cmd/govulncheck@latest ./...