Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate to taskfile #400

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .githooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ function failed {

trap 'failed' ERR

make lint
task lint
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
# Project #
###########

# make output
bin/
# build files
build/
out/
.task

# test projects
awesome-project/
testing-project/
test-project/

##########
# Golang #
Expand Down
70 changes: 0 additions & 70 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,63 +1,6 @@
SHELL=/bin/bash -e -o pipefail
PWD = $(shell pwd)
LINTER_VERSION = v1.55.1

all: git-hooks generate ## Initializes all tools and files

out:
@mkdir -pv "$(@)"

test-build: ## Tests whether the code compiles
@go build -o /dev/null ./...

build: out/bin ## Builds all binaries

GO_BUILD = mkdir -pv "$(@)" && go build -ldflags="-w -s" -o "$(@)" ./...
.PHONY: out/bin
out/bin:
$(GO_BUILD)

git-hooks:
@git config --local core.hooksPath .githooks/

download: ## Downloads the dependencies
@go mod download

fmt: ## Formats all code with go fmt
@go fmt ./...

run: fmt ## Run a controller from your host
@go run ./main.go

generate: ## Generates files
@go run cmd/options2md/main.go -o docs/options.md


lint: fmt download ## Lints all code with golangci-lint
@go run -v github.com/golangci/golangci-lint/cmd/golangci-lint@$(LINTER_VERSION) run

govulncheck: ## Vulnerability detection using govulncheck
@go run golang.org/x/vuln/cmd/govulncheck ./...

test: ## Runs all tests
@go test ./...

coverage: out/report.json ## Displays coverage per func on cli
go tool cover -func=out/cover.out

html-coverage: out/report.json ## Displays the coverage results in the browser
go tool cover -html=out/cover.out

test-coverage: out ## Creates a test coverage profile
go test -v -cover ./... -coverprofile out/coverage.out -coverpkg ./...
go tool cover -func out/coverage.out -o out/coverage.out

clean-test-project: ## Removes test-project
@rm -rf testing-project

clean: clean-test-project ## Cleans up everything
@rm -rf bin out

.PHONY: testing-project
testing-project: clean-test-project ## Creates a testing-project from the template
@go run cmd/gt/*.go new -c $$VALUES_FILE
Expand All @@ -77,16 +20,3 @@ testing-project-ci: ## Creates for all yml files in ./test_project_values a tes
for VALUES in ./test_project_values/*.yml; do \
make testing-project-ci-single VALUES_FILE=$$VALUES; \
done

.PHONY: release
release: ## Create a new release version
@./hack/release.sh

help:
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@echo 'Available targets are:'
@echo ''
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo ''
91 changes: 91 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
version: "3"

vars:
LINTER_VERSION: v1.55.1
BUILD_DIR: ./build/
TEST_PROJECT_DIR: ./test-project/

tasks:
build:
desc: Builds the project
sources:
- "**/*.go"
cmds:
- go build -o {{.BUILD_DIR}} ./...
generates:
- build/gt
- build/options2md

run:
desc: Builds and runs gt (cleans test project output before)
deps:
- build
cmds:
- rm -rf {{.TEST_PROJECT_DIR}}
- build/gt
generates:
- build/gt

clean:
desc: Removes artifacts
cmds:
- rm -rf {{.BUILD_DIR}}
- rm -rf {{.TEST_PROJECT_DIR}}

lint:
desc: Lints the project
cmds:
- go run -v github.com/golangci/golangci-lint/cmd/golangci-lint@{{.LINTER_VERSION}} run

test:
desc: Runs all automated tests
cmds:
- go test ./...

test-build:
desc: Tests if the project can be built
cmds:
- go build -o /dev/null ./...

coverage:
desc: Generates test coverage report
cmds:
- go test -v -cover ./... -coverprofile out/coverage.out -coverpkg ./...
- go tool cover -func out/coverage.out -o out/coverage.out
generates:
- out/coverage.out

generate:
desc: Regenerates generated files
cmds:
- go run cmd/options2md/main.go -o docs/options.md
generates:
- docs/options.md

release:
desc: Creates a new release
prompt: Are you sure you want to create a new release?
deps:
- lint
- test
cmds:
- hack/release.sh

setup:
desc: Set up the project
cmds:
- git config --local core.hooksPath .githooks/
- go mod download

create-test-project:
desc: Creates a preconfigured test project
aliases:
- test-project
- tp
vars:
CONFIG_FILE: testdata/default.yml
deps:
- build
cmds:
- rm -rf {{.TEST_PROJECT_DIR}}
- go run cmd/gt/*.go new -c {{.CONFIG_FILE}}
9 changes: 0 additions & 9 deletions test_project_values/ci_case_0.yml

This file was deleted.

9 changes: 0 additions & 9 deletions test_project_values/ci_case_1.yml

This file was deleted.

9 changes: 0 additions & 9 deletions test_project_values/ci_case_2.yml

This file was deleted.

9 changes: 0 additions & 9 deletions test_project_values/ci_case_3.yml

This file was deleted.

10 changes: 0 additions & 10 deletions test_project_values/grpc_with_gateway.yml

This file was deleted.

6 changes: 0 additions & 6 deletions test_project_values/no_extentions.yml

This file was deleted.

9 changes: 9 additions & 0 deletions testdata/ci_case_0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
base:
projectName: Test Project
projectSlug: test-project
projectDescription: Some project used for testing
appName: test
moduleName: github.com/fake/test
extensions:
ci:
provider: 0 # No CI
9 changes: 9 additions & 0 deletions testdata/ci_case_1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
base:
projectName: Test Project
projectSlug: test-project
projectDescription: Some project used for testing
appName: test
moduleName: github.com/fake/test
extensions:
ci:
provider: 1 # Github
9 changes: 9 additions & 0 deletions testdata/ci_case_2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
base:
projectName: Test Project
projectSlug: test-project
projectDescription: Some project used for testing
appName: test
moduleName: github.com/fake/test
extensions:
ci:
provider: 2 #Gitlab
9 changes: 9 additions & 0 deletions testdata/ci_case_3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
base:
projectName: Test Project
projectSlug: test-project
projectDescription: Some project used for testing
appName: test
moduleName: github.com/fake/test
extensions:
ci:
provider: 3 # Azure DevOps
16 changes: 16 additions & 0 deletions testdata/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
base:
projectName: Test Project
projectSlug: test-project
projectDescription: Some project used for testing
appName: testing
moduleName: github.com/fake/test
extensions:
openSource:
author: "Marty Mc Fly"
codeowner: "[email protected]"
license: 1 # MIT License
ci:
provider: 1
grpc:
base: true
grpcGateway: false
10 changes: 10 additions & 0 deletions testdata/grpc_with_gateway.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
base:
projectName: Test Project
projectSlug: test-project
projectDescription: Some project used for testing
appName: test
moduleName: github.com/fake/test
extensions:
grpc:
base: true
grpcGateway: true
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
base:
projectName: Testing Project
projectSlug: testing-project
projectName: Test Project
projectSlug: test-project
projectDescription: Some project used for testing
appName: testing
moduleName: github.com/fake/testing
appName: test
moduleName: github.com/fake/test
extensions:
openSource:
author: "Marty Mc Fly"
Expand Down
6 changes: 6 additions & 0 deletions testdata/no_extentions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
base:
projectName: Test Project
projectSlug: test-project
projectDescription: Some project used for testing
appName: test
moduleName: github.com/fake/test
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
base:
projectName: Testing Project
projectSlug: testing-project
projectName: Test Project
projectSlug: test-project
projectDescription: Some project used for testing
appName: testing
moduleName: github.com/fake/testing
appName: test
moduleName: github.com/fake/test
extensions:
openSource:
author: "Marty Mc Fly"
Expand Down
Loading