-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathMakefile
More file actions
120 lines (95 loc) · 4.11 KB
/
Copy pathMakefile
File metadata and controls
120 lines (95 loc) · 4.11 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
GO_BIN?=$(shell pwd)/.bin
BINARY_DIR=bin
BINARY_NAME=doco-cd
.PHONY: test test-verbose test-coverage test-run test-e2e build build-bitwarden fmt lint update update-all download tools compose-up compose-down wiki-tools wiki-build wiki-serve wiki-version-publish
.DEFAULT_GOAL := build
ifneq (,$(wildcard ./.env))
include .env
export
endif
BUILD_FLAGS:=
ifeq ($(shell uname), Linux)
BUILD_FLAGS:=-linkmode external -extldflags '-static -Wl,-unresolved-symbols=ignore-all'
COMPILER=CGO_ENABLED=1 CC=musl-gcc
else ifeq ($(shell uname), Darwin)
BUILD_FLAGS:=""
COMPILER=CGO_ENABLED=1 CC=clang CXX=clang++
endif
BUILD_FLAGS:=-ldflags="-X main.Version=dev $(BUILD_FLAGS)"
test:
@echo "Running tests..."
@WEBHOOK_SECRET="test_Secret1" API_SECRET="test_apiSecret1" ${COMPILER} go test ${BUILD_FLAGS} -cover ./... -timeout 10m
# The nobitwarden build tag excludes the Bitwarden SDK, which is the only
# dependency that requires cgo, so this target builds without a C compiler.
test-nobitwarden:
@echo "Running tests without bitwarden integration..."
@WEBHOOK_SECRET="test_Secret1" API_SECRET="test_apiSecret1" CGO_ENABLED=0 go test -ldflags="-X main.Version=dev" -tags nobitwarden -cover ./... -timeout 10m
test-verbose:
@echo "Running tests..."
@WEBHOOK_SECRET="test_Secret1" API_SECRET="test_apiSecret1" ${COMPILER} go test ${BUILD_FLAGS} -v -cover ./... -timeout 10m
test-coverage:
@echo "Running tests with coverage..."
@WEBHOOK_SECRET="test_Secret1" API_SECRET="test_apiSecret1" ${COMPILER} go test ${BUILD_FLAGS} -v -coverprofile cover.out ./...
@go tool cover -html cover.out -o cover.html
# Run specified tests from arguments
test-run:
@echo "Running tests: $(filter-out $@,$(MAKECMDGOALS))"
@WEBHOOK_SECRET="test_Secret1" API_SECRET="test_apiSecret1" ${COMPILER} go test ${BUILD_FLAGS} -cover ./... -timeout 10m -run $(filter-out $@,$(MAKECMDGOALS))
# Run e2e scenarios against a real doco-cd built from the working tree.
# Optionally filter scenarios: make test-e2e E2E_RUN=TestFailedDeployRetry
test-e2e:
@go test -tags e2e ./test/e2e/... -v -timeout 30m -run '$(E2E_RUN)'
build:
@echo "Building without bitwarden integration (no CGO)..."
mkdir -p $(BINARY_DIR)
CGO_ENABLED=0 go build -ldflags="-X main.Version=dev" -tags nobitwarden -o $(BINARY_DIR) ./...
# Build with Bitwarden SDK support, which requires cgo.
build-bitwarden:
mkdir -p $(BINARY_DIR)
${COMPILER} go build ${BUILD_FLAGS} -o $(BINARY_DIR) ./...
lint fmt:
${GO_BIN}/golangci-lint run --fix ./...
go fix ./...
update:
git pull origin main
git submodule update --recursive --remote
update-all: update
git submodule foreach git pull origin master
git submodule foreach git checkout master
download:
@echo Download go.mod dependencies
@go mod download
tools:
mkdir -p ${GO_BIN}
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b ${GO_BIN} latest
GOBIN=${GO_BIN} go install tool
compose-up:
@echo "Starting dev docker-compose..."
@docker compose -f dev.compose.yaml up --build
compose-down:
@echo "Stopping dev docker-compose..."
@docker compose -f dev.compose.yaml down --volumes
cleanup:
@CONTAINERS=$$(docker container ls -a --format "{{.ID}}" --filter "label=cd.doco.metadata.manager"); \
if [ -n "$$CONTAINERS" ]; then \
for PROJECT in $$(for ID in $$CONTAINERS; do docker container inspect --format '{{ index .Config.Labels "com.docker.compose.project" }}' $$ID; done | sort | uniq); do \
docker compose -p $$PROJECT down -v; \
done; \
else \
echo "No containers to clean up."; \
fi
clean-testcache:
go clean -testcache
webhook:
@SIGNATURE=$$(openssl dgst -sha256 -hmac "test_Secret1" < cmd/doco-cd/testdata/github_payload.json | sed 's/^.* //') && \
curl -X POST -H "X-Hub-Signature-256: sha256=$$SIGNATURE" \
-H "Content-Type: application/json" \
-H "X-GitHub-Event: push" \
--data @cmd/doco-cd/testdata/github_payload.json \
http://localhost/v1/webhook
wiki-tools:
python3 -m venv .venv-wiki
.venv-wiki/bin/python -m pip install --upgrade pip
.venv-wiki/bin/python -m pip install -r wiki/requirements.txt
wiki-serve:
.venv-wiki/bin/zensical serve --config-file wiki/zensical.toml