|
| 1 | +# Copyright 2025 Flant JSC |
| 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 | +SHELL = /usr/bin/env bash |
| 16 | + |
| 17 | +GOLANGCI_VERSION = 2.7.2 |
| 18 | +GOFUMPT_VERSION=0.9.2 |
| 19 | +JQ_VERSION=1.7.1 |
| 20 | + |
| 21 | +PLATFORM_NAME := $(shell uname -m) |
| 22 | + |
| 23 | +OS_NAME := $(shell uname) |
| 24 | +ifndef OS |
| 25 | + ifeq ($(UNAME), Linux) |
| 26 | + OS = linux |
| 27 | + else ifeq ($(UNAME), Darwin) |
| 28 | + OS = darwin |
| 29 | + endif |
| 30 | +endif |
| 31 | + |
| 32 | +# Set platform for deps |
| 33 | +ifeq ($(OS_NAME), Linux) |
| 34 | + GOFUMPT_PLATFORM = linux |
| 35 | + JQ_PLATFORM = linux |
| 36 | +else ifeq ($(OS_NAME), Darwin) |
| 37 | + GOFUMPT_PLATFORM = darwin |
| 38 | + JQ_PLATFORM = macos |
| 39 | +endif |
| 40 | + |
| 41 | +# Set arch for deps |
| 42 | +ifeq ($(PLATFORM_NAME), x86_64) |
| 43 | + GOFUMPT_ARCH = amd64 |
| 44 | + JQ_PLATFORM_ARCH = $(JQ_PLATFORM)-amd64 |
| 45 | +else ifeq ($(PLATFORM_NAME), arm64) |
| 46 | + GOFUMPT_ARCH = arm64 |
| 47 | + JQ_PLATFORM_ARCH = $(JQ_PLATFORM)-arm64 |
| 48 | +endif |
| 49 | + |
| 50 | +.PHONY: bin/jq bin/gofumpt bin/golangci-lint clean validation/license/download |
| 51 | + |
| 52 | +bin: |
| 53 | + mkdir -p bin |
| 54 | + |
| 55 | +curl-installed: |
| 56 | + command -v curl > /dev/null |
| 57 | + |
| 58 | +go-installed: |
| 59 | + command -v go |
| 60 | + go version |
| 61 | + |
| 62 | +bin/jq: curl-installed bin |
| 63 | + curl -sSfL https://github.com/jqlang/jq/releases/download/jq-$(JQ_VERSION)/jq-$(JQ_PLATFORM_ARCH) -o ./bin/jq |
| 64 | + @chmod +x "./bin/jq" |
| 65 | + |
| 66 | +bin/golangci-lint: curl-installed bin |
| 67 | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | BINARY=golangci-lint bash -s -- v${GOLANGCI_VERSION} |
| 68 | + @chmod +x "./bin/golangci-lint" |
| 69 | + |
| 70 | +bin/gofumpt: curl-installed bin |
| 71 | + curl -sSfLo "bin/gofumpt" https://github.com/mvdan/gofumpt/releases/download/v$(GOFUMPT_VERSION)/gofumpt_v$(GOFUMPT_VERSION)_$(GOFUMPT_PLATFORM)_$(GOFUMPT_ARCH) |
| 72 | + @chmod +x "./bin/gofumpt" |
| 73 | + |
| 74 | +deps: bin bin/jq bin/golangci-lint bin/gofumpt |
| 75 | + |
| 76 | +test: go-installed |
| 77 | + ./hack/run_tests.sh |
| 78 | + |
| 79 | +lint: bin/golangci-lint |
| 80 | + ./bin/golangci-lint run ./... -c .golangci.yaml |
| 81 | + |
| 82 | +lint/fix: bin/golangci-lint |
| 83 | + ./bin/golangci-lint run ./... -c .golangci.yaml --fix |
| 84 | + |
| 85 | +fmt: bin/gofumpt |
| 86 | + find . -type f -name '*.go' -not -path "./validation*" -print0 | xargs -0 ./bin/gofumpt -l |
| 87 | + |
| 88 | +validation/license/dir: |
| 89 | + mkdir -p validation |
| 90 | + |
| 91 | +validation/license/download: curl-installed validation/license/dir bin/jq |
| 92 | + set -o pipefail; \ |
| 93 | + curl -sL https://api.github.com/repos/deckhouse/deckhouse/contents/tools/validation \ |
| 94 | + | ./bin/jq 'map(select(.type == "file")) | map(select(.name | test(".*.go")))' \ |
| 95 | + | ./bin/jq -r '.[] | ["curl -sSfLo \"validation/\(.name)\" \"\(.download_url)\""] | join("\n")' \ |
| 96 | + | while IFS= read -r command_to_run; do echo "run: $$command_to_run"; $(SHELL) -c "$$command_to_run"; done |
| 97 | + |
| 98 | +validation/license: go-installed validation/license/download |
| 99 | + cd ./validation; declare -a validation_deps=("github.com/tidwall/gjson" "gopkg.in/yaml.v2"); \ |
| 100 | + for i in "${validation_deps[@]}"; do \ |
| 101 | + go get "$$i"; \ |
| 102 | + done |
| 103 | + go run ./validation/{main,messages,diff,copyright,no_cyrillic,doc_changes,grafana_dashboard,release_requirements}.go -type copyright |
| 104 | + # prevent goland ide errors |
| 105 | + rm -f ./validation/go.mod ./validation/go.sum |
| 106 | + |
| 107 | +all: bin deps validation/license fmt lint test |
| 108 | + |
| 109 | +clean: |
| 110 | + rm -rf ./bin |
| 111 | + rm -rf ./validation |
0 commit comments