Contributing to Pact Erlang
View SourceThank you for your interest in contributing to Pact Erlang! This document provides guidelines and information for contributors.
Table of Contents
- Code of Conduct
- How to Contribute
- Development Setup
- Development Workflow
- Testing
- Code Style and Standards
- Pull Request Process
- Release Process
- Getting Help
Code of Conduct
This project adheres to a code of conduct that we expect all contributors to follow. Please be respectful and considerate in all interactions.
How to Contribute
Reporting Issues
Before creating an issue, please:
- Search existing issues to avoid duplicates
- Use the latest version to ensure the issue hasn't been fixed
- Provide detailed information including:
- Erlang/OTP version
- Operating system
- Steps to reproduce
- Expected vs actual behavior
- Relevant logs or error messages
Suggesting Enhancements
Enhancement suggestions are welcome! Please:
- Check if the enhancement already exists in issues or discussions
- Describe the use case and why it would be valuable
- Provide examples of how the feature would be used
- Consider backward compatibility implications
Contributing Code
We welcome code contributions! Types of contributions include:
- Bug fixes
- New features
- Performance improvements
- Documentation improvements
- Test coverage improvements
- Examples and tutorials
Development Setup
Prerequisites
- Erlang/OTP: Version 25, 26, 27, or 28
- Rebar3: Version 3.24.0 or later
- Git: For version control
- Make: For build automation
- C compiler: GCC or Clang (for compiling NIFs)
- curl: For downloading Pact FFI library
Platform Support
- Linux: x86_64, aarch64
- macOS: x86_64, arm64 (Apple Silicon)
Initial Setup
Fork the repository on GitHub
Clone your fork:
git clone https://github.com/YOUR_USERNAME/pact_erlang.git cd pact_erlang
Add upstream remote:
git remote add upstream https://github.com/greyorange-labs/pact_erlang.git
Install dependencies and compile:
make compile
Project Structure
pact_erlang/
├── src/ # Erlang source files
├── c_src/ # C NIF source files
│ ├── include/ # C header files
│ ├── pactffi_nif.c # Main NIF implementation
│ ├── pact_verifier_external.c # Standalone verifier executable
│ └── Makefile # C build configuration
├── test/ # Test suites
├── shell_scripts/ # test scripts
├── priv/ # Private files (compiled artifacts)
├── _build/ # Rebar3 build artifacts
├── CHANGELOG.md
├── CONTRIBUTING.md
├── README.md
├── LICENSE
├── Makefile
├── rebar.config
├── rebar.lock
├── codecov.json
└── ct-docker-compose.yml
Development Workflow
Branching Strategy
- Main branch:
develop
(default branch for development) - Feature branches:
feature/your-feature-name
- Bug fix branches:
fix/issue-description
Making Changes
Create a feature branch:
git checkout develop git pull upstream develop git checkout -b feature/your-feature-name
Make your changes following the coding standards
Add tests for new functionality
Update documentation as needed
Run the test suite to ensure everything works
Commit your changes with clear messages
Commit Message Format
Use clear, descriptive commit messages:
type(scope): short description
Longer description if needed, explaining what and why.
Fixes #123
Types:
feat
: New featurefix
: Bug fixdocs
: Documentation changestest
: Adding or updating testsrefactor
: Code refactoringperf
: Performance improvementsbuild
: Build system changesci
: CI/CD changes
Testing
Running Tests
# Run all tests
make test
# Run tests with verbose output
rebar3 ct -v -c
# Run specific test suite
rebar3 ct --suite test/http_end_to_end_SUITE
# Generate coverage report
rebar3 cover -v
Test Types
- Unit Tests: Test individual modules and functions
- Integration Tests: Test interaction between components
- End-to-End Tests: Test complete workflows
- Message Pact Tests: Test asynchronous messaging contracts
- HTTP Pact Tests: Test HTTP API contracts
Writing Tests
- Follow existing patterns in the test directory
- Test both success and failure cases
- Use descriptive test names that explain what is being tested
- Include setup and cleanup as needed
- Add comments for complex test logic
Test Environment
Some tests require external services (like Pact Broker). Use the provided Docker Compose setup:
# Start test services
docker-compose -f ct-docker-compose.yml up -d
# Run tests
make test
# Stop services
docker-compose -f ct-docker-compose.yml down
Code Style and Standards
Erlang Code Style
This project uses erlfmt
for consistent formatting:
# Check formatting
make check-format
# Auto-format code
make format
Key Style Guidelines:
- Use 4 spaces for indentation
- Line length limit: 120 characters
- Use descriptive variable names
- Add type specs for exported functions
- Include documentation for public APIs
- Follow OTP design principles
C Code Style
For C NIFs:
- Use consistent indentation (4 spaces)
- Follow K&R style guidelines
- Include proper error handling
- Add comments for complex logic
- Use meaningful variable names
Documentation
- Public APIs: Must have comprehensive documentation
- Complex functions: Should have inline comments
- Examples: Include usage examples in documentation
- README updates: Update README.md when adding major features
Pull Request Process
Before Submitting
Ensure all tests pass:
make test
Run static analysis:
make checks
Update documentation if needed
Add changelog entry if applicable
Submitting the PR
- Push your branch to your fork
- Create a Pull Request against the
develop
branch - Fill out the PR template completely
- Link related issues using keywords (e.g., "Fixes #123")
PR Requirements
- ✅ All CI checks must pass
- ✅ Code coverage should not decrease
- ✅ All conversations must be resolved
- ✅ At least one maintainer approval required
- ✅ Up-to-date with target branch
Review Process
- Automated checks run on every PR
- Maintainer review for code quality and design
- Testing on multiple platforms
- Documentation review if applicable
- Final approval and merge
Release Process
Version Management
This project uses Semantic Versioning:
- MAJOR: Breaking changes
- MINOR: New features (backward compatible)
- PATCH: Bug fixes (backward compatible)
Release Steps
- Update version in
src/pact_erlang.app.src
- Update
CHANGELOG.md
with release notes - Commit changes and create a git tag
- Push tag to trigger release workflow
- Publish to Hex.pm
Example release checklist from README:
- Update version in
src/pact_erlang.app.src
- Update CHANGELOG.md
- Run
rebar3 hex publish --dry-run
- Commit files and add git tag
- Push to remote
- Run
rebar3 hex publish
Static Analysis and Quality Checks
The project includes several quality assurance tools:
# Run all checks
make checks
# Individual checks
make xref # Cross-reference analysis
make dialyzer # Static type analysis
make check-format # Code formatting check
Dialyzer
Dialyzer performs static analysis to find type errors:
rebar3 as dialyzer dialyzer
Add type specifications to help Dialyzer:
-spec function_name(Arg1Type, Arg2Type) -> ReturnType.
Xref
Cross-reference analysis finds unused functions and calls to undefined functions:
rebar3 xref
Platform-Specific Notes
Linux Development
- Supports x86_64 and aarch64 architectures
- Uses system GCC compiler
- Builds standalone verifier executable
macOS Development
- Supports both Intel and Apple Silicon
- Uses Xcode command line tools
- May require additional setup for C compilation
Dependencies
The project automatically downloads required dependencies:
- Pact FFI Library: Downloaded during build process
- Erlang Dependencies: Managed by Rebar3
- C Headers: Included in the repository
Troubleshooting
Common Issues
Compilation Failures:
- Ensure you have a C compiler installed
- Check that Erlang development headers are available
- Verify network access for downloading Pact FFI library
Test Failures:
- Ensure all required services are running
- Check for port conflicts
- Verify test data is properly set up
NIF Loading Issues:
- Ensure the shared library was compiled correctly
- Check architecture compatibility
- Verify library dependencies are available
Getting Debug Information
# Verbose compilation
make compile V=1
# Detailed test output
rebar3 ct -v -c --readable true
# Check NIF loading
erl -eval "application:start(pact_erlang), init:stop()."
Getting Help
Community Resources
- GitHub Issues: For bug reports and feature requests
- GitHub Discussions: For questions and general discussion
- Documentation: Available at hexdocs.pm/pact_erlang
Maintainer Contact
When reaching out:
- Search existing issues first
- Provide context about your environment and use case
- Include relevant code or error messages
- Be patient - maintainers contribute in their spare time
Contributing to Documentation
Documentation improvements are always welcome:
- Fix typos or unclear explanations
- Add missing examples
- Improve API documentation
- Add tutorials or guides
Thank you for contributing to Pact Erlang! Your contributions help make contract testing more accessible to the Erlang community.