Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opentofu registry makefile #1248

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.idea

generated/
bin/
96 changes: 96 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
.POSIX:

export PATH := $(abspath bin/):${PATH}

.PHONY: all
all: help ## Default target (help)

.PHONY: check-mkcert
check-mkcert: ## Check if mkcert is installed
@which mkcert > /dev/null || (echo "mkcert is not installed. Please install it from https://github.com/FiloSottile/mkcert" && exit 1)

.PHONY: create-certificate
create-certificate: check-mkcert ## Create a new local certificate if it doesn't exist
# if the certificate does not exist, create a new one
@if [ ! -f src/cmd/run-server/localhost.pem ]; then \
echo "* Creating a new certificate"; \
cd src/cmd/run-server && mkcert -install && mkcert localhost; \
else \
echo "* Certificate already exists"; \
fi

.PHONY: mod-init
mod-init: create-certificate ## Initialize go mod
# if go.mod does not exist, initialize it
@if [ ! -f src/go.mod ]; then \
echo "* Initializing go mod"; \
cd src && go mod init .; \
else \
echo "* go.mod already exists"; \
fi

.PHONY: populate-generated-folder
populate-generated-folder: mod-init ## Populate the generated folder
# if the generated folder exist, remove it
@if [ -d generated ]; then \
rm -rf generated; \
fi
# create the generated folder
@cd src && go run ./cmd/generate-v1 --destination ../generated

.PHONY: run-server
run-server: populate-generated-folder ## Run the server
cd src && go run ./cmd/run-server -certificate cmd/run-server/localhost.pem -key cmd/run-server/localhost-key.pem

.PHONY: build-all
build-all: mod-init ## Build all the binaries
@echo "* Building all binaries"
@cd src && go build -o ../bin/add-module ./cmd/add-module
@cd src && go build -o ../bin/add-provider ./cmd/add-provider
@cd src && go build -o ../bin/bump-versions ./cmd/bump-versions
@cd src && go build -o ../bin/generate-v0 ./cmd/generate-v1
@cd src && go build -o ../bin/run-server ./cmd/run-server
@cd src && go build -o ../bin/validate ./cmd/validate
@cd src && go build -o ../bin/verify-gpg-key ./cmd/verify-gpg-key

.PHONY: test
test: mod-init ## Run the tests for all the packages
@cd src && go test ./...

.PHONY: clean
clean: ## Clean generated files and binaries
# remove all bins under src
@rm -rf bin/
# remove generated folders
@rm -rf bin generated

.PHONY: fmt
fmt: ## Format the Go code
@cd src && go fmt ./...

.PHONY: lint
lint: ## Run static analysis on the code
@cd src && golangci-lint run

.PHONY: vet
vet: ## Examine the code for potential issues
@cd src && go vet ./...

.PHONY: install-tools
install-tools: ## Install necessary development tools
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

.PHONY: help
help: ## Prints this help message.
@echo ""
@echo "Opentofu Registry Makefile"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "The available targets for execution are listed below."
@echo ""
@echo "Targets:"
@awk 'BEGIN {FS = ":.*$$"; OFS = ""} \
/^# .*$$/ { doc=$$0; sub(/^# /, "", doc); next } \
/^[a-zA-Z0-9_-]+:.*## .*$$/ { target=$$1; sub(/:$$/, "", target); desc=$$0; sub(/^[^#]*## /, "", desc); if (!seen[target]++) { printf "\033[1m%-30s\033[0m %s\n", target, desc } } \
/^[a-zA-Z0-9_-]+:.*$$/ { target=$$1; sub(/:$$/, "", target); if (!seen[target]++) { if (doc != "") { printf "\033[1m%-30s\033[0m %s\n", target, doc; doc="" } else { printf "\033[1m%-30s\033[0m\n", target } } }' $(MAKEFILE_LIST)