github.com/fastly/go-fastly/v6@v6.8.0/Makefile (about)

     1  SHELL := /bin/bash -o pipefail
     2  
     3  # List of tests to run
     4  FILES ?= ./...
     5  
     6  # List all our actual files, excluding vendor
     7  GOPKGS ?= $(shell go list $(FILES) | grep -v /vendor/)
     8  GOFILES ?= $(shell find . -name '*.go' | grep -v /vendor/)
     9  
    10  # Tags specific for building
    11  GOTAGS ?=
    12  
    13  # Number of procs to use
    14  GOMAXPROCS ?= 4
    15  
    16  NAME := $(notdir $(shell pwd))
    17  
    18  # Test Service ID
    19  FASTLY_TEST_SERVICE_ID ?=
    20  FASTLY_API_KEY ?=
    21  #
    22  # Enables support for tools such as https://github.com/rakyll/gotest
    23  TEST_COMMAND ?= go test
    24  
    25  all: mod-download dev-dependencies tidy fmt fiximports test vet staticcheck ## Runs all of the required cleaning and verification targets.
    26  .PHONY: all
    27  
    28  tidy: ## Cleans the Go module.
    29  	@echo "==> Tidying module"
    30  	@go mod tidy
    31  .PHONY: tidy
    32  
    33  mod-download: ## Downloads the Go module.
    34  	@echo "==> Downloading Go module"
    35  	@go mod download
    36  .PHONY: mod-download
    37  
    38  dev-dependencies: ## Downloads the necessesary dev dependencies.
    39  	@echo "==> Downloading development dependencies"
    40  	@go install honnef.co/go/tools/cmd/staticcheck
    41  	@go install golang.org/x/tools/cmd/goimports
    42  .PHONY: dev-dependencies
    43  
    44  test: ## Runs the test suite with VCR mocks enabled.
    45  	@echo "==> Testing ${NAME}"
    46  	@$(TEST_COMMAND) -timeout=30s -parallel=20 -tags="${GOTAGS}" ${GOPKGS} ${TESTARGS}
    47  .PHONY: test
    48  
    49  test-race: ## Runs the test suite with the -race flag to identify race conditions, if they exist.
    50  	@echo "==> Testing ${NAME} (race)"
    51  	@$(TEST_COMMAND) -timeout=60s -race -tags="${GOTAGS}" ${GOPKGS} ${TESTARGS}
    52  .PHONY: test-race
    53  
    54  test-full: ## Runs the tests with VCR disabled (i.e., makes external calls).
    55  	@echo "==> Testing ${NAME} with VCR disabled"
    56  	@VCR_DISABLE=1 \
    57  		bash -c \
    58  		'go test -timeout=60s -parallel=20 ${GOPKGS} ${TESTARGS}'
    59  .PHONY: test-full
    60  
    61  fix-fixtures: ## Updates test fixtures with a specified default service ID.
    62  	@echo "==> Updating fixtures"
    63  	@$(shell pwd)/scripts/fixFixtures.sh ${FASTLY_TEST_SERVICE_ID}
    64  .PHONY: fix-fixtures
    65  
    66  check-imports: ## A check which lists improperly-formatted imports, if they exist.
    67  	@$(shell pwd)/scripts/check-imports.sh
    68  .PHONY: check-imports
    69  
    70  check-fmt: ## A check which lists improperly-formatted files, if they exist.
    71  	@$(shell pwd)/scripts/check-gofmt.sh
    72  .PHONY: check-fmt
    73  
    74  check-mod: ## A check which lists extraneous dependencies, if they exist.
    75  	@$(shell pwd)/scripts/check-mod.sh
    76  .PHONY: check-mod
    77  
    78  fiximports: ## Properly formats and orders imports.
    79  	@echo "==> Fixing imports"
    80  	@goimports -w {fastly,tools}
    81  .PHONY: fiximports
    82  
    83  fmt: ## Properly formats Go files and orders dependencies.
    84  	@echo "==> Running gofmt"
    85  	@gofmt -s -w ${GOFILES}
    86  .PHONY: fmt
    87  
    88  vet: ## Identifies common errors.
    89  	@echo "==> Running go vet"
    90  	@go vet ./...
    91  .PHONY: vet
    92  
    93  staticcheck: ## Runs the staticcheck linter.
    94  	@echo "==> Running staticcheck"
    95  	@staticcheck ./...
    96  .PHONY: staticcheck
    97  
    98  .PHONY: help
    99  help: ## Prints this help menu.
   100  	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'