-
Notifications
You must be signed in to change notification settings - Fork 43
/
Makefile
105 lines (89 loc) · 3.58 KB
/
Makefile
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
.PHONY: help
help:
@echo "Usage: \n"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | sort | column -t -s ':' | sed -e 's/^/ /'
.PHONY: go-install
go-install:
## go-install: Build and install terraform-provider-juju in $GOPATH/bin
@echo "Installing terraform-provider-juju"
@go mod tidy
@go install
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
GOPATH=$(shell go env GOPATH)
PARALLEL_TEST_COUNT ?= 3
EDGE_VERSION ?= 0.15.0
REGISTRY_DIR=~/.terraform.d/plugins/registry.terraform.io/juju/juju/${EDGE_VERSION}/${GOOS}_${GOARCH}
.PHONY: install
install: simplify docs go-install
## install: Build terraform-provider-juju and copy to ~/.terraform.d using EDGEVERSION
@echo "Copied to ~/.terraform.d/plugins/registry.terraform.io/juju/juju/${EDGE_VERSION}/${GOOS}_${GOARCH}"
@mkdir -p ${REGISTRY_DIR}
@cp ${GOPATH}/bin/terraform-provider-juju ${REGISTRY_DIR}/terraform-provider-juju_v${EDGE_VERSION}
.PHONY: simplify
# Reformat and simplify source files.
simplify:
## simplify: Format and simplify the go source code
@echo "Formatting the go source code"
@gofmt -w -l -s .
.PHONY: lint
lint:
## lint: run the go linter
@echo "Running go lint"
@golangci-lint run -c .golangci.yml
.PHONY: static-analysis
static-analysis:
## static-analysis: Check the go code using static-analysis
@./tools/static-analysis.sh
HAS_TERRAFORM := $(shell command -v terraform 2> /dev/null)
.PHONY: docs
docs:
## docs: update the generated terraform docs.
ifneq ($(HAS_TERRAFORM),)
@echo "Generating docs"
@go generate ./...
else
@echo "Unable to generate docs, terraform not installed"
endif
JUJU=juju
CONTROLLER=$(shell ${JUJU} whoami | yq .Controller)
CONTROLLER_ADDRESSES="$(shell ${JUJU} show-controller | yq '.${CONTROLLER}.details."api-endpoints"' | tr -d "[]' "|tr -d '"'|tr -d '\n')"
USERNAME="$(shell cat ~/.local/share/juju/accounts.yaml | yq '.controllers.${CONTROLLER}.user'|tr -d '"')"
PASSWORD="$(shell cat ~/.local/share/juju/accounts.yaml | yq '.controllers.${CONTROLLER}.password'|tr -d '"')"
CA_CERT="$(shell ${JUJU} show-controller $(echo ${CONTROLLER}|tr -d '"')| yq '.${CONTROLLER}.details."ca-cert"'|tr -d '"'|sed 's/\\n/\n/g')"
.PHONY: juju-unit-test
juju-unit-test:
## juju-unit-test: Run unit tests for internal/juju
go test ./internal/juju/... -v $(TESTARGS)
.PHONY: envtestlxd
envtestlxd:
## envtestlxd: Under development - Include env var and run unit tests against lxd
JUJU_CONTROLLER_ADDRESSES=${CONTROLLER_ADDRESSES} \
JUJU_USERNAME=${USERNAME} JUJU_PASSWORD=${PASSWORD} \
JUJU_CA_CERT=${CA_CERT} TF_ACC=1 TEST_CLOUD=lxd go test ./... -v $(TESTARGS) -timeout 120m
.PHONY: testlxd
testlxd:
## testlxd: Run acceptance tests against lxd
TF_ACC=1 TEST_CLOUD=lxd go test ./internal/provider/... -parallel ${PARALLEL_TEST_COUNT} -v $(TESTARGS) -timeout 120m
.PHONY: testmicrok8s
testmicrok8s:
## testmicrok8s: Run acceptance tests against microk8s
TF_ACC=1 TEST_CLOUD=microk8s go test ./internal/provider/... -parallel ${PARALLEL_TEST_COUNT} -v $(TESTARGS) -timeout 120m
PACKAGES=terraform golangci-lint go
# Function to check if Snap packages are installed
check-snap-package:
@for package in $(PACKAGES); do \
if snap list $$package >/dev/null 2>&1; then \
echo "Package $$package is already installed."; \
else \
echo "Package $$package is not installed."; \
sudo snap install $$package --classic; \
fi; \
done
.PHONY: install-snap-dependencies
install-snap-dependencies: check-snap-package
## install-snap-dependencies: Install all the snap dependencies
.PHONY: install-dependencies
install-dependencies: install-snap-dependencies
## install-dependencies: Install all the dependencies
check: juju-unit-test