From 2e8345a4b675f972dd33733fe455ffa8ad223e34 Mon Sep 17 00:00:00 2001 From: Johannes Aubart Date: Tue, 25 Mar 2025 14:13:52 +0100 Subject: [PATCH 1/2] use common task definitions --- .gitignore | 2 +- .gitmodules | 3 ++ Makefile | 137 +------------------------------------------------- Taskfile.yaml | 8 +++ hack/common | 1 + 5 files changed, 14 insertions(+), 137 deletions(-) create mode 100644 .gitmodules mode change 100644 => 120000 Makefile create mode 100644 Taskfile.yaml create mode 160000 hack/common diff --git a/.gitignore b/.gitignore index ed0fe68..5509cbf 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ bin/* *.test # Output of the go coverage tool, specifically when used with LiteIDE -cover.html +cover*.html *.out # Go workspace file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c0425ec --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "hack/common"] + path = hack/common + url = https://github.com/openmcp-project/build diff --git a/Makefile b/Makefile deleted file mode 100644 index cb0cfef..0000000 --- a/Makefile +++ /dev/null @@ -1,136 +0,0 @@ -PROJECT_FULL_NAME := controller-utils -REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) -EFFECTIVE_VERSION := $(shell $(REPO_ROOT)/hack/get-version.sh) - -# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) -ifeq (,$(shell go env GOBIN)) -GOBIN=$(shell go env GOPATH)/bin -else -GOBIN=$(shell go env GOBIN) -endif - -# CONTAINER_TOOL defines the container tool to be used for building images. -# Be aware that the target commands are only tested with Docker which is -# scaffolded by default. However, you might want to replace it to use other -# tools. (i.e. podman) -CONTAINER_TOOL ?= docker - -# Setting SHELL to bash allows bash commands to be executed by recipes. -# Options are set to exit when a recipe line exits non-zero or a piped command fails. -SHELL = /usr/bin/env bash -o pipefail -.SHELLFLAGS = -ec - -ROOT_CODE_DIRS := $(REPO_ROOT)/pkg/... - -##@ General - -# The help target prints out all targets with their descriptions organized -# beneath their categories. The categories are represented by '##@' and the -# target descriptions by '##'. The awk commands is responsible for reading the -# entire set of makefiles included in this invocation, looking for lines of the -# file as xyz: ## something, and then pretty-format the target and help. Then, -# if there's a line with ##@ something, that gets pretty-printed as a category. -# More info on the usage of ANSI control characters for terminal formatting: -# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters -# More info on the awk command: -# http://linuxcommand.org/lc3_adv_awk.php - -.PHONY: help -help: ## Display this help. - @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) - -##@ Development - -.PHONY: tidy -tidy: ## Runs 'go mod tidy' for all modules in this repo. - @$(REPO_ROOT)/hack/tidy.sh - -.PHONY: format -format: goimports ## Formats the imports. - @FORMATTER=$(FORMATTER) $(REPO_ROOT)/hack/format.sh $(ROOT_CODE_DIRS) - -.PHONY: verify -verify: golangci-lint goimports ## Runs linter, 'go vet', and checks if the formatter has been run. - @( echo "> Verifying root module ..." && \ - pushd $(REPO_ROOT) &>/dev/null && \ - go vet $(ROOT_CODE_DIRS) && \ - $(LINTER) run -c $(REPO_ROOT)/.golangci.yaml $(ROOT_CODE_DIRS) && \ - popd &>/dev/null ) - @test "$(SKIP_FORMATTING_CHECK)" = "true" || \ - ( echo "> Checking for unformatted files ..." && \ - FORMATTER=$(FORMATTER) $(REPO_ROOT)/hack/format.sh --verify $(ROOT_CODE_DIRS) ) - -.PHONY: test -test: ## Run tests. - go test $(ROOT_CODE_DIRS) -coverprofile cover.out - go tool cover --html=cover.out -o cover.html - go tool cover -func cover.out | tail -n 1 - -##@ Release - -.PHONY: prepare-release -prepare-release: tidy format verify test - -.PHONY: release-major -release-major: prepare-release ## Creates a new major release. - @$(REPO_ROOT)/hack/release.sh major - -.PHONY: release-minor -release-minor: prepare-release ## Creates a new minor release. - @$(REPO_ROOT)/hack/release.sh minor - -.PHONY: release-patch -release-patch: prepare-release ## Creates a new patch release. - @$(REPO_ROOT)/hack/release.sh patch - -##@ Build Dependencies - -## Location to install dependencies to -LOCALBIN ?= $(REPO_ROOT)/bin - -## Tool Binaries -FORMATTER ?= $(LOCALBIN)/goimports -LINTER ?= $(LOCALBIN)/golangci-lint - -## Tool Versions -FORMATTER_VERSION ?= v0.22.0 -LINTER_VERSION ?= 1.61.0 - -.PHONY: localbin -localbin: - @test -d $(LOCALBIN) || mkdir -p $(LOCALBIN) - -.PHONY: goimports -goimports: localbin ## Download goimports locally if necessary. If wrong version is installed, it will be overwritten. - @test -s $(FORMATTER) && test -s ./hack/goimports_version && cat ./hack/goimports_version | grep -q $(FORMATTER_VERSION) || \ - ( echo "Installing goimports $(FORMATTER_VERSION) ..."; \ - GOBIN=$(LOCALBIN) go install golang.org/x/tools/cmd/goimports@$(FORMATTER_VERSION) && \ - echo $(FORMATTER_VERSION) > ./hack/goimports_version ) - -.PHONY: golangci-lint -golangci-lint: localbin ## Download golangci-lint locally if necessary. If wrong version is installed, it will be overwritten. - @test -s $(LINTER) && $(LINTER) --version | grep -q $(LINTER_VERSION) || \ - ( echo "Installing golangci-lint $(LINTER_VERSION) ..."; \ - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCALBIN) v$(LINTER_VERSION) ) - - - - - -## Location to install dependencies to -LOCALBIN ?= $(shell pwd)/bin -$(LOCALBIN): - mkdir -p $(LOCALBIN) - -CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen -CONTROLLER_TOOLS_VERSION ?= v0.15.0 - -.PHONY: generate -generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. - $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." - -.PHONY: controller-gen -controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten. -$(CONTROLLER_GEN): $(LOCALBIN) - test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \ - GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) diff --git a/Makefile b/Makefile new file mode 120000 index 0000000..c21893a --- /dev/null +++ b/Makefile @@ -0,0 +1 @@ +./hack/common/Makefile \ No newline at end of file diff --git a/Taskfile.yaml b/Taskfile.yaml new file mode 100644 index 0000000..c9e0bdb --- /dev/null +++ b/Taskfile.yaml @@ -0,0 +1,8 @@ +version: 3 + +includes: + shared: + taskfile: hack/common/Taskfile_library.yaml + flatten: true + vars: + CODE_DIRS: '{{.ROOT_DIR}}/pkg/...' \ No newline at end of file diff --git a/hack/common b/hack/common new file mode 160000 index 0000000..97cc96a --- /dev/null +++ b/hack/common @@ -0,0 +1 @@ +Subproject commit 97cc96a1d70673f0668af6d0fd00cce3c654bd7b From 1ae7f115a5471a7b134cb39909e81ef1c782b9a6 Mon Sep 17 00:00:00 2001 From: Johannes Aubart Date: Thu, 27 Mar 2025 15:23:11 +0100 Subject: [PATCH 2/2] adapt GHAs to task --- .github/workflows/ci.yaml | 19 +++++++++++++------ .github/workflows/release.yaml | 14 ++++++++++---- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 309f298..43a8ef6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,19 +15,26 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + submodules: recursive - name: Set up Go uses: actions/setup-go@v5 with: go-version-file: go.mod - - name: make tidy + - name: Install Task + uses: arduino/setup-task@v2 + with: + version: 3.x + + - name: task generate run: | - make tidy + task generate --verbose git diff --exit-code - - name: make verify - run: make verify + - name: task validate + run: task validate --verbose - - name: make test - run: make test + - name: task test + run: task test --verbose diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8e043a5..798ae16 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,13 +19,19 @@ jobs: ssh-key: ${{ secrets.PUSH_KEY }} fetch-tags: true fetch-depth: 0 + submodules: recursive + + - name: Install Task + uses: arduino/setup-task@v2 + with: + version: 3.x - name: Read and validate VERSION id: version run: | - VERSION=$(cat VERSION) - if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-dev)?$ ]]; then - echo "Invalid version format in VERSION file: $VERSION" + VERSION=$(task version) + if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-dev(-[0-9a-f]*)?)?$ ]]; then + echo "Invalid version format: $VERSION" exit 1 fi echo "New version: $VERSION" @@ -79,7 +85,7 @@ jobs: - name: Push dev VERSION if: ${{ env.SKIP != 'true' }} run: | - echo "${{ env.version }}-dev" > VERSION + task release:set-version --verbose -- "${{ env.version }}-dev" git config user.name "${{ env.AUTHOR_NAME }}" git config user.email "${{ env.AUTHOR_EMAIL }}" git add VERSION