UNPKG

@kubeasy-dev/kubeasy-cli

Version:

Command Line to interact with kubeasy.dev and challenges

236 lines (213 loc) 7.72 kB
# https://taskfile.dev version: '3' vars: BINARY_NAME: kubeasy VERSION: sh: git describe --tags --always --dirty 2>/dev/null || echo "dev" BUILD_DIR: bin DIST_DIR: dist K8S_VERSION: "1.34.1" GOPATH: sh: go env GOPATH LDFLAGS: >- -s -w -X 'github.com/kubeasy-dev/kubeasy-cli/pkg/constants.Version={{.VERSION}}' -X 'github.com/kubeasy-dev/kubeasy-cli/pkg/constants.LogFilePath=/tmp/kubeasy-cli.log' -X 'github.com/kubeasy-dev/kubeasy-cli/pkg/constants.WebsiteURL=https://kubeasy.dev' -X 'github.com/kubeasy-dev/kubeasy-cli/pkg/constants.ExercicesRepoBranch=main' tasks: default: desc: Show available tasks cmds: - task --list # =========================================================================== # Tool Installation (granular, with status checks) # =========================================================================== install:lint: desc: Install golangci-lint status: - command -v golangci-lint cmds: - echo "Installing golangci-lint..." - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b {{.GOPATH}}/bin latest install:envtest: desc: Install setup-envtest status: - command -v setup-envtest cmds: - echo "Installing setup-envtest..." - go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest install:goreleaser: desc: Install goreleaser status: - command -v goreleaser cmds: - echo "Installing goreleaser..." - go install github.com/goreleaser/goreleaser/v2@latest install:gocovmerge: desc: Install gocovmerge status: - command -v gocovmerge cmds: - echo "Installing gocovmerge..." - go install github.com/wadey/gocovmerge@latest install:tools: desc: Install all development tools deps: - install:lint - install:envtest - install:goreleaser - install:gocovmerge # =========================================================================== # Setup # =========================================================================== setup:envtest: desc: Setup envtest Kubernetes assets deps: [install:envtest] status: - test -d ./bin/k8s/k8s cmds: - echo "Setting up envtest assets..." - "{{.GOPATH}}/bin/setup-envtest use {{.K8S_VERSION}} --bin-dir ./bin/k8s" # =========================================================================== # Dependencies # =========================================================================== deps: desc: Download and tidy Go dependencies cmds: - echo "Downloading dependencies..." - go mod download - go mod tidy vendor: desc: Generate vendor directory cmds: - echo "Generating vendor directory..." - go mod vendor # =========================================================================== # Build # =========================================================================== build: desc: Build the binary for current platform sources: - "**/*.go" - go.mod - go.sum generates: - "{{.BUILD_DIR}}/{{.BINARY_NAME}}" cmds: - echo "Building {{.BINARY_NAME}} {{.VERSION}}..." - mkdir -p {{.BUILD_DIR}} - go build -ldflags "{{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}} . build:all: desc: Build binaries for all platforms deps: [clean] cmds: - echo "Building for all platforms..." - mkdir -p {{.DIST_DIR}} - for: matrix: GOOS: [linux, darwin, windows] GOARCH: [amd64, arm64] cmd: | echo " → {{.ITEM.GOOS}} {{.ITEM.GOARCH}}..." EXT={{if eq .ITEM.GOOS "windows"}}.exe{{end}} GOOS={{.ITEM.GOOS}} GOARCH={{.ITEM.GOARCH}} go build -ldflags "{{.LDFLAGS}}" -o {{.DIST_DIR}}/{{.BINARY_NAME}}-{{.ITEM.GOOS}}-{{.ITEM.GOARCH}}${EXT} . # =========================================================================== # Testing # =========================================================================== test: desc: Run all tests (unit + integration) cmds: - task: test:unit - task: test:integration test:unit: desc: Run unit tests only cmds: - echo "Running unit tests..." - | go test -v -race -coverprofile=coverage-unit.out -covermode=atomic \ -coverpkg=./pkg/... $(go list ./... | grep -v /test/integration) - | if [ -s coverage-unit.out ]; then go tool cover -func=coverage-unit.out | tail -1 fi test:integration: desc: Run integration tests deps: [setup:envtest] cmds: - echo "Running integration tests..." - | KUBEBUILDER_ASSETS=$({{.GOPATH}}/bin/setup-envtest use -p path {{.K8S_VERSION}}) \ go test -v -tags=integration -coverprofile=coverage-integration.out \ -covermode=atomic -coverpkg=./pkg/... ./test/integration/... -timeout 15m - | if [ -s coverage-integration.out ]; then go tool cover -func=coverage-integration.out | tail -1 fi test:coverage: desc: Generate combined coverage report deps: [install:gocovmerge] cmds: - task: test - echo "Generating combined coverage report..." - mkdir -p coverage - | if [ -s coverage-unit.out ] && [ -s coverage-integration.out ]; then echo "Merging unit and integration coverage..." {{.GOPATH}}/bin/gocovmerge coverage-unit.out coverage-integration.out > coverage.out elif [ -s coverage-integration.out ]; then cp coverage-integration.out coverage.out elif [ -s coverage-unit.out ]; then cp coverage-unit.out coverage.out else echo "No coverage data found" exit 1 fi - go tool cover -html=coverage.out -o coverage.html - go tool cover -func=coverage.out | tail -1 # =========================================================================== # Linting # =========================================================================== lint: desc: Run golangci-lint deps: [install:lint] cmds: - echo "Running linters..." - golangci-lint run --config .github/linters/.golangci.yml lint:fix: desc: Run golangci-lint with auto-fix deps: [install:lint] cmds: - echo "Running linters with auto-fix..." - golangci-lint run --config .github/linters/.golangci.yml --fix - task: fmt fmt: desc: Format Go code cmds: - echo "Formatting code..." - gofmt -w $(find . -name "*.go" -not -path "./vendor/*") # =========================================================================== # Cleanup # =========================================================================== clean: desc: Clean build artifacts cmds: - echo "Cleaning..." - rm -rf {{.BUILD_DIR}} {{.DIST_DIR}} vendor coverage*.out coverage.html coverage/ - go clean -testcache # =========================================================================== # Development # =========================================================================== dev: desc: Build and run in development mode deps: [build] cmds: - ./{{.BUILD_DIR}}/{{.BINARY_NAME}} # =========================================================================== # Renovate # =========================================================================== renovate:dry-run: desc: Run renovate in debug mode cmds: - echo "Running renovate in debug mode..." - docker run --rm -v $(pwd):/usr/src/app/renovate renovate/renovate --platform=local