CI/CD Pipeline
This document describes the Continuous Integration and Continuous Deployment (CI/CD) pipeline for the Subnetter project, including workflows, processes, and tools.
Overview
The Subnetter project implements a robust CI/CD pipeline consisting of several GitHub Actions workflows:
- CI/CD Workflow - Tests code, creates releases, and publishes packages when code is merged to main
- Pull Request Validation - Validates code changes in pull requests before merging
- Documentation Publishing - Deploys documentation to GitHub Pages
The pipelines are designed to ensure code quality, maintain test coverage, and automate the release process.
CI/CD Workflow
The main CI/CD workflow is defined in .github/workflows/ci-cd.yml
and handles testing, building, and releasing the project when changes are pushed to the main branch or when pull requests are created.
CI/CD Workflow Jobs
The workflow includes the following jobs:
-
Validate PR (only on pull requests):
- Checks that package-lock.json is not committed (Yarn-only project)
- Sets up Node.js
- Configures Yarn Berry
- Installs dependencies
- Lints commit messages
-
Test PR (only on pull requests):
- Sets up Node.js
- Configures Yarn Berry
- Installs dependencies
- Runs linting checks
- Builds the project with the correct order (cidr-utils → core → cli)
- Runs unit tests
- Runs end-to-end tests
-
Test Main Branch (only on push to main):
- Similar to Test PR but runs when changes are pushed to main
-
Check If Release Needed:
- Determines if a release is needed based on commit messages
- Uses conventional commits to identify changes that would trigger a release
-
Release (if needed):
- Sets up Node.js
- Configures Yarn Berry
- Configures Git for automated commits
- Installs dependencies
- Builds the project
- Runs the semantic-release process
Build Process
The CI/CD workflow builds packages in a specific order to ensure proper dependency resolution:
- Build
@subnetter/cidr-utils
first (foundation package) - Build
@subnetter/core
second (depends on cidr-utils) - Build
@subnetter/cli
last (depends on core)
This build order is explicitly defined in the workflow to prevent module resolution issues:
- name: Build run: | yarn build:cidr-utils yarn build:core yarn build:cli
Dependencies and Configuration
The CI/CD pipeline has been optimized to remove unnecessary dependencies and configurations:
- No System Dependencies: The pipeline does not require any specialized system dependencies as the project uses pure JavaScript/TypeScript
- Simplified Configuration: No custom
.npmrc
configuration is needed - Yarn Berry: Uses Yarn Berry’s zero-install features for improved dependency management
Pull Request Validation
Pull requests are validated through a series of checks to ensure they meet quality standards before being merged:
- Package-lock.json Check: Ensures no package-lock.json files are committed (Yarn-only project)
- Commit Message Linting: Validates that commit messages follow the conventional commits format
- Code Quality: Runs linting checks to ensure code style and quality standards
- Tests: Runs unit tests and end-to-end tests to ensure functionality
Documentation Publishing
The Documentation Publishing workflow automatically builds and deploys the documentation site to GitHub Pages when documentation files are changed or on manual triggers.
Documentation Publishing Process
- Build the TypeScript Projects: Builds all packages with proper order (cidr-utils → core → cli)
- Build the Documentation Site: Builds the Astro documentation site
- Deploy to GitHub Pages: Deploys the documentation to GitHub Pages
Release Process
The release process is automated and follows semantic versioning principles:
-
Version Determination:
- Patch version (1.0.x): For bug fixes (
fix:
commits) - Minor version (1.x.0): For new features (
feat:
commits) - Major version (x.0.0): For breaking changes (
feat!:
,fix!:
, orBREAKING CHANGE:
in commit body)
- Patch version (1.0.x): For bug fixes (
-
Release Creation:
- Updates version numbers
- Generates release notes
- Updates the changelog
- Creates a GitHub release
- Tags the repository
-
Package Publishing:
- Publishes packages to npm or GitHub Packages
- Follows the dependency order (cidr-utils → core → cli)
Workflow Dependencies
The CI/CD workflow has been optimized to ensure efficient execution:
- Workspace Dependencies: Uses the
"workspace:^"
syntax in package.json files to ensure proper linking between packages - Caching: Caches Yarn dependencies for faster builds
- Concurrency Control: Uses concurrency settings to prevent simultaneous releases
Local Development and CI Consistency
When developing locally, you can run the same checks that will be performed in the CI pipeline:
# Build all packages in the correct orderyarn build
# Build individual packagesyarn build:cidr-utilsyarn build:coreyarn build:cli
# Run lintingyarn lint
# Run testsyarn test
# Run end-to-end testsyarn test:e2e
Troubleshooting CI/CD Issues
Common CI Failures
-
Linting errors:
- Run
yarn lint
locally to identify and fix issues - Many linting errors can be automatically fixed with
yarn lint:fix
- Run
-
Test failures:
- Check the CI logs to see which tests are failing
- Run the specific failing tests locally to debug
- Make sure all tests pass locally before pushing
-
Dependency issues:
- Ensure dependencies are correctly declared in package.json files
- Use the
"workspace:^"
syntax for internal dependencies - Make sure the build order is correct
Recent Improvements
The CI/CD pipeline has been recently optimized:
-
Removed Unnecessary Dependencies: Eliminated system dependencies (libvips-dev, libjpeg-dev, libpng-dev) that were not required for the project, simplifying the build process.
-
Removed Sharp Configuration: Removed Sharp-specific configuration from the workflow, as the project doesn’t use image processing functionality.
-
Build Order: Ensured proper build order (cidr-utils → core → cli) to prevent module resolution issues.
-
Workspace Dependencies: Fixed workspace dependency references using the
"workspace:^"
syntax to ensure proper linking between packages.
These improvements have streamlined the build process and made it more reliable.
Conclusion
The CI/CD pipeline is a critical part of the Subnetter project, ensuring code quality, automating testing, and streamlining the release process. By leveraging GitHub Actions and other tools, we maintain a consistent and reliable development workflow that helps the project deliver high-quality software.
For more information about contributing to the project, see the Developer Guide and Contribution Guidelines.