-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
137 lines (118 loc) · 5.69 KB
/
Makefile
File metadata and controls
137 lines (118 loc) · 5.69 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
PROVIDER_BIN:=$(shell basename `git rev-parse --show-toplevel`)
PROVIDER_NAME:=$(shell echo $(PROVIDER_BIN) | sed 's/terraform-provider-//g')
PROVIDER_DIRECTORY:=~/.terraform.d/plugins/local/altinity/${PROVIDER_NAME}
DEFAULT_GRAPHQL_SCHEMA_FILE:=internal/sdk/client/graphql.schema
DEFAULT_GRAPHQL_SCHEMA_URL:=https://anywhere.dev.altinity.cloud/api/v1/graphql.schema
GRAPHQL_SCHEMA_URL:=$(or $(GRAPHQL_SCHEMA_URL),$(DEFAULT_GRAPHQL_SCHEMA_URL))
GRAPHQL_SCHEMA_FILE:=$(or $(GRAPHQL_SCHEMA_FILE),$(DEFAULT_GRAPHQL_SCHEMA_FILE))
VERSION:=0.0.1
OS:=darwin
ARCH:=amd64
LOCAL_DIRECTORY:=local
ifeq ($(shell uname -s), Linux)
OS := linux
endif
# ifeq ($(shell uname -m), arm64)
# ARCH=arm64
# endif
default: help
.PHONY: testacc
testacc:
ALTINITYCLOUD_TEST_ENV_PREFIX="ianaya89" \
ALTINITYCLOUD_API_TOKEN="eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhbHRpbml0eS5jbG91ZC5sb2NhbGhvc3QiLCJpYXQiOjE3MzQ5NjYyNTgsInN1YiI6ImhpQGlhbmF5YTg5LmRldiJ9.4dUY1ulQQZI1cIkAZQogHgaC7Bti55oP3spYZRjqB5eyRCrLV1NGzLe3GI_TgIJP4S0vU8GjVKfP_z0xxN8rAw" \
ALTINITYCLOUD_API_URL="https://internal.altinity.cloud.localhost:7443" \
TF_ACC=1 go test ./... -run TestAccAltinityCloudEnvAWS_Basic -v $(TESTARGS) -timeout 120m
.PHONY: build
build:
go build -o ${PROVIDER_BIN}
.PHONY: local
local: build
chmod +x ${PROVIDER_BIN}
mkdir -p ${PROVIDER_DIRECTORY}/${VERSION}/${OS}_${ARCH}/
mv ${PROVIDER_BIN} ${PROVIDER_DIRECTORY}/${VERSION}/${OS}_${ARCH}/${PROVIDER_BIN}_v${VERSION}
mkdir -p $(LOCAL_DIRECTORY)
if [ ! -f $(LOCAL_DIRECTORY)/versions.tf ]; then echo 'terraform {\n required_providers {\n ${PROVIDER_NAME} = {\n source = "local/altinity/${PROVIDER_NAME}"\n version = "${VERSION}"\n }\n }\n}' > $(LOCAL_DIRECTORY)/versions.tf; fi
cd ${LOCAL_DIRECTORY} && rm -f .terraform.lock.hcl .terrform
cd ${LOCAL_DIRECTORY} && TF_LOG=TRACE terraform init -upgrade
.PHONY: bump
bump:
@if [ -z "$(type)" ]; then \
echo "Error: 'type' not specified. Use 'make bump type=major', 'make bump type=minor', or 'make bump type=patch'."; \
exit 1; \
fi; \
LATEST_VERSION=$$(git describe --tags `git rev-list --tags --max-count=1` | sed 's/^v//'); \
MAJOR=$$(echo $$LATEST_VERSION | cut -d. -f1); \
MINOR=$$(echo $$LATEST_VERSION | cut -d. -f2); \
PATCH=$$(echo $$LATEST_VERSION | cut -d. -f3); \
if [ "$(type)" = "major" ]; then \
NEW_VERSION=v$$((MAJOR + 1)).0.0; \
elif [ "$(type)" = "minor" ]; then \
NEW_VERSION=v$$MAJOR.$$((MINOR + 1)).0; \
elif [ "$(type)" = "patch" ]; then \
NEW_VERSION=v$$MAJOR.$$MINOR.$$((PATCH + 1)); \
else \
echo "Invalid type: $(type). Use 'major', 'minor', or 'patch'."; \
exit 1; \
fi; \
echo "New version: $$NEW_VERSION"; \
git tag $$NEW_VERSION; \
echo "New version tagged: $$NEW_VERSION"
.PHONY: sync
sync:
@$(eval LATEST_VERSION=$(shell git describe --tags `git rev-list --tags --max-count=1` | sed 's/^v//'))
@echo "Current Version: $(LATEST_VERSION)"
@# Determine OS type
@$(eval OS_TYPE=$(shell uname))
@# Adjust sed command based on OS
@if [ $(OS_TYPE) = "Darwin" ]; then \
find ./docs -name "*.md" -exec sed -i '' "s/%%VERSION%%/$(LATEST_VERSION)/g" {} +; \
else \
find ./docs -name "*.md" -exec sed -i "s/%%VERSION%%/$(LATEST_VERSION)/g" {} +; \
fi
@echo "Updated Terraform files in './docs' directory to version $(LATEST_VERSION)"
.PHONY: docs
docs:
ifeq ($(OS), darwin)
GOOS=darwin GOARCH=amd64 go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
else
go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
endif
.PHONY: sdk
sdk:
@echo "Fetching GraphQL schema from ${GRAPHQL_SCHEMA_URL} to ${GRAPHQL_SCHEMA_FILE}"
curl -o ${GRAPHQL_SCHEMA_FILE} ${GRAPHQL_SCHEMA_URL}
cd internal/sdk/client && go run github.com/Yamashou/gqlgenc
.PHONY: gen
gen: sdk docs
.PHONY: fmt
fmt:
go fmt ./...
terraform fmt -recursive
.PHONY: lint
lint:
golangci-lint run
.PHONY: install-hooks
install-hooks:
@echo "Installing git hooks (core.hooksPath = .githooks)"
git config core.hooksPath .githooks
chmod +x .githooks/pre-commit
@echo "Done. Pre-commit will run golangci-lint before each commit."
.PHONY: test
test:
go test -v -cover ./...
.PHONY: help
help:
@echo "Available commands:"
@echo
@echo "build - Build the provider binary. This compiles the provider's Go code into a binary executable."
@echo "bump - Bump version tags in Git. Use 'make bump type=[major|minor|patch]' to create a new version tag."
@echo "docs - Generate provider documentation. This uses terraform-plugin-docs to create documentation for the provider."
@echo "fmt - Format Terraform and Go code. This ensures that the code follows standard formatting conventions."
@echo "gen - Run SDK generation, version sync, and docs generation. This is a combined command that runs sdk, sync, and docs commands."
@echo "install-hooks - Install git hooks so lint runs before each commit (git config core.hooksPath .githooks)."
@echo "local - Build the provider and set up the local directory for testing. This is useful for local development and testing."
@echo "sdk - Re-sync the SDK client and models. This pulls the latest GraphQL schema and regenerates the client code."
@echo "sync - Fetch and update the current version in the 'example' directory. This syncs the version used in examples with the latest git tag."
@echo "test - Run Go unit tests with coverage. This runs all unit tests in the project and provides coverage information."
@echo "testacc - Run acceptance tests. These are integration tests that use the Terraform binary to test real infrastructure."
@echo "tool - Run Go tools. This is a placeholder for any Go-based tools you might want to run as part of the build."