forked from cedar-policy/cedar-go
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
98 lines (87 loc) · 4.87 KB
/
Makefile
File metadata and controls
98 lines (87 loc) · 4.87 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
.PHONY: test linters corpus-update check-upstream-corpus testdata-validation testdata-entity-parsing
# Run all tests
test:
go test -count 1 -cover ./...
# Run linters and coverage checks
linters:
golangci-lint run
go run github.com/alecthomas/go-check-sumtype/cmd/go-check-sumtype@latest -default-signifies-exhaustive=false ./...
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out | sed 's/%$$//' | awk '{ if ($$3 < 100.0) { printf "Insufficient code coverage for %s\n", $$0; failed=1 } } END { exit failed }'
# Download the latest corpus tests tarball and overwrite corpus-tests.tar.gz if changed
check-upstream-corpus:
@tmpdir="$$(mktemp -d)" && \
trap 'rm -rf "$$tmpdir"' EXIT && \
curl -fL -o "$$tmpdir/corpus-tests.tar.gz" https://raw.githubusercontent.com/cedar-policy/cedar-integration-tests/main/corpus-tests.tar.gz && \
if cmp -s "$$tmpdir/corpus-tests.tar.gz" corpus-tests.tar.gz; then \
echo "corpus-tests.tar.gz is up to date."; \
else \
mv "$$tmpdir/corpus-tests.tar.gz" corpus-tests.tar.gz; \
echo "corpus-tests.tar.gz updated."; \
fi
# Use an order-only prerequisite to check for changes. This allows other targets to
# reference corpus-tests.tar.gz as a dependency so that they'll only be re-created
# if the corpus tests are updated.
corpus-tests.tar.gz: | check-upstream-corpus
# Convert Cedar schemas to JSON schemas
corpus-tests-json-schemas.tar.gz: corpus-tests.tar.gz
@echo "Generating JSON schemas from Cedar schemas..."
@tmpdir="$$(mktemp -d)" && \
trap 'rm -rf "$$tmpdir"' EXIT && \
tar -xzf corpus-tests.tar.gz -C "$$tmpdir" && \
mkdir -p "$$tmpdir/corpus-tests-json-schemas" && \
for schema in "$$tmpdir"/corpus-tests/*.cedarschema; do \
basename=$$(basename "$$schema" .cedarschema); \
echo " Converting $$basename.cedarschema..."; \
cedar translate-schema --direction cedar-to-json --schema "$$schema" \
> "$$tmpdir/corpus-tests-json-schemas/$$basename.cedarschema.json" 2>&1; \
done && \
tar -czf corpus-tests-json-schemas.tar.gz -C "$$tmpdir" corpus-tests-json-schemas && \
echo "Done! Created corpus-tests-json-schemas.tar.gz"
# Build cedar-validation-tool
test/cedar-validation-tool/target/release/cedar-validation-tool: test/cedar-validation-tool/src/main.rs test/cedar-validation-tool/Cargo.toml
@echo "Building cedar-validation-tool..."
@cd test/cedar-validation-tool && cargo build --release
# Generate validation results from Rust Cedar
corpus-tests-validation.tar.gz: corpus-tests.tar.gz test/cedar-validation-tool/target/release/cedar-validation-tool
@echo "Generating validation results from Rust Cedar..."
@tmpdir="$$(mktemp -d)" && \
trap 'rm -rf "$$tmpdir"' EXIT && \
tar -xzf corpus-tests.tar.gz -C "$$tmpdir" && \
mkdir -p "$$tmpdir/corpus-tests-validation" && \
for testjson in "$$tmpdir"/corpus-tests/*.json; do \
case "$$testjson" in *.entities.json) continue ;; esac; \
basename=$$(basename "$$testjson" .json); \
test/cedar-validation-tool/target/release/cedar-validation-tool \
"$$testjson" "$$tmpdir/corpus-tests-validation/$${basename}.validation.json"; \
done && \
tar -czf corpus-tests-validation.tar.gz -C "$$tmpdir" corpus-tests-validation && \
echo "Done! Created corpus-tests-validation.tar.gz"
# Regenerate validation data for x/exp/schema/validate/testdata
testdata-validation: test/cedar-validation-tool/target/release/cedar-validation-tool
@echo "Regenerating testdata validation files..."
@for testjson in x/exp/schema/validate/testdata/*.json; do \
case "$$testjson" in *.entities.json|*.validation.json) continue ;; esac; \
basename=$$(basename "$$testjson" .json); \
echo " Validating $$basename..."; \
test/cedar-validation-tool/target/release/cedar-validation-tool \
"$$testjson" "x/exp/schema/validate/testdata/$${basename}.validation.json"; \
done
@echo "Done! Regenerated testdata validation files."
# Build cedar-entity-parsing-tool and generate entity parsing results
test/cedar-entity-parsing-tool/target/release/cedar-entity-parsing-tool: test/cedar-entity-parsing-tool/src/main.rs test/cedar-entity-parsing-tool/Cargo.toml
@echo "Building cedar-entity-parsing-tool..."
@cd test/cedar-entity-parsing-tool && cargo build --release
# Regenerate entity parsing data for x/exp/types/testdata
testdata-entity-parsing: test/cedar-entity-parsing-tool/target/release/cedar-entity-parsing-tool
@echo "Regenerating entity parsing test files..."
@for testjson in x/exp/types/testdata/*.json; do \
case "$$testjson" in *.entities.json|*.parsing.json) continue ;; esac; \
basename=$$(basename $$testjson .json); \
echo " Parsing $$basename..."; \
test/cedar-entity-parsing-tool/target/release/cedar-entity-parsing-tool \
"$$testjson" "x/exp/types/testdata/$${basename}.parsing.json"; \
done
@echo "Done! Regenerated entity parsing test files."
# Download, convert, and validate
corpus-update: corpus-tests-json-schemas.tar.gz corpus-tests-validation.tar.gz testdata-validation testdata-entity-parsing