ifneq (,$(wildcard ./.env))
include .env
export
endif
RUNPOD_API_KEY ?=
RUNPOD_BASE_URL ?= https://rest.runpod.io/v1
RUNPOD_TIMEOUT_SECS ?= 30
define make-log
$(info [$(shell date '+%Y-%m-%d %H:%M:%S')] [MAKE] [$(MAKECMDGOALS)] $(1))
endef
define shell-log
printf "[%s] [MAKE] [$(MAKECMDGOALS)] $(1)\n" "$$(date '+%Y-%m-%d %H:%M:%S')"
endef
.PHONY: setup
setup: install-tools env
$(call make-log,Project setup complete!)
.PHONY: env
env:
$(call make-log,Setting up environment file...)
@if [ ! -f .env ]; then \
$(call shell-log,Creating .env from .env.example...); \
cp .env.example .env; \
$(call shell-log,.env file created. Please edit it with your actual values.); \
else \
$(call shell-log,.env file already exists.); \
fi
.PHONY: install-tools
install-tools:
$(call make-log,Installing development tools...)
@if ! command -v cargo-audit >/dev/null 2>&1; then \
$(call shell-log,Installing cargo-audit...); \
cargo install cargo-audit --locked; \
$(call shell-log,cargo-audit installed successfully.); \
else \
$(call shell-log,cargo-audit already available: $$(cargo audit --version)); \
fi
@if ! command -v cargo-deny >/dev/null 2>&1; then \
$(call shell-log,Installing cargo-deny...); \
cargo install cargo-deny --locked; \
$(call shell-log,cargo-deny installed successfully.); \
else \
$(call shell-log,cargo-deny already available: $$(cargo deny --version)); \
fi
.PHONY: check-env
check-env:
$(call make-log,Checking environment configuration...)
@if [ -z "$(RUNPOD_API_KEY)" ]; then \
$(call shell-log,ERROR: RUNPOD_API_KEY is not set. Please set it in .env file.); \
exit 1; \
else \
$(call shell-log,RUNPOD_API_KEY is configured.); \
fi
@$(call shell-log,Base URL: $(RUNPOD_BASE_URL))
@$(call shell-log,Timeout: $(RUNPOD_TIMEOUT_SECS) seconds)
.PHONY: build
build:
$(call make-log,Building project in release mode...)
@cargo build --release
.PHONY: test
test:
$(call make-log,Running all tests with environment loaded...)
@RUNPOD_API_KEY="$(RUNPOD_API_KEY)" \
RUNPOD_BASE_URL="$(RUNPOD_BASE_URL)" \
RUNPOD_TIMEOUT_SECS="$(RUNPOD_TIMEOUT_SECS)" \
cargo test
.PHONY: examples
examples: check-env
$(call make-log,Running examples...)
@for example in basic_usage manage_endpoint; do \
$(call shell-log,Running $$example example...); \
RUNPOD_API_KEY="$(RUNPOD_API_KEY)" \
RUNPOD_BASE_URL="$(RUNPOD_BASE_URL)" \
RUNPOD_TIMEOUT_SECS="$(RUNPOD_TIMEOUT_SECS)" \
cargo run --example $$example || exit 1; \
done
.PHONY: fmt
fmt:
$(call make-log,Formatting code...)
@cargo fmt
.PHONY: clippy
clippy:
$(call make-log,Running clippy...)
@RUNPOD_API_KEY="$(RUNPOD_API_KEY)" \
RUNPOD_BASE_URL="$(RUNPOD_BASE_URL)" \
RUNPOD_TIMEOUT_SECS="$(RUNPOD_TIMEOUT_SECS)" \
cargo clippy --all-targets --all-features -- -D warnings
.PHONY: run-tools
run-tools: install-tools
$(call make-log,Running security audits and tools...)
@$(call shell-log,Running cargo audit...)
@cargo audit
@$(call shell-log,Running cargo deny...)
@cargo deny check
.PHONY: doc
doc:
$(call make-log,Generating and opening documentation...)
@RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features --open
.PHONY: dev
dev: fmt clippy test
$(call make-log,Development checks completed!)