5.5 KiB
Development and Contribution Guidelines
This document provides guidelines for developing and contributing to the PSOPNSenseAPI module.
Development Environment Setup
Prerequisites
- Visual Studio 2019 or later
- PowerShell 5.1 or PowerShell 7+
- .NET Framework 4.7.2 SDK (for Windows PowerShell 5.1 compatibility)
- .NET Core 3.1 SDK or later (for PowerShell 7+ compatibility)
- Git
Setting Up the Development Environment
-
Clone the repository:
git clone https://github.com/freedbygrace/PSOPNSenseAPI.git cd PSOPNSenseAPI -
Open the solution in Visual Studio:
start PSOPNSenseAPI.sln -
Restore NuGet packages:
dotnet restore -
Build the solution:
dotnet build
Coding Standards
C# Code Style
- Follow Microsoft's C# coding conventions
- Use meaningful names for classes, methods, and variables
- Add XML documentation comments to all public members
- Use proper exception handling
- Write unit tests for all functionality
- Keep methods small and focused on a single responsibility
- Use dependency injection where appropriate
- Avoid static methods except for utility functions
PowerShell Cmdlet Design
- Follow the PowerShell Verb-Noun naming convention
- Use approved PowerShell verbs (Get, Set, New, Remove, etc.)
- Implement proper parameter validation
- Support pipeline input where appropriate
- Implement ShouldProcess for cmdlets that make changes
- Provide meaningful error messages
- Write detailed help content
- Support common parameters (-Verbose, -Debug, etc.)
- Return appropriate objects, not strings
Documentation
- Document all public APIs with XML comments
- Include examples in cmdlet help
- Update README.md and other documentation when adding features
- Document breaking changes in CHANGELOG.md
Project Structure
The project follows this structure:
- src/PSOPNSenseAPI: Main source code
- Cmdlets: PowerShell cmdlets
- Models: Data models
- Services: Service classes for API communication
- Utilities: Utility classes
- Logging: Logging infrastructure
- tests: Unit and integration tests
- docs: Documentation
- build: Build scripts
- output: Build output (not in source control)
Development Workflow
Feature Development
-
Create a new branch from
main:git checkout -b feature/my-feature -
Implement the feature:
- Add model classes if needed
- Implement service classes
- Create PowerShell cmdlets
- Add unit tests
- Update documentation
-
Build and test locally:
.\build\build.ps1 .\build\test.ps1 -
Commit your changes with meaningful commit messages:
git commit -m "Add feature: description of the feature" -
Push your branch and create a pull request:
git push origin feature/my-feature
Bug Fixes
-
Create a new branch from
main:git checkout -b fix/bug-description -
Fix the bug:
- Add a test that reproduces the bug
- Fix the bug
- Verify that the test passes
-
Commit your changes:
git commit -m "Fix: description of the bug fix" -
Push your branch and create a pull request:
git push origin fix/bug-description
Testing
Unit Testing
- Write unit tests for all functionality
- Use xUnit for testing
- Mock external dependencies
- Aim for high code coverage
- Run tests before submitting pull requests
Integration Testing
- Write integration tests for API interactions
- Use a test OPNSense instance if possible
- Skip integration tests if no test instance is available
Running Tests
# Run all tests
.\build\test.ps1
# Run specific tests
dotnet test --filter "FullyQualifiedName~PSOPNSenseAPI.Tests.NetworkUtilityTests"
Building and Packaging
Building the Module
# Build the module
.\build\build.ps1
# Build a release version with automatic versioning
.\build\build-release.ps1 -Clean -Test -Package
Versioning
The module uses a versioning scheme of yyyy.MM.dd.HHmm for releases, which is automatically generated during the build process.
Creating a Release
- Update the CHANGELOG.md file
- Build a release package:
.\build\build-release.ps1 -Clean -Test -Package - Create a new release on GitHub with the generated package
Continuous Integration
The project uses GitHub Actions for continuous integration:
- Builds and tests are run on every push to the main branch
- Release packages are automatically created with the versioning scheme
- Release artifacts are uploaded to GitHub Releases
Pull Request Guidelines
When submitting a pull request:
- Ensure all tests pass
- Update documentation if needed
- Add entries to CHANGELOG.md for new features or bug fixes
- Follow the coding standards
- Keep pull requests focused on a single change
- Provide a clear description of the changes
- Link to any related issues
Code Review Process
All pull requests will be reviewed for:
- Code quality and style
- Test coverage
- Documentation
- Performance considerations
- Security implications
Release Process
- Merge approved pull requests into the main branch
- Update the version in the module manifest
- Update CHANGELOG.md
- Create a new release on GitHub
- Publish the module to PowerShell Gallery (if applicable)
Support
If you need help with development:
- Open an issue on GitHub
- Reach out to the maintainers
- Check the documentation and existing issues
License
All contributions to this project are subject to the terms of the MIT License.