From adb603c4bdb31f7337377ba8d79633c98eef978a Mon Sep 17 00:00:00 2001 From: Eser Ozvataf Date: Sat, 31 Aug 2024 11:41:39 +0300 Subject: [PATCH] feat(makefile): add init and generate targets, improve dev target fallback - Added init target for environment setup with installation of pre-commit, make, air, govulncheck, and gcov2lcov - Added generate target for code generation - Improved dev target to fallback to go run if air fails docs(readme): update installation instructions with init target usage on macOS --- Makefile | 20 +++++++++++++++----- README.md | 12 ++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index d93aab7..2d108eb 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,18 @@ -.PHONY: dev build multiarch-build run clean test test-api test-cov test-ci dep lint container-start container-start-prod container-rebuild container-rebuild-prod container-restart container-restart-prod container-stop container-stop-prod container-destroy container-destroy-prod container-update container-update-prod container-dev container-ps container-ps-prod container-logs-all container-logs-all-prod container-logs container-logs-prod container-cli container-cli-prod container-push +.PHONY: init dev build multiarch-build generate clean run test test-api test-cov test-ci dep lint container-start container-start-prod container-rebuild container-rebuild-prod container-restart container-restart-prod container-stop container-stop-prod container-destroy container-destroy-prod container-update container-update-prod container-dev container-ps container-ps-prod container-logs-all container-logs-all-prod container-logs container-logs-prod container-cli container-cli-prod container-push # .RECIPEPREFIX := $(.RECIPEPREFIX) BINARY_NAME=service-cli TESTCOVERAGE_THRESHOLD=0 +init: + brew install pre-commit + brew install make + pre-commit install + go install github.com/air-verse/air@latest + go install golang.org/x/vuln/cmd/govulncheck@latest + go install github.com/jandelgado/gcov2lcov@latest + dev: - # go run ./cmd/${BINARY_NAME}/ - air + air; if [ $$? -ne 0 ]; then go run ./cmd/${BINARY_NAME}/; fi build: go build -o ./tmp/dist/${BINARY_NAME} ./cmd/${BINARY_NAME}/ @@ -18,12 +25,15 @@ multiarch-build: GOARCH=arm64 GOOS=linux go build -o ./tmp/dist/${BINARY_NAME}-linux-arm64 ./cmd/${BINARY_NAME} GOARCH=arm64 GOOS=windows go build -o ./tmp/dist/${BINARY_NAME}-windows-arm64 ./cmd/${BINARY_NAME} -run: build - ./tmp/dist/${BINARY_NAME} +generate: + go generate ./... clean: go clean +run: build + ./tmp/dist/${BINARY_NAME} + test-api: cd ./deployments/api/ && \ bru run ./ --env development && \ diff --git a/README.md b/README.md index e3fd144..2c92658 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,18 @@ This project inherits the [Standard Go Project Layout](https://github.com/golang - 2️⃣ Install prerequisites + + **On macOS and Homebrew (automatically):** + + ```bash + $ make init + ``` + + If it fails on any step, you can install them manually by following the steps below. Otherwise, you can skip the rest of the steps. + + + **On other OS or without Homebrew:** + - Install and enable [pre-commit](https://pre-commit.com/#install) - Install [GNU make](https://www.gnu.org/software/make/) - Install [govulncheck](https://go.googlesource.com/vuln)