-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathmakefile
More file actions
144 lines (122 loc) · 5.41 KB
/
makefile
File metadata and controls
144 lines (122 loc) · 5.41 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
137
138
139
140
141
142
143
144
-include devcontainer.make
gitops_repo ?= argocd-diff-preview
github_org ?= dag-andersen
base_branch := main
docker_file := Dockerfile
argocd_namespace := argocd-diff-preview
timeout := 60
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
use_argocd_api ?= false
debug ?= false
argocd_ui_url ?= ""
render_method ?= "server-api"
output_app_manifests ?= false
GO_TEST_FLAGS ?=
# Detect Docker API version if client is too new for server
DOCKER_API_VERSION ?= $(shell docker version 2>&1 | sed -n 's/.*Maximum supported API version is \([0-9.]*\).*/\1/p')
export DOCKER_API_VERSION
go-build:
go build -ldflags="-X 'main.Version=$(VERSION)' -X 'main.Commit=$(COMMIT)' -X 'main.BuildDate=$(BUILD_DATE)'" -o bin/argocd-diff-preview ./cmd
pull-repository:
@rm -rf base-branch || true && mkdir -p base-branch
@rm -rf target-branch || true && mkdir -p target-branch
cd base-branch && git clone https://github.com/$(github_org)/$(gitops_repo).git --depth=1 --branch "$(base_branch)" && cp -r $(gitops_repo)/. . && rm -rf .git && echo "*" > .gitignore && rm -rf $(gitops_repo) && cd -
cd target-branch && git clone https://github.com/$(github_org)/$(gitops_repo).git --depth=1 --branch "$(target_branch)" && cp -r $(gitops_repo)/. . && rm -rf .git && echo "*" > .gitignore && rm -rf $(gitops_repo) && cd -
docker-build:
docker build . -f $(docker_file) -t image
docker-build-release:
docker build . -f $(docker_file) -t image --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) --build-arg BUILD_DATE=$(BUILD_DATE)
run-with-go: go-build pull-repository
./bin/argocd-diff-preview \
--base-branch="$(base_branch)" \
--target-branch="$(target_branch)" \
--repo="$(github_org)/$(gitops_repo)" \
--keep-cluster-alive \
--file-regex="$(regex)" \
--diff-ignore="$(diff_ignore)" \
--timeout=$(timeout) \
--selector="$(selector)" \
--argocd-namespace="$(argocd_namespace)" \
--files-changed="$(files_changed)" \
--line-count="$(line_count)" \
--redirect-target-revisions="HEAD" \
--render-method="$(render_method)" \
--argocd-ui-url="${argocd_ui_url}" \
--output-app-manifests="$(output_app_manifests)" \
--debug="$(debug)"
run-with-docker: pull-repository docker-build
docker rm argocd-diff-preview || true
docker run \
--name="argocd-diff-preview" \
--network=host \
-v ~/.kube:/root/.kube \
-v /var/run/docker.sock:/var/run/docker.sock \
$(if $(DOCKER_API_VERSION),-e DOCKER_API_VERSION=$(DOCKER_API_VERSION)) \
-v $(PWD)/base-branch:/base-branch \
-v $(PWD)/target-branch:/target-branch \
-v $(PWD)/output:/output \
-v $(PWD)/secrets:/secrets \
-e BASE_BRANCH=$(base_branch) \
-e TARGET_BRANCH=$(target_branch) \
-e REPO=$(github_org)/$(gitops_repo) \
-e FILE_REGEX="$(regex)" \
-e DIFF_IGNORE="$(diff_ignore)" \
-e TIMEOUT=$(timeout) \
-e SELECTOR="$(selector)" \
-e FILES_CHANGED="$(files_changed)" \
-e ARGOCD_CHART_NAME="$(argocd_chart_name)" \
-e ARGOCD_CHART_URL="$(argocd_chart_url)" \
-e LINE_COUNT="$(line_count)" \
-e MAX_DIFF_LENGTH="$(max_diff_length)" \
image \
--argocd-namespace="$(argocd_namespace)" \
--render-method="$(render_method)" \
--debug="$(debug)"
mkdocs:
python3 -m venv venv \
&& source venv/bin/activate \
&& pip3 install mkdocs-material \
&& mkdocs serve --watch-theme --open
run-lint:
golangci-lint run
run-unit-tests:
go test $(GO_TEST_FLAGS) ./cmd/... ./pkg/...
go test $(GO_TEST_FLAGS) -race ./cmd/... ./pkg/...
go test $(GO_TEST_FLAGS) -cover ./cmd/... ./pkg/...
# go test -coverprofile=coverage.out ./...
# go tool cover -html=coverage.out
# New Go-based integration tests
run-integration-tests-go: go-build
cd integration-test && go test -v -timeout 60m -run TestIntegration ./...
run-integration-tests-docker: go-build
cd integration-test && go test -v -timeout 60m -run TestIntegration -docker ./...
# Run integration tests with the Argo CD server API
run-integration-tests-go-with-api: go-build
cd integration-test && go test -v -timeout 60m -run TestIntegration -render-method=server-api ./...
run-integration-tests-docker-with-api: go-build
cd integration-test && go test -v -timeout 60m -run TestIntegration -docker -render-method=server-api ./...
# Run integration tests with the Argo CD repo server API
run-integration-tests-go-with-repo-server-api: go-build
cd integration-test && go test -v -timeout 60m -run TestIntegration -render-method=repo-server-api ./...
run-integration-tests-docker-with-repo-server-api: go-build
cd integration-test && go test -v -timeout 60m -run TestIntegration -docker -render-method=repo-server-api ./...
# Update golden files for integration tests
update-integration-tests: go-build
cd integration-test && go test -v -timeout 60m -run TestIntegration -update ./...
update-integration-tests-docker: go-build
cd integration-test && go test -v -timeout 60m -run TestIntegration -docker -update ./...
# Run before release
check-release: run-lint run-unit-tests
$(MAKE) run-integration-tests-go
$(MAKE) run-integration-tests-go-with-repo-server-api
$(MAKE) run-integration-tests-docker-with-api
# Loop the above commands until one fails
check-release-repeat:
@i=1; while true; do \
echo "⭐⭐⭐⭐⭐ Iteration $$i ⭐⭐⭐⭐⭐"; \
$(MAKE) run-integration-tests-go || exit 1; \
$(MAKE) run-integration-tests-docker-with-api || exit 1; \
i=$$((i + 1)); \
done