-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
117 lines (94 loc) · 4.42 KB
/
Makefile
File metadata and controls
117 lines (94 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
.PHONY: fmt validate docs lint changelog release tag clean help check-deps check-all
SHELL := /bin/bash
# Current version from the latest git tag (strip leading 'v')
CURRENT_VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.0.0")
DATE := $(shell date +%Y-%m-%d)
# Repository URL
REPO_URL := https://github.com/atlet99/terraform-openstack-instance-module
# Required binaries
REQUIRED_BINS := terraform tflint terraform-docs git git-cliff tfenv
# Use tfenv if available, otherwise fallback to standard terraform
TERRAFORM := $(shell if command -v tfenv >/dev/null 2>&1; then echo "tfenv exec"; else echo "terraform"; fi)
###############################################################################
# Helpers
###############################################################################
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
check-deps: ## Check that all required tools are installed
@for bin in $(REQUIRED_BINS); do \
if ! command -v $$bin &>/dev/null; then \
echo "ERROR: '$$bin' is not installed."; \
case $$bin in \
terraform) echo " Install: https://developer.hashicorp.com/terraform/install" ;; \
tflint) echo " Install: brew install tflint" ;; \
terraform-docs) echo " Install: brew install terraform-docs" ;; \
git) echo " Install: brew install git" ;; \
esac; \
exit 1; \
fi; \
done
@echo "All dependencies are available."
###############################################################################
# Terraform
###############################################################################
fmt: check-deps ## Run terraform fmt recursively
$(TERRAFORM) fmt -recursive
validate: check-deps ## Run terraform init + validate
$(TERRAFORM) init -backend=false -input=false
$(TERRAFORM) validate
###############################################################################
# Linting & Docs
###############################################################################
lint: check-deps ## Run tflint
tflint --init
tflint
docs: check-deps ## Generate documentation with terraform-docs
terraform-docs .
check-all: fmt validate lint docs ## Run all checks: fmt, validate, lint, docs
###############################################################################
# Changelog & Release
###############################################################################
changelog: check-deps ## Generate CHANGELOG.md from git commits
@echo "Generating CHANGELOG.md with git-cliff..."
@git cliff -o CHANGELOG.md
@echo "Done. Review CHANGELOG.md and commit."
# Next version automatically determined by git-cliff
NEXT_VERSION := $(shell git cliff --bumped-version 2>/dev/null || echo "v1.0.1")
changelog-preview: check-deps ## Preview the next version and unreleased changes
@echo "Next version: $(NEXT_VERSION)"
@echo "Unreleased changes:"
@git cliff --unreleased --strip all
release: check-deps ## Create a release: make release [VERSION=x.y.z]
@version="$(VERSION)"; \
if [ -z "$$version" ]; then \
version="$(NEXT_VERSION)"; \
fi; \
version=$${version#v}; \
echo "Releasing v$$version (current: v$(CURRENT_VERSION))..."; \
sed -i.bak -e "s/version = \".*\"/version = \"$$version\"/g" README.md; \
rm -f README.md.bak; \
git cliff --bump --tag "v$$version" -o CHANGELOG.md; \
git add CHANGELOG.md README.md; \
git commit -m "chore: release v$$version"; \
git tag -a "v$$version" -m "Release v$$version"; \
echo "Done. Run 'git push && git push --tags' to publish."
tag: check-deps ## Create a tag with CHANGELOG update: make tag [VERSION=x.y.z]
@version="$(VERSION)"; \
if [ -z "$$version" ]; then \
version="$(NEXT_VERSION)"; \
fi; \
version=$${version#v}; \
echo "Creating tag v$$version (current: v$(CURRENT_VERSION))..."; \
sed -i.bak -e "s/version = \".*\"/version = \"$$version\"/g" README.md; \
rm -f README.md.bak; \
git cliff --bump --tag "v$$version" -o CHANGELOG.md; \
git add CHANGELOG.md README.md; \
git commit -m "chore: release v$$version"; \
git tag -a "v$$version" -m "Release v$$version"; \
echo "Tag v$$version created. Run 'git push && git push --tags' to publish."
###############################################################################
# Cleanup
###############################################################################
clean: ## Remove terraform init artifacts
rm -rf .terraform .terraform.lock.hcl