From 575626733181786f05c097d3453f0547d3d0db9d Mon Sep 17 00:00:00 2001 From: Madh93 Date: Tue, 31 Dec 2024 00:52:58 +0000 Subject: [PATCH] build: replace Makefile with Taskfile --- .air.toml | 2 +- .tool-versions | 4 ++-- Makefile | 23 ------------------- README.md | 2 +- Taskfile.yml | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 27 deletions(-) delete mode 100644 Makefile create mode 100644 Taskfile.yml diff --git a/.air.toml b/.air.toml index 539cc09..244cc42 100644 --- a/.air.toml +++ b/.air.toml @@ -1,3 +1,3 @@ [build] -cmd = "/usr/bin/make install" +cmd = "task install" bin = "/usr/bin/true" diff --git a/.tool-versions b/.tool-versions index 4587e35..c4c2a44 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -air 1.43.0 -golang 1.22.0 +air 1.61.5 +task 3.40.1 diff --git a/Makefile b/Makefile deleted file mode 100644 index 84d2228..0000000 --- a/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -# Go parameters -GOCMD=go -GOBUILD=$(GOCMD) build #-race -GORUN=$(GOCMD) run -GOCLEAN=$(GOCMD) clean -GOTEST=$(GOCMD) test -OUT=tpm - -.PHONY: all clean test run build install update-dependencies - -all: build -clean: - $(GOCLEAN) && rm -rf bin/$(OUT) -test: - $(GOTEST) ./... -run: - $(GORUN) main.go -build: - $(GOBUILD) -o bin/$(OUT) main.go -install: build - mkdir -p /usr/local/bin && cp bin/$(OUT) /usr/local/bin/$(OUT) && chmod +x /usr/local/bin/$(OUT) -update-dependencies: - $(GOCMD) get -u all && $(GOCMD) mod tidy diff --git a/README.md b/README.md index 76e3248..d4b7222 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Install Go if it is not already installed. You can download it from the official Clone the Terraform Provider Manager repository to build and install the binary: ```shell -git clone https://github.com/Madh93/tpm && cd tpm && make install +git clone https://github.com/Madh93/tpm && cd tpm && task install ``` ## Usage diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..5482764 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,61 @@ +version: "3" + +vars: + APP_NAME: tpm + APP_VERSION: + sh: git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0" + COMMIT_HASH: + sh: git rev-parse HEAD + LD_FLAG_VERSION: "-X github.com/Madh93/tpm/internal/version.appVersion={{.APP_VERSION}}" + LD_FLAG_COMMIT: "-X github.com/Madh93/tpm/internal/version.commitHash={{.COMMIT_HASH}}" + +env: + GCO_ENABLED: 0 + +tasks: + default: + desc: "Build and run" + cmds: + - task update-dependencies + - task build + - task install + + clean: + desc: "Clean build artifacts" + cmds: + - go clean + - rm -rf bin + + install: + desc: "Install the application" + cmds: + - go install -trimpath -ldflags "-s -w {{.LD_FLAG_VERSION}} {{.LD_FLAG_COMMIT}}" + + test: + desc: "Run tests" + cmds: + - go test ./... + + lint: + desc: "Run linters" + cmds: + - golangci-lint run + + update-dependencies: + desc: "Update dependencies" + cmds: + - go get -u all && go mod tidy + + ############# + ### BUILD ### + ############# + + build: + desc: "Build the application" + cmds: + - go build -trimpath -ldflags "-s -w {{.LD_FLAG_VERSION}} {{.LD_FLAG_COMMIT}}" -o bin/{{.APP_NAME}} main.go + + build:debug: + desc: "Build the application for debug mode" + cmds: + - go build -ldflags "{{.LD_FLAG_VERSION}} {{.LD_FLAG_COMMIT}}" -gcflags=all="-N -l" -o bin/{{.APP_NAME}}-debug main.go