Skip to content

Commit 60caa5e

Browse files
committed
fix: update Makefile to handle cross-platform
1 parent 5a33527 commit 60caa5e

File tree

1 file changed

+81
-5
lines changed

1 file changed

+81
-5
lines changed

Makefile

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
qodana semgrep verify-image health-check lint test-unit test-integration \
44
install-pipx install-semgrep
55

6-
GRADLE := ./gradlew
76
DOCKER := docker
87
IMAGE_NAME := backend-app
98
IMAGE_TAG := latest
@@ -27,6 +26,15 @@ else
2726
DETECTED_OS := Unknown
2827
endif
2928

29+
# Set GRADLE command based on OS
30+
ifeq ($(DETECTED_OS),Windows)
31+
GRADLE := gradlew.bat
32+
PWD := $(shell cd)
33+
else
34+
GRADLE := ./gradlew
35+
PWD := $(shell pwd)
36+
endif
37+
3038
.DEFAULT_GOAL := help
3139

3240
help:
@@ -56,20 +64,37 @@ dev: ## Run with development profile
5664
##@ Testing
5765

5866
test: ## Run all tests
67+
ifeq ($(DETECTED_OS),Windows)
68+
@set TESTCONTAINERS_RYUK_DISABLED=true && set TESTCONTAINERS_CHECKS_DISABLE=true && $(GRADLE) clean test --info --no-daemon
69+
else
5970
@TESTCONTAINERS_RYUK_DISABLED=true \
6071
TESTCONTAINERS_CHECKS_DISABLE=true \
6172
$(GRADLE) clean test --info --no-daemon
73+
endif
6274

6375
test-unit: ## Run unit tests only
6476
$(GRADLE) test --tests '*Test' --no-daemon
6577

6678
test-integration: ## Run integration tests only
79+
ifeq ($(DETECTED_OS),Windows)
80+
@set TESTCONTAINERS_RYUK_DISABLED=true && $(GRADLE) test --tests '*IT' --no-daemon
81+
else
6782
@TESTCONTAINERS_RYUK_DISABLED=true \
6883
$(GRADLE) test --tests '*IT' --no-daemon
84+
endif
6985

7086
##@ Code Quality
7187

7288
format: ## Format code (Java and YAML)
89+
ifeq ($(DETECTED_OS),Windows)
90+
@if exist format.bat ( \
91+
call format.bat \
92+
) else if exist format.sh ( \
93+
bash format.sh \
94+
) else ( \
95+
echo Error: No format script found (format.sh or format.bat) && exit 1 \
96+
)
97+
else
7398
@if [ -f "format.sh" ]; then \
7499
chmod +x format.sh && ./format.sh; \
75100
elif [ -f "format.bat" ]; then \
@@ -78,8 +103,19 @@ format: ## Format code (Java and YAML)
78103
echo "Error: No format script found (format.sh or format.bat)"; \
79104
exit 1; \
80105
fi
106+
endif
81107

82108
format-check: ## Verify code formatting
109+
ifeq ($(DETECTED_OS),Windows)
110+
@if exist format.bat ( \
111+
call format.bat \
112+
) else if exist format.sh ( \
113+
bash format.sh \
114+
) else ( \
115+
echo Error: No format script found (format.sh or format.bat) && exit 1 \
116+
)
117+
@git diff --exit-code || (echo Formatting issues detected. Run 'make format' to fix. && exit 1)
118+
else
83119
@if [ -f "format.sh" ]; then \
84120
chmod +x format.sh && ./format.sh; \
85121
elif [ -f "format.bat" ]; then \
@@ -89,17 +125,23 @@ format-check: ## Verify code formatting
89125
exit 1; \
90126
fi
91127
@git diff --exit-code || (echo "Formatting issues detected. Run 'make format' to fix." && exit 1)
128+
endif
92129

93130
lint: ## Run linting checks
94131
$(GRADLE) check --no-daemon
95132

96133
qodana: ## Run Qodana code analysis
134+
ifeq ($(DETECTED_OS),Windows)
135+
@if not exist qodana-results mkdir qodana-results
136+
@docker run --rm -v $(PWD):/data/project -v $(PWD)/qodana-results:/data/results jetbrains/qodana-jvm-community:latest --save-report --results-dir=/data/results
137+
else
97138
@mkdir -p $(PWD)/qodana-results
98139
@docker run --rm \
99140
-v $(PWD):/data/project \
100141
-v $(PWD)/qodana-results:/data/results \
101142
jetbrains/qodana-jvm-community:latest \
102143
--save-report --results-dir=/data/results
144+
endif
103145

104146
install-pipx: ## Install pipx based on OS
105147
ifeq ($(DETECTED_OS),Linux)
@@ -134,21 +176,35 @@ else ifeq ($(DETECTED_OS),MacOS)
134176
echo "pipx is already installed"; \
135177
fi
136178
else ifeq ($(DETECTED_OS),Windows)
137-
@echo "Installing pipx on Windows..."
138-
@python -m pip install --user pipx || python3 -m pip install --user pipx
139-
@python -m pipx ensurepath || python3 -m pipx ensurepath
179+
@where pipx >nul 2>nul || ( \
180+
echo Installing pipx on Windows... && \
181+
python -m pip install --user pipx && \
182+
python -m pipx ensurepath \
183+
) || ( \
184+
python3 -m pip install --user pipx && \
185+
python3 -m pipx ensurepath \
186+
)
187+
@where pipx >nul 2>nul && echo pipx is already installed
140188
else
141189
@echo "Unknown OS. Please install pipx manually."
142190
@exit 1
143191
endif
144192

145193
install-semgrep: install-pipx ## Install Semgrep using pipx
194+
ifeq ($(DETECTED_OS),Windows)
195+
@where semgrep >nul 2>nul || ( \
196+
echo Installing Semgrep via pipx... && \
197+
pipx install semgrep || (echo Failed to install Semgrep && exit 1) \
198+
)
199+
@where semgrep >nul 2>nul && echo Semgrep is already installed
200+
else
146201
@if ! command -v semgrep >/dev/null 2>&1; then \
147202
echo "Installing Semgrep via pipx..."; \
148203
pipx install semgrep || (echo "Failed to install Semgrep" && exit 1); \
149204
else \
150205
echo "Semgrep is already installed"; \
151206
fi
207+
endif
152208

153209
semgrep: install-semgrep ## Run Semgrep security scanning
154210
@semgrep ci --config=auto --sarif --output=semgrep.sarif --verbose
@@ -159,10 +215,14 @@ docker-build: ## Build Docker image
159215
$(DOCKER) build -t $(IMAGE_NAME):$(IMAGE_TAG) .
160216

161217
docker-build-cache: ## Build Docker image with buildx cache
218+
ifeq ($(DETECTED_OS),Windows)
219+
$(DOCKER) buildx build --cache-from type=local,src=%TEMP%\.buildx-cache --cache-to type=local,dest=%TEMP%\.buildx-cache -t $(IMAGE_NAME):$(IMAGE_TAG) .
220+
else
162221
$(DOCKER) buildx build \
163222
--cache-from type=local,src=/tmp/.buildx-cache \
164223
--cache-to type=local,dest=/tmp/.buildx-cache \
165224
-t $(IMAGE_NAME):$(IMAGE_TAG) .
225+
endif
166226

167227
verify-image: ## Verify Docker image contents and configuration
168228
@echo "Verifying image exists:"
@@ -187,7 +247,11 @@ docker-logs: ## View container logs
187247
$(DOCKER) logs -f $(CONTAINER_NAME)
188248

189249
health-check: ## Check application health endpoint
250+
ifeq ($(DETECTED_OS),Windows)
251+
@powershell -Command "Invoke-WebRequest -Uri http://localhost:$(PORT)/actuator/health -UseBasicParsing"
252+
else
190253
@curl -f http://localhost:$(PORT)/actuator/health
254+
endif
191255

192256
##@ CI/CD
193257

@@ -205,7 +269,11 @@ ci-semgrep: semgrep ## Run CI Semgrep pipeline locally
205269

206270
clean: ## Clean build artifacts
207271
$(GRADLE) clean --no-daemon
272+
ifeq ($(DETECTED_OS),Windows)
273+
@if exist build rmdir /s /q build
274+
else
208275
@rm -rf build/
276+
endif
209277

210278
clean-docker: docker-stop ## Remove Docker images and containers
211279
@$(DOCKER) rmi $(IMAGE_NAME):$(IMAGE_TAG) 2>/dev/null || true
@@ -215,15 +283,23 @@ clean-all: clean clean-docker ## Complete cleanup
215283
##@ Setup
216284

217285
install: ## Install and verify development tools
286+
ifeq ($(DETECTED_OS),Windows)
287+
@if not exist google-java-format-1.28.0-all-deps.jar ( \
288+
curl -L -o google-java-format-1.28.0-all-deps.jar https://github.com/google/google-java-format/releases/download/v1.28.0/google-java-format-1.28.0-all-deps.jar \
289+
)
290+
@if exist format.sh ( attrib +x format.sh 2>nul )
291+
@if exist yamlfmt ( attrib +x yamlfmt\* 2>nul )
292+
else
218293
@test -f google-java-format-1.28.0-all-deps.jar || \
219294
curl -L -o google-java-format-1.28.0-all-deps.jar \
220295
https://github.com/google/google-java-format/releases/download/v1.28.0/google-java-format-1.28.0-all-deps.jar
221296
@if [ -f "format.sh" ]; then chmod +x format.sh; fi
222297
@if [ -d "yamlfmt" ]; then chmod +x yamlfmt/* 2>/dev/null || true; fi
298+
endif
223299

224300
verify: ## Verify development environment
225301
@echo "Detected OS: $(DETECTED_OS)"
226-
@echo "Format script: $(FORMAT_SCRIPT)"
302+
@echo "Gradle command: $(GRADLE)"
227303
@java -version
228304
@$(GRADLE) --version
229305
@docker --version

0 commit comments

Comments
 (0)