Skip to content

Commit

Permalink
feat(makefile): add init and generate targets, improve dev target fal…
Browse files Browse the repository at this point in the history
…lback

- 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
  • Loading branch information
eser committed Aug 31, 2024
1 parent 3867456 commit adb603c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)<space>
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}/
Expand All @@ -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 && \
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit adb603c

Please sign in to comment.