github.com/sacloud/iaas-api-go@v1.12.0/includes/go/common.mk (about)

     1  #
     2  # Copyright 2022-2023 The sacloud/makefile Authors
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #      http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  #
    16  
    17  AUTHOR                  ?= The sacloud/makefile Authors
    18  COPYRIGHT_YEAR          ?= 2023
    19  COPYRIGHT_FILES         ?= $$(find . -name "*.go" -print | grep -v "/vendor/")
    20  GO                      ?= go
    21  DEFAULT_GOALS           ?= fmt set-license go-licenses-check goimports lint test
    22  GOLANG_CI_LINT_VERSION  ?= v1.56.2
    23  TEXTLINT_ACTION_VERSION ?= v0.0.3
    24  
    25  .DEFAULT_GOAL = default
    26  
    27  .PHONY: test
    28  test:
    29  	@echo "running 'go test'..."
    30  	TESTACC= $(GO) test ./... $(TESTARGS) -v -timeout=120m -parallel=8 -race;
    31  
    32  .PHONY: testacc
    33  testacc:
    34  	@echo "running 'go test' with TESTACC=1..."
    35  	TESTACC=1 $(GO) test ./... $(TESTARGS) --tags=acctest -v -timeout=120m -parallel=8 ;
    36  
    37  .PHONY: dev-tools
    38  dev-tools:
    39  	$(GO) install github.com/rinchsan/gosimports/cmd/gosimports@latest
    40  	$(GO) install golang.org/x/tools/cmd/stringer@latest
    41  	$(GO) install github.com/sacloud/addlicense@latest
    42  	$(GO) install github.com/client9/misspell/cmd/misspell@latest
    43  	$(GO) install github.com/google/go-licenses@v1.0.0
    44  	$(GO) install github.com/rhysd/actionlint/cmd/actionlint@latest
    45  	curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin $(GOLANG_CI_LINT_VERSION)
    46  
    47  .PHONY: goimports
    48  goimports: fmt
    49  	@echo "running gosimports..."
    50  	@gosimports -l -w .
    51  
    52  .PHONY: fmt
    53  fmt:
    54  	@echo "running gofmt..."
    55  	@find . -name '*.go' | grep -v vendor | xargs gofmt -s -w
    56  
    57  .PHONY: godoc
    58  godoc:
    59  	godoc -http=localhost:6060
    60  
    61  .PHONY: lint
    62  lint: lint-go lint-text lint-action
    63  
    64  .PHONY: lint-go
    65  lint-go:
    66  	@echo "running golanci-lint..."
    67  	@golangci-lint run --fix ./...
    68  
    69  .PHONY: textlint lint-text
    70  textlint: lint-text
    71  lint-text:
    72  	@echo "running textlint..."
    73  	@docker run -t --rm -v $$PWD:/work -w /work ghcr.io/sacloud/textlint-action:$(TEXTLINT_ACTION_VERSION) .
    74  
    75  .PHONY: lint-action
    76  lint-action:
    77  	@echo "running rhysd/actionlint..."
    78  	@actionlint
    79  
    80  .PHONY: set-license
    81  set-license:
    82  	@addlicense -c "$(AUTHOR)" -y "$(COPYRIGHT_YEAR)" $(COPYRIGHT_FILES)
    83  
    84  .PHONY: go-licenses-check
    85  go-licenses-check:
    86  	@echo "running go-licenses..."
    87  	@go-licenses check .