Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
120 lines (96 loc) · 5.07 KB
/
Copy pathMakefile
File metadata and controls
120 lines (96 loc) · 5.07 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 ?= go
NODE ?= node
NPM ?= npm
PYTHON ?= python3
VERSION ?= dev
PLUGIN_RELEASE_DIR ?= dist/plugin-release-$(VERSION)
PACKAGE_PLATFORMS ?= linux/amd64 linux/arm64 darwin/amd64 darwin/arm64
FUZZ_TIME ?= 10s
FUZZ_PARALLEL ?= 2
export GOWORK := off
COMMIT := $(shell git rev-parse HEAD 2>/dev/null || echo unknown)
LDFLAGS := -X github.com/alibaba/open-guardrail/internal/buildinfo.Version=$(VERSION) -X github.com/alibaba/open-guardrail/internal/buildinfo.Commit=$(COMMIT)
.PHONY: build check-dependency-licenses check-dependency-notices check-generated check-public-release generate test test-go test-fuzz test-web test-python test-scripts demo smoke smoke-docker smoke-release preview-release release public-release
build:
CGO_ENABLED=0 $(GO) build -trimpath -ldflags "$(LDFLAGS)" -o bin/open-guardrail ./cmd/open-guardrail
CGO_ENABLED=0 $(GO) build -trimpath -ldflags "$(LDFLAGS)" -o bin/guardrailctl ./cmd/guardrailctl
generate:
$(GO) generate ./api/openapi
check-generated:
GO="$(GO)" sh scripts/check-generated.sh
check-dependency-licenses:
sh scripts/check-dependency-licenses.sh
check-dependency-notices:
$(PYTHON) scripts/dependency-notices.py
test: test-go test-web test-python test-scripts
test-go: check-generated
sh scripts/check-toolchain.sh
test -z "$$(gofmt -l cmd internal api migrations storage web)"
$(GO) vet ./...
$(GO) test -race ./...
test-fuzz:
$(GO) test ./internal/domain/spec -run '^$$' -fuzz '^FuzzValidateSpec$$' -fuzztime "$(FUZZ_TIME)" -fuzzminimizetime=5s -parallel "$(FUZZ_PARALLEL)" -timeout=2m
$(GO) test ./internal/domain/spec -run '^$$' -fuzz '^FuzzSpecTextIdentity$$' -fuzztime "$(FUZZ_TIME)" -fuzzminimizetime=5s -parallel "$(FUZZ_PARALLEL)" -timeout=2m
$(GO) test ./internal/domain/run -run '^$$' -fuzz '^FuzzCanonicalizeChangeSet$$' -fuzztime "$(FUZZ_TIME)" -fuzzminimizetime=5s -parallel "$(FUZZ_PARALLEL)" -timeout=2m
$(GO) test ./internal/domain/run -run '^$$' -fuzz '^FuzzRejectDuplicateChangeSetKeys$$' -fuzztime "$(FUZZ_TIME)" -fuzzminimizetime=5s -parallel "$(FUZZ_PARALLEL)" -timeout=2m
test-web: test-pages
$(NODE) --test web/*.test.cjs scripts/spec-canonicalization.test.cjs
.PHONY: test-pages
test-pages:
$(NPM) --prefix pages ci --ignore-scripts
$(NPM) --prefix pages run check
SITE_BASE_PATH=/open-guardrail/ SITE_ORIGIN=https://alibaba.github.io $(NPM) --prefix pages run build
test-python:
PYTHONDONTWRITEBYTECODE=1 $(PYTHON) -m unittest discover -s integrations -t . -p 'test_*.py'
PYTHONDONTWRITEBYTECODE=1 $(PYTHON) -m unittest discover -s integrations/github-actions -p 'test_*.py'
PYTHONDONTWRITEBYTECODE=1 $(PYTHON) -m unittest discover -s examples/agent-demo -p 'test_*.py'
PYTHONDONTWRITEBYTECODE=1 $(PYTHON) -m unittest discover -s examples/cleanup-demo -p 'test_*.py'
$(MAKE) test-agent-plugins
$(PYTHON) -B integrations/github-actions/demo.py
$(PYTHON) -B examples/resource-bindings/smoke.py
$(PYTHON) -B examples/business-id/smoke.py
# Default plugin gate builds native binaries and checks isolated service/file effects.
# External pi/DSH SDK tests additionally require OPEN_GUARDRAIL_HOST_MODULES.
.PHONY: smoke-bindings
smoke-bindings: build
$(PYTHON) -B examples/resource-bindings/smoke.py
.PHONY: test-agent-plugins
test-agent-plugins: build
$(NODE) integrations/agent-plugins/pack.mjs
OPEN_GUARDRAIL_BINARIES="$(CURDIR)/bin" $(PYTHON) -B -m unittest discover -s integrations/agent-plugins -p 'test_*.py' -v
OPEN_GUARDRAIL_BINARIES="$(CURDIR)/bin" $(NODE) --test integrations/agent-plugins/test/*.test.mjs
test-scripts:
PYTHONDONTWRITEBYTECODE=1 $(PYTHON) scripts/assemble-release.test.py
PYTHONDONTWRITEBYTECODE=1 $(PYTHON) scripts/plugin-release.test.py
sh scripts/check-generated.test.sh
sh scripts/package.test.sh
sh scripts/check-public-release.test.sh
sh scripts/check-dependency-licenses.test.sh
PYTHONDONTWRITEBYTECODE=1 $(PYTHON) scripts/dependency-notices.test.py
$(MAKE) check-dependency-licenses
$(MAKE) check-dependency-notices
smoke:
PYTHONDONTWRITEBYTECODE=1 $(PYTHON) examples/agent-demo/smoke.py
demo:
PYTHONDONTWRITEBYTECODE=1 $(PYTHON) examples/cleanup-demo/demo.py
smoke-docker:
PYTHONDONTWRITEBYTECODE=1 $(PYTHON) scripts/smoke_docker.py
preview-release:
PACKAGE_KIND=preview PACKAGE_PLATFORMS="$(PACKAGE_PLATFORMS)" VERSION=$(VERSION) GO="$(GO)" PYTHON="$(PYTHON)" sh scripts/package.sh
check-public-release:
VERSION=$(VERSION) PYTHON="$(PYTHON)" sh scripts/check-public-release.sh
release: public-release
public-release:
$(MAKE) check-public-release
$(MAKE) check-dependency-licenses
$(MAKE) check-dependency-notices
PACKAGE_KIND=public PACKAGE_PLATFORMS="$(PACKAGE_PLATFORMS)" VERSION=$(VERSION) GO="$(GO)" PYTHON="$(PYTHON)" sh scripts/package.sh
# Verify preview artifacts without bypassing the separate public-release gates.
smoke-release: preview-release
$(PYTHON) scripts/smoke_release.py --version "$(VERSION)"
.PHONY: plugin-release
plugin-release:
$(PYTHON) scripts/plugin-release.py --version "$(VERSION)" --output-dir "$(PLUGIN_RELEASE_DIR)"
.PHONY: smoke-plugin-release
smoke-plugin-release: plugin-release
$(PYTHON) scripts/smoke-plugin-release.py --version "$(VERSION)" --assets-dir "$(PLUGIN_RELEASE_DIR)"