github.com/fastly/cli@v1.7.2-0.20240304164155-9d0f1d77c3bf/Makefile (about)

     1  .PHONY: clean
     2  
     3  SHELL := /usr/bin/env bash -o pipefail ## Set the shell to use for finding Go files (default: /bin/bash)
     4  
     5  
     6  # Compile program (implicit default target).
     7  #
     8  # GO_ARGS allows for passing additional arguments.
     9  # e.g. make build GO_ARGS='--ldflags "-s -w"'
    10  .PHONY: build
    11  build: config ## Compile program (CGO disabled)
    12  	CGO_ENABLED=0 $(GO_BIN) build $(GO_ARGS) ./cmd/fastly
    13  
    14  GO_BIN ?= go ## Allows overriding go executable.
    15  TEST_COMMAND ?= $(GO_BIN) test ## Enables support for tools such as https://github.com/rakyll/gotest
    16  TEST_ARGS ?= -v -timeout 15m ./... ## The compute tests can sometimes exceed the default 10m limit
    17  
    18  GOHOSTOS ?= $(shell go env GOHOSTOS || echo unknown)
    19  GOHOSTARCH ?= $(shell go env GOHOSTARCH || echo unknown)
    20  
    21  ifeq ($(OS), Windows_NT)
    22  	SHELL = cmd.exe
    23  	.SHELLFLAGS = /c
    24  	GO_FILES = $(shell where /r pkg *.go)
    25  	GO_FILES += $(shell where /r cmd *.go)
    26  	CONFIG_SCRIPT = scripts\config.sh
    27  	CONFIG_FILE = pkg\config\config.toml
    28  else
    29  	GO_FILES = $(shell find cmd pkg -type f -name '*.go')
    30  	CONFIG_SCRIPT = ./scripts/config.sh
    31  	CONFIG_FILE = pkg/config/config.toml
    32  endif
    33  
    34  # Build executables using goreleaser (useful for local testing purposes).
    35  #
    36  # You can pass flags to goreleaser via GORELEASER_ARGS
    37  # --clean will save you deleting the dist dir
    38  # --single-target will be quicker and only build for your os & architecture
    39  # --skip=post-hooks which prevents errors such as trying to execute the binary for each OS (e.g. we call scripts/documentation.sh and we can't run Windows exe on a Mac).
    40  # --skip=validate will skip the checks (e.g. git tag checks which result in a 'dirty git state' error)
    41  #
    42  # EXAMPLE:
    43  # make release GORELEASER_ARGS="--clean --skip=post-hooks --skip=validate"
    44  release: dependencies $(GO_FILES) ## Build executables using goreleaser
    45  	@GOHOSTOS="${GOHOSTOS}" GOHOSTARCH="${GOHOSTARCH}" goreleaser build ${GORELEASER_ARGS}
    46  
    47  # Useful for attaching a debugger such as https://github.com/go-delve/delve
    48  debug:
    49  	@$(GO_BIN) build -gcflags="all=-N -l" $(GO_ARGS) -o "fastly" ./cmd/fastly
    50  
    51  .PHONY: config
    52  config:
    53  	@$(CONFIG_SCRIPT)
    54  
    55  .PHONY: all
    56  all: config dependencies tidy fmt vet staticcheck gosec semgrep test build install ## Run EVERYTHING!
    57  
    58  # Update CI tools used by ./.github/workflows/pr_test.yml
    59  .PHONY: dependencies
    60  dependencies:
    61  	@while read -r line || [ -n "$$line" ]; do \
    62  		$(GO_BIN) install $$line; \
    63  	done < .github/dependencies.txt
    64  	@if [ "$$(uname)" = 'Darwin' ]; then \
    65  			if ! command -v semgrep &> /dev/null; then \
    66  					brew install semgrep; \
    67  			fi \
    68  	fi
    69  
    70  # Clean up Go modules file.
    71  .PHONY: tidy
    72  tidy:
    73  	$(GO_BIN) mod tidy
    74  
    75  # Run formatter.
    76  .PHONY: fmt
    77  fmt:
    78  	@echo gofmt -l ./{cmd,pkg}
    79  	@eval "bash -c 'F=\$$(gofmt -l ./{cmd,pkg}) ; if [[ \$$F ]] ; then echo \$$F ; exit 1 ; fi'"
    80  
    81  # Run static analysis.
    82  .PHONY: vet
    83  vet: config ## Run vet static analysis
    84  	$(GO_BIN) vet ./{cmd,pkg}/...
    85  
    86  # Run linter.
    87  .PHONY: revive
    88  revive: ## Run linter (using revive)
    89  	revive ./...
    90  
    91  # Run security vulnerability checker.
    92  .PHONY: gosec
    93  gosec: ## Run security vulnerability checker
    94  	gosec -quiet -exclude=G104 ./{cmd,pkg}/...
    95  
    96  nilaway: ## Run nilaway
    97  	@nilaway ./...
    98  
    99  # Run semgrep checker.
   100  # NOTE: We can only exclude the import-text-template rule via a semgrep CLI flag
   101  .PHONY: semgrep
   102  semgrep: ## Run semgrep
   103  	@if [ '$(SEMGREP_SKIP)' != 'true' ]; then \
   104  		if command -v semgrep &> /dev/null; then semgrep ci --config auto --exclude-rule go.lang.security.audit.xss.import-text-template.import-text-template $(SEMGREP_ARGS); fi \
   105  	fi
   106  
   107  # Run third-party static analysis.
   108  # To ignore lines use: //lint:ignore <CODE> <REASON>
   109  .PHONY: staticcheck
   110  staticcheck: ## Run static analysis
   111  	staticcheck ./{cmd,pkg}/...
   112  
   113  .PHONY: golangci
   114  golangci: ## Run golangci-lint
   115  	golangci-lint run --verbose
   116  
   117  # Run tests
   118  .PHONY: test
   119  test: config ## Run tests (with race detection)
   120  	@$(TEST_COMMAND) -race $(TEST_ARGS)
   121  
   122  # Compile and install program.
   123  #
   124  # GO_ARGS allows for passing additional arguments.
   125  .PHONY: install
   126  install: config ## Compile and install program
   127  	CGO_ENABLED=0 $(GO_BIN) install $(GO_ARGS) ./cmd/fastly
   128  
   129  # Scaffold a new CLI command from template files.
   130  .PHONY: scaffold
   131  scaffold:
   132  	@$(shell pwd)/scripts/scaffold.sh $(CLI_PACKAGE) $(CLI_COMMAND) $(CLI_API)
   133  
   134  # Scaffold a new CLI 'category' command from template files.
   135  .PHONY: scaffold-category
   136  scaffold-category:
   137  	@$(shell pwd)/scripts/scaffold-category.sh $(CLI_CATEGORY) $(CLI_CATEGORY_COMMAND) $(CLI_PACKAGE) $(CLI_COMMAND) $(CLI_API)
   138  
   139  # Graph generates a call graph that focuses on the specified package.
   140  # Output is callvis.svg
   141  # e.g. make graph PKG_IMPORT_PATH=github.com/fastly/cli/pkg/commands/kvstoreentry
   142  .PHONY: graph
   143  graph: ## Graph generates a call graph that focuses on the specified package
   144  	@$(GO_BIN) install github.com/ofabry/go-callvis@latest 2>/dev/null
   145  	go-callvis -file "callvis" -focus "$(PKG_IMPORT_PATH)" ./cmd/fastly/
   146  	@rm callvis.gv
   147  
   148  .PHONY: help
   149  help:
   150  	@printf "Targets\n"
   151  	@(grep -h -E '^[0-9a-zA-Z_.-]+:.*?## .*$$' $(MAKEFILE_LIST) || true) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-22s\033[0m %s\n", $$1, $$2}'
   152  	@printf "\nDefault target\n"
   153  	@printf "\033[36m%s\033[0m" $(.DEFAULT_GOAL)
   154  	@printf "\n\nMake Variables\n"
   155  	@(grep -h -E '^[0-9a-zA-Z_.-]+\s[:?]?=.*? ## .*$$' $(MAKEFILE_LIST) || true) | sort | awk 'BEGIN {FS = "[:?]?=.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'