backbeat: add module sources
This commit is contained in:
206
contracts/tests/integration/Makefile
Normal file
206
contracts/tests/integration/Makefile
Normal file
@@ -0,0 +1,206 @@
|
||||
# BACKBEAT Contracts CI Integration Makefile
|
||||
|
||||
# Variables
|
||||
SCHEMA_DIR = ../../schemas
|
||||
EXAMPLES_DIR = ../examples
|
||||
CLI_TOOL = ./cmd/backbeat-validate
|
||||
BINARY_NAME = backbeat-validate
|
||||
|
||||
# Default target
|
||||
.PHONY: all
|
||||
all: build test
|
||||
|
||||
# Build the CLI validation tool
|
||||
.PHONY: build
|
||||
build:
|
||||
@echo "Building BACKBEAT validation CLI tool..."
|
||||
go build -o $(BINARY_NAME) $(CLI_TOOL)
|
||||
|
||||
# Run all tests
|
||||
.PHONY: test
|
||||
test: test-schemas test-examples test-integration
|
||||
|
||||
# Test schema files are valid
|
||||
.PHONY: test-schemas
|
||||
test-schemas:
|
||||
@echo "Testing JSON schema files..."
|
||||
@for schema in $(SCHEMA_DIR)/*.schema.json; do \
|
||||
echo "Validating schema: $$schema"; \
|
||||
python3 -c "import json; json.load(open('$$schema'))" || exit 1; \
|
||||
done
|
||||
|
||||
# Test all example files
|
||||
.PHONY: test-examples
|
||||
test-examples: build
|
||||
@echo "Testing example messages..."
|
||||
./$(BINARY_NAME) --schemas $(SCHEMA_DIR) --dir $(EXAMPLES_DIR)
|
||||
|
||||
# Run Go integration tests
|
||||
.PHONY: test-integration
|
||||
test-integration:
|
||||
@echo "Running Go integration tests..."
|
||||
go test -v ./...
|
||||
|
||||
# Validate built-in examples
|
||||
.PHONY: validate-examples
|
||||
validate-examples: build
|
||||
@echo "Validating built-in examples..."
|
||||
./$(BINARY_NAME) --schemas $(SCHEMA_DIR) --examples
|
||||
|
||||
# Validate a specific directory (for CI use)
|
||||
.PHONY: validate-dir
|
||||
validate-dir: build
|
||||
@if [ -z "$(DIR)" ]; then \
|
||||
echo "Usage: make validate-dir DIR=/path/to/messages"; \
|
||||
exit 1; \
|
||||
fi
|
||||
./$(BINARY_NAME) --schemas $(SCHEMA_DIR) --dir $(DIR) --exit-code
|
||||
|
||||
# Validate a specific file (for CI use)
|
||||
.PHONY: validate-file
|
||||
validate-file: build
|
||||
@if [ -z "$(FILE)" ]; then \
|
||||
echo "Usage: make validate-file FILE=/path/to/message.json"; \
|
||||
exit 1; \
|
||||
fi
|
||||
./$(BINARY_NAME) --schemas $(SCHEMA_DIR) --file $(FILE) --exit-code
|
||||
|
||||
# Clean build artifacts
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f $(BINARY_NAME)
|
||||
|
||||
# Install dependencies
|
||||
.PHONY: deps
|
||||
deps:
|
||||
go mod tidy
|
||||
go mod download
|
||||
|
||||
# Format Go code
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
go fmt ./...
|
||||
|
||||
# Run static analysis
|
||||
.PHONY: lint
|
||||
lint:
|
||||
go vet ./...
|
||||
|
||||
# Generate CI configuration examples
|
||||
.PHONY: examples
|
||||
examples: generate-github-actions generate-gitlab-ci generate-makefile-example
|
||||
|
||||
# Generate GitHub Actions workflow
|
||||
.PHONY: generate-github-actions
|
||||
generate-github-actions:
|
||||
@echo "Generating GitHub Actions workflow..."
|
||||
@mkdir -p ci-examples
|
||||
@cat > ci-examples/github-actions.yml << 'EOF'\
|
||||
name: BACKBEAT Contract Validation\
|
||||
\
|
||||
on:\
|
||||
push:\
|
||||
branches: [ main, develop ]\
|
||||
pull_request:\
|
||||
branches: [ main ]\
|
||||
\
|
||||
jobs:\
|
||||
validate-backbeat-messages:\
|
||||
runs-on: ubuntu-latest\
|
||||
\
|
||||
steps:\
|
||||
- uses: actions/checkout@v4\
|
||||
with:\
|
||||
repository: 'chorus-services/backbeat'\
|
||||
path: 'backbeat-contracts'\
|
||||
\
|
||||
- uses: actions/checkout@v4\
|
||||
with:\
|
||||
path: 'current-repo'\
|
||||
\
|
||||
- name: Set up Go\
|
||||
uses: actions/setup-go@v4\
|
||||
with:\
|
||||
go-version: '1.22'\
|
||||
\
|
||||
- name: Build BACKBEAT validator\
|
||||
run: |\
|
||||
cd backbeat-contracts/contracts/tests/integration\
|
||||
make build\
|
||||
\
|
||||
- name: Validate BACKBEAT messages\
|
||||
run: |\
|
||||
cd backbeat-contracts/contracts/tests/integration\
|
||||
./backbeat-validate \\\
|
||||
--schemas ../../schemas \\\
|
||||
--dir ../../../current-repo/path/to/messages \\\
|
||||
--exit-code\
|
||||
EOF
|
||||
|
||||
# Generate GitLab CI configuration
|
||||
.PHONY: generate-gitlab-ci
|
||||
generate-gitlab-ci:
|
||||
@echo "Generating GitLab CI configuration..."
|
||||
@mkdir -p ci-examples
|
||||
@cat > ci-examples/gitlab-ci.yml << 'EOF'\
|
||||
validate-backbeat-contracts:\
|
||||
stage: test\
|
||||
image: golang:1.22\
|
||||
\
|
||||
before_script:\
|
||||
- git clone https://github.com/chorus-services/backbeat.git /tmp/backbeat\
|
||||
- cd /tmp/backbeat/contracts/tests/integration\
|
||||
- make deps build\
|
||||
\
|
||||
script:\
|
||||
- /tmp/backbeat/contracts/tests/integration/backbeat-validate \\\
|
||||
--schemas /tmp/backbeat/contracts/schemas \\\
|
||||
--dir $$CI_PROJECT_DIR/path/to/messages \\\
|
||||
--exit-code\
|
||||
\
|
||||
only:\
|
||||
- merge_requests\
|
||||
- main\
|
||||
- develop\
|
||||
EOF
|
||||
|
||||
# Generate example Makefile for downstream projects
|
||||
.PHONY: generate-makefile-example
|
||||
generate-makefile-example:
|
||||
@echo "Generating example Makefile for downstream projects..."
|
||||
@mkdir -p ci-examples
|
||||
@echo "# Example Makefile for BACKBEAT contract validation" > ci-examples/downstream-makefile
|
||||
@echo "" >> ci-examples/downstream-makefile
|
||||
@echo "BACKBEAT_REPO = https://github.com/chorus-services/backbeat.git" >> ci-examples/downstream-makefile
|
||||
@echo "BACKBEAT_DIR = .backbeat-contracts" >> ci-examples/downstream-makefile
|
||||
@echo "" >> ci-examples/downstream-makefile
|
||||
@echo "validate-backbeat:" >> ci-examples/downstream-makefile
|
||||
@echo " git clone \$$(BACKBEAT_REPO) \$$(BACKBEAT_DIR) 2>/dev/null || true" >> ci-examples/downstream-makefile
|
||||
@echo " cd \$$(BACKBEAT_DIR)/contracts/tests/integration && make build" >> ci-examples/downstream-makefile
|
||||
@echo " \$$(BACKBEAT_DIR)/contracts/tests/integration/backbeat-validate --schemas \$$(BACKBEAT_DIR)/contracts/schemas --dir messages --exit-code" >> ci-examples/downstream-makefile
|
||||
|
||||
# Help target
|
||||
.PHONY: help
|
||||
help:
|
||||
@echo "BACKBEAT Contracts CI Integration Makefile"
|
||||
@echo ""
|
||||
@echo "Available targets:"
|
||||
@echo " all - Build and test everything"
|
||||
@echo " build - Build the CLI validation tool"
|
||||
@echo " test - Run all tests"
|
||||
@echo " test-schemas - Validate JSON schema files"
|
||||
@echo " test-examples - Test example message files"
|
||||
@echo " test-integration - Run Go integration tests"
|
||||
@echo " validate-examples - Validate built-in examples"
|
||||
@echo " validate-dir DIR=path - Validate messages in directory"
|
||||
@echo " validate-file FILE=path - Validate single message file"
|
||||
@echo " clean - Clean build artifacts"
|
||||
@echo " deps - Install Go dependencies"
|
||||
@echo " fmt - Format Go code"
|
||||
@echo " lint - Run static analysis"
|
||||
@echo " examples - Generate CI configuration examples"
|
||||
@echo " help - Show this help message"
|
||||
@echo ""
|
||||
@echo "Examples:"
|
||||
@echo " make validate-dir DIR=../../../examples"
|
||||
@echo " make validate-file FILE=../../../examples/beatframe-valid.json"
|
||||
Reference in New Issue
Block a user