diff --git a/.githooks/pre-push b/.githooks/pre-push index e06d7b16..20de2644 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -18,4 +18,4 @@ function failed { trap 'failed' ERR -make lint +task lint diff --git a/.gitignore b/.gitignore index 47b64e67..184db4e5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,13 +2,15 @@ # Project # ########### -# make output -bin/ +# build files +build/ out/ +.task # test projects awesome-project/ testing-project/ +test-project/ ########## # Golang # diff --git a/Makefile b/Makefile index 631950b4..62ed6b5b 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 ... ' - @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 '' diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 00000000..17a50f6e --- /dev/null +++ b/Taskfile.yml @@ -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}} diff --git a/test_project_values/ci_case_0.yml b/test_project_values/ci_case_0.yml deleted file mode 100644 index f0de39f1..00000000 --- a/test_project_values/ci_case_0.yml +++ /dev/null @@ -1,9 +0,0 @@ -base: - projectName: Testing Project - projectSlug: testing-project - projectDescription: Some project used for testing - appName: testing - moduleName: github.com/fake/testing -extensions: - ci: - provider: 0 # No CI diff --git a/test_project_values/ci_case_1.yml b/test_project_values/ci_case_1.yml deleted file mode 100644 index d8f5328f..00000000 --- a/test_project_values/ci_case_1.yml +++ /dev/null @@ -1,9 +0,0 @@ -base: - projectName: Testing Project - projectSlug: testing-project - projectDescription: Some project used for testing - appName: testing - moduleName: github.com/fake/testing -extensions: - ci: - provider: 1 # Github diff --git a/test_project_values/ci_case_2.yml b/test_project_values/ci_case_2.yml deleted file mode 100644 index 7424585a..00000000 --- a/test_project_values/ci_case_2.yml +++ /dev/null @@ -1,9 +0,0 @@ -base: - projectName: Testing Project - projectSlug: testing-project - projectDescription: Some project used for testing - appName: testing - moduleName: github.com/fake/testing -extensions: - ci: - provider: 2 #Gitlab diff --git a/test_project_values/ci_case_3.yml b/test_project_values/ci_case_3.yml deleted file mode 100644 index 9e9109c8..00000000 --- a/test_project_values/ci_case_3.yml +++ /dev/null @@ -1,9 +0,0 @@ -base: - projectName: Testing Project - projectSlug: testing-project - projectDescription: Some project used for testing - appName: testing - moduleName: github.com/fake/testing -extensions: - ci: - provider: 3 # Azure DevOps diff --git a/test_project_values/grpc_with_gateway.yml b/test_project_values/grpc_with_gateway.yml deleted file mode 100644 index 97199e14..00000000 --- a/test_project_values/grpc_with_gateway.yml +++ /dev/null @@ -1,10 +0,0 @@ -base: - projectName: Testing Project - projectSlug: testing-project - projectDescription: Some project used for testing - appName: testing - moduleName: github.com/fake/testing -extensions: - grpc: - base: true - grpcGateway: true diff --git a/test_project_values/no_extentions.yml b/test_project_values/no_extentions.yml deleted file mode 100644 index 82a4ae7a..00000000 --- a/test_project_values/no_extentions.yml +++ /dev/null @@ -1,6 +0,0 @@ -base: - projectName: Testing Project - projectSlug: testing-project - projectDescription: Some project used for testing - appName: testing - moduleName: github.com/fake/testing diff --git a/testdata/ci_case_0.yml b/testdata/ci_case_0.yml new file mode 100644 index 00000000..93b85a79 --- /dev/null +++ b/testdata/ci_case_0.yml @@ -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 diff --git a/testdata/ci_case_1.yml b/testdata/ci_case_1.yml new file mode 100644 index 00000000..ed7c67d3 --- /dev/null +++ b/testdata/ci_case_1.yml @@ -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 diff --git a/testdata/ci_case_2.yml b/testdata/ci_case_2.yml new file mode 100644 index 00000000..fef68503 --- /dev/null +++ b/testdata/ci_case_2.yml @@ -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 diff --git a/testdata/ci_case_3.yml b/testdata/ci_case_3.yml new file mode 100644 index 00000000..b948c31e --- /dev/null +++ b/testdata/ci_case_3.yml @@ -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 diff --git a/testdata/default.yml b/testdata/default.yml new file mode 100644 index 00000000..e08cb0a9 --- /dev/null +++ b/testdata/default.yml @@ -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: "Marty.Mc.Fly@future.back" + license: 1 # MIT License + ci: + provider: 1 + grpc: + base: true + grpcGateway: false diff --git a/testdata/grpc_with_gateway.yml b/testdata/grpc_with_gateway.yml new file mode 100644 index 00000000..83f7fbdf --- /dev/null +++ b/testdata/grpc_with_gateway.yml @@ -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 diff --git a/test_project_values/grpc_without_gateway.yml b/testdata/grpc_without_gateway.yml similarity index 60% rename from test_project_values/grpc_without_gateway.yml rename to testdata/grpc_without_gateway.yml index bb33ed2e..f9a1a3f2 100644 --- a/test_project_values/grpc_without_gateway.yml +++ b/testdata/grpc_without_gateway.yml @@ -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" diff --git a/testdata/no_extentions.yml b/testdata/no_extentions.yml new file mode 100644 index 00000000..f75f5fbf --- /dev/null +++ b/testdata/no_extentions.yml @@ -0,0 +1,6 @@ +base: + projectName: Test Project + projectSlug: test-project + projectDescription: Some project used for testing + appName: test + moduleName: github.com/fake/test diff --git a/test_project_values/open_source.yml b/testdata/open_source.yml similarity index 60% rename from test_project_values/open_source.yml rename to testdata/open_source.yml index bb33ed2e..f9a1a3f2 100644 --- a/test_project_values/open_source.yml +++ b/testdata/open_source.yml @@ -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"