2020-08-12 16:04:15 +00:00
|
|
|
#!/usr/bin/make -f
|
|
|
|
SHELL=bash
|
2020-01-30 11:41:24 +00:00
|
|
|
|
2024-11-06 12:01:19 +00:00
|
|
|
VERSION_CHECK_BRANCH ?=$(shell git describe --tags --match "version-check*" 2>/dev/null || echo "remotes/origin/master")
|
|
|
|
|
2024-09-02 11:59:24 +00:00
|
|
|
include help.mk
|
|
|
|
|
2024-11-06 12:01:19 +00:00
|
|
|
.PHONY: doc fmt check-version compatibility pre-commit unpre-commit pre-commit-run
|
2024-09-02 11:59:24 +00:00
|
|
|
|
2020-09-17 19:04:00 +00:00
|
|
|
# Regenerate documentation for proto files:
|
2020-08-12 16:04:15 +00:00
|
|
|
doc:
|
|
|
|
@for f in `find . -type f -name '*.proto' -exec dirname {} \; | sort -u `; do \
|
2020-09-17 19:04:00 +00:00
|
|
|
echo "⇒ Documentation for $$(basename $$f)"; \
|
2020-01-30 11:41:24 +00:00
|
|
|
protoc \
|
|
|
|
--doc_opt=.github/markdown.tmpl,$${f}.md \
|
2020-08-12 16:04:15 +00:00
|
|
|
--proto_path=.:/usr/local/include \
|
2020-01-30 11:41:24 +00:00
|
|
|
--doc_out=proto-docs/ $${f}/*.proto; \
|
|
|
|
done
|
2024-02-28 15:53:04 +00:00
|
|
|
|
2024-09-02 11:59:24 +00:00
|
|
|
# Run clang-format
|
2024-02-28 15:53:04 +00:00
|
|
|
fmt:
|
|
|
|
@for f in `ls **/*.proto`; do \
|
|
|
|
echo "⇒ Formatting $$f"; \
|
|
|
|
clang-format -i $$f; \
|
|
|
|
done
|
2024-09-02 11:59:24 +00:00
|
|
|
|
2024-11-06 12:01:19 +00:00
|
|
|
# Run version update check in version.json file
|
|
|
|
check-version:
|
|
|
|
@protoChanges=$$(git diff --name-only $(VERSION_CHECK_BRANCH) | grep '**/*.proto'); \
|
|
|
|
version=$$(git show $(VERSION_CHECK_BRANCH):version.json); \
|
|
|
|
if [ -z "$$version" ] || [ -z "$$protoChanges" ]; then \
|
|
|
|
exit; \
|
|
|
|
fi; \
|
|
|
|
masterMilestone=$$(jq -n --argjson data "$$version" '$$data.milestone'); \
|
|
|
|
masterPatch=$$(jq -n --argjson data "$$version" '$$data.patch'); \
|
|
|
|
milestone=$$(jq -r '.milestone' version.json); \
|
|
|
|
patch=$$(jq -r '.patch' version.json); \
|
|
|
|
if [ "$$masterMilestone" -eq "$$milestone" -a "$$masterPatch" -eq "$$patch" ]; then \
|
|
|
|
echo "⇒ You need to update the api version in the version.json file"; \
|
|
|
|
exit 1; \
|
|
|
|
fi; \
|
|
|
|
if [ "$$masterMilestone" -gt "$$milestone" ]; then \
|
|
|
|
echo "⇒ The milestone cannot be decrement in the version.json file"; \
|
|
|
|
exit 1; \
|
|
|
|
fi; \
|
|
|
|
if [ "$$masterMilestone" -eq "$$milestone" -a "$$masterPatch" -gt "$$patch" ]; then \
|
|
|
|
echo "⇒ The patch cannot be decrement without milestone increment in the version.json file"; \
|
|
|
|
exit 1; \
|
|
|
|
fi; \
|
|
|
|
if [ "$$masterMilestone" -lt "$$milestone" -a "$$patch" -ne 0 ]; then \
|
|
|
|
echo "⇒ The patch should be 0 after milestone increment in the version.json file"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Run a compatibility information check
|
|
|
|
# Checks that the files that describe compatibility in the compatibility package
|
|
|
|
# have the current version information added in the version.json file.
|
|
|
|
# Description of logic:
|
|
|
|
# 1. Determine the current API version from the version.json file;
|
|
|
|
# 2. Find all JSON files with compatibility descriptions in the compatibility package;
|
|
|
|
# 3. For each such file, we define all the described rpc methods;
|
|
|
|
# 4. For each rpc method in each compatibility file, we check that the updated version information is present.
|
|
|
|
compatibility:
|
|
|
|
@version=$$(jq -r '.milestone' version.json).$$(jq -r '.patch' version.json); \
|
|
|
|
conflicts=0; \
|
|
|
|
for f in `ls compatibility/*.json`; do \
|
|
|
|
for rpc in $$(jq -r '.[] | to_entries | .[].key' $$f); do \
|
|
|
|
if $$(jq -r '.[].'$$rpc' | has("v'$$version'") | not' $$f); then \
|
|
|
|
echo "⇒ No compatibility information found for version" $$version "in file" $$f "for rpc" $$rpc; \
|
|
|
|
conflicts=$$(($conflicts+1)); \
|
|
|
|
fi \
|
|
|
|
done \
|
|
|
|
done; \
|
|
|
|
exit $$conflicts;
|
|
|
|
|
2024-09-02 11:59:24 +00:00
|
|
|
# Activate pre-commit hooks
|
|
|
|
pre-commit:
|
|
|
|
pre-commit install --hook-type pre-commit
|
|
|
|
|
|
|
|
# Deactivate pre-commit hooks
|
|
|
|
unpre-commit:
|
|
|
|
pre-commit uninstall --hook-type pre-commit
|
|
|
|
|
|
|
|
# Run pre-commit hooks
|
|
|
|
pre-commit-run:
|
|
|
|
@pre-commit run --all-files --hook-stage manual
|