Development Best Practices#
This guide outlines the best practices for development workflows, Git usage, and deployment processes for OCRG projects.
Trunk-Based Development#
We follow a trunk-based development workflow, which means:
- The main branch (
main
) is always stable and deployable - Feature development happens in short-lived feature branches
- Feature branches are merged back to main frequently through pull requests
- Long-lived feature branches are avoided
Benefits of Trunk-Based Development#
- Reduces merge conflicts
- Enables continuous integration
- Improves collaboration
- Makes deployment more reliable
Git Workflow Best Practices#
Branching Strategy#
- Main Branch: The
main
branch is the primary branch and is always deployable. - Production Branch: The
gh-pages
branch contains the built site and is automatically updated when changes are merged tomain
. -
Feature Branches: Create a feature branch for each new feature or bug fix:
# Create and switch to a new branch git checkout -b feature/descriptive-feature-name # Switch to an existing branch git checkout branch-name # List all branches git branch # List all branches including remote git branch -a # Push a new branch to GitHub git push -u origin branch-name # Update your branch with latest main git checkout main git pull git checkout your-branch git merge main
-
Naming Conventions: Use prefixes for branch names:
feature/
for new featuresbugfix/
for bug fixeshotfix/
for urgent production fixesdocs/
for documentation updates
Commit Practices#
Atomic Commits#
Make small, focused commits that do one thing well:
- Each commit should represent a single logical change
- Keep commits small and focused on a single aspect
- Ensure each commit leaves the codebase in a working state
Good Atomic Commit Example:
Commit Messages#
Write clear, descriptive commit messages:
- Use the imperative mood ("Add feature" not "Added feature")
- First line should be 50 characters or less (summary)
- Optionally, follow with a blank line and detailed explanation
- Reference issue numbers when applicable
Good Commit Message Format:
Fix release badge in README
- Updated the badge URL to use cache-busting parameters
- Ensures badge always shows the latest release version
- Fixes issue #42
Pull Request Workflow#
-
Create Feature Branch from main:
-
Make Changes with good commits
- Push Branch to the remote repository:
- Create Pull Request with a clear description:
- What changes were made
- Why they were made
- How to test them
- Any related issues
- Code Review by at least one other team member
- Address Feedback if any changes are requested:
- Merge the PR using the "Merge" strategy (or "Squash and Merge" for cleanup)
- Delete the Branch after merging:
Code Review Guidelines#
- Be respectful and constructive
- Focus on the code, not the person
- Look for:
- Bugs and edge cases
- Code clarity and readability
- Performance issues
- Consistency with existing code
- Test coverage
Deployment Process#
We use GitHub Actions for continuous integration and deployment:
- Automated Tests run on every push and PR
- Build Process creates production-ready assets
- Deployment happens automatically when changes are merged to main:
- The site is built using MkDocs
- The built site is deployed to the
gh-pages
branch - The deployment only occurs on merges to
main
, not on PRs - The
gh-pages
branch is automatically updated with the latest build
Release Process#
- Semantic Versioning: We follow semantic versioning (MAJOR.MINOR.PATCH)
- Changelog: Update the CHANGELOG.md file with all notable changes
- Tags: Create a Git tag for each release:
- Release Notes: Create detailed release notes on GitHub
Development Environment Setup#
Ensure your development environment is consistent:
- Use the recommended Node.js version (see README)
- Install all dependencies with
npm install
- Follow the code style guidelines with linters and formatters
- Run tests locally before pushing changes
Conclusion#
Following these best practices ensures:
- Consistent, high-quality code
- Smooth collaboration between team members
- Reliable, reproducible deployments
- Clear project history and documentation
Remember: The goal is to make development efficient, collaborative, and maintainable!
Other useful commands ``` git commit --amend --no-edit