-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
139 lines (120 loc) · 5.1 KB
/
Copy pathMakefile
File metadata and controls
139 lines (120 loc) · 5.1 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
SHELL := /bin/bash
RUST_VERSION := $(shell sed -n 's/^[[:space:]]*channel[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' rust-toolchain.toml)
ifeq ($(strip $(RUST_VERSION)),)
$(error could not read the toolchain channel from rust-toolchain.toml)
endif
export RUST_VERSION
GENERATED_PATHS := \
README.md \
docs \
examples \
crates/oapi-codegen/tests/generated
.PHONY: help
help: ## Show this help text
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-35s\033[0m %s\n", $$1, $$2}'
.PHONY: clean
clean: ## Remove built files
cargo clean
.PHONY: run
run: ## Run the CLI
cargo run -p oapi-codegen
.PHONY: lint
lint: ## Run the linter
cargo clippy \
--all-targets \
--workspace \
--locked \
-- -D warnings
RUSTDOCFLAGS="-D warnings -D rustdoc::broken_intra_doc_links -D rustdoc::private_intra_doc_links" \
cargo doc --no-deps --workspace --locked
cargo +nightly fmt \
-- --check
npx prettier --check .
.PHONY: format
format: ## Format source files
cargo clippy \
--all-targets \
--fix \
--allow-dirty
cargo +nightly fmt
npx prettier --write .
.PHONY: build
build: ## Build all Rust crates
cargo build --release
.PHONY: test-unit
test-unit: ## Run unit tests
cargo test
.PHONY: test-integration
test-integration: ## Run integration tests
cargo test --features integration --test '*_integration' -- --nocapture
.PHONY: test-e2e
test-e2e: ## Run the Docker end-to-end test for the generated server and client
@compose="docker compose -f crates/oapi-codegen/tests/integration/docker-compose.yml"; \
trap 'code=$$?; $$compose down --remove-orphans --volumes; exit $$code' EXIT; \
$$compose up --build --exit-code-from client --abort-on-container-exit
.PHONY: update-generated
update-generated: ## Refresh generated files from the coverage fixtures
UPDATE_GENERATED=1 cargo test -p oapi-codegen --test coverage
.PHONY: update-docs
update-docs: ## Refresh docs/cli.md and the documented command output in Markdown files
UPDATE_DOCS=1 cargo test -p oapi-codegen --test cli_docs
TRYCMD=overwrite cargo test -p oapi-codegen --test documentation
.PHONY: generate-example
generate-example: ## Regenerate the bookstore example from its OpenAPI specification
cd examples/bookstore && \
cargo run -q -p oapi-codegen -- --config-file oapi-codegen-common.yaml schemas/common.yaml && \
cargo run -q -p oapi-codegen -- --config-file oapi-codegen-catalog.yaml schemas/catalog.yaml && \
cargo run -q -p oapi-codegen -- --config-file oapi-codegen-server.yaml openapi.yaml && \
cargo run -q -p oapi-codegen -- --config-file oapi-codegen-client.yaml openapi.yaml
.PHONY: verify-example
verify-example: ## Fail when the bookstore example is out of date, without writing to it
cd examples/bookstore && \
cargo run -q -p oapi-codegen -- --check --config-file oapi-codegen-common.yaml schemas/common.yaml && \
cargo run -q -p oapi-codegen -- --check --config-file oapi-codegen-catalog.yaml schemas/catalog.yaml && \
cargo run -q -p oapi-codegen -- --check --config-file oapi-codegen-server.yaml openapi.yaml && \
cargo run -q -p oapi-codegen -- --check --config-file oapi-codegen-client.yaml openapi.yaml
.PHONY: print-generated-paths
print-generated-paths: ## Print the paths that regeneration writes, one per line
@printf '%s\n' $(GENERATED_PATHS)
.PHONY: verify-generated
verify-generated: ## Regenerate all generated files and fail when they differ from committed files
$(MAKE) verify-example
$(MAKE) update-generated
$(MAKE) update-docs
@if [ -n "$$(git status --porcelain -- $(GENERATED_PATHS))" ]; then \
echo "ERROR: generated files are out of date."; \
echo "Run 'make generate-example', 'make update-generated' and 'make update-docs'. Commit the result."; \
git status --porcelain -- $(GENERATED_PATHS); \
git --no-pager diff -- $(GENERATED_PATHS); \
exit 1; \
fi
@echo "Generated files are up to date."
.PHONY: verify-package
verify-package: ## Fail when the published package does not build or run, or when it carries the test suite
@set -euo pipefail; \
files="$$(cargo package -p oapi-codegen --locked --list)"; \
if grep -q '^tests/' <<< "$$files"; then \
echo "ERROR: the package carries the test suite."; \
echo "Check 'include' in crates/oapi-codegen/Cargo.toml."; \
exit 1; \
fi
cargo package -p oapi-codegen --locked
@set -euo pipefail; \
version="$$(cargo metadata --format-version 1 --no-deps --locked \
| jq -er '.packages[] | select(.name == "oapi-codegen") | .version')"; \
work="$$(mktemp -d)"; \
trap 'rm -rf "$$work"' EXIT; \
tar xzf target/package/oapi-codegen-$$version.crate -C "$$work"; \
cd "$$work/oapi-codegen-$$version" && cargo build --locked -q; \
cp -R $(CURDIR)/examples/bookstore "$$work/example"; \
cd "$$work/example" && \
"$$work/oapi-codegen-$$version/target/debug/oapi-codegen" \
--config-file oapi-codegen-catalog.yaml schemas/catalog.yaml \
< /dev/null; \
diff -u $(CURDIR)/examples/bookstore/generated/apimodel/catalog.rs \
"$$work/example/generated/apimodel/catalog.rs"
@echo "The package builds, runs, and carries no tests."
.PHONY: docs
docs: ## Generate and open Rust documentation
cargo doc --no-deps --open