Skip to content

feat: add validation and semver utility modules#70

Open
AdekunleBamz wants to merge 1 commit intoExodusMovement:masterfrom
AdekunleBamz:feat/add-validation-and-semver-utilities
Open

feat: add validation and semver utility modules#70
AdekunleBamz wants to merge 1 commit intoExodusMovement:masterfrom
AdekunleBamz:feat/add-validation-and-semver-utilities

Conversation

@AdekunleBamz
Copy link

Summary

This PR adds two comprehensive utility modules to enhance input validation and semantic versioning operations for the lerna release action.

Changes

New Files

src/utils/validation.ts - Input validation utilities:

  • isValidPackageName() - Validates npm package naming conventions (scoped and unscoped)
  • getPackageScope() - Extracts scope from scoped package names
  • getUnscopedName() - Gets the unscoped portion of a package name
  • isNonEmptyString() - Type guard for non-empty strings
  • validatePackagesCsv() - Parses and validates comma-separated package lists
  • isValidBranchName() - Validates git branch naming rules
  • isValidGitHubTokenFormat() - Validates GitHub token format (PAT, OAuth, App tokens)
  • sanitizeForShell() - Removes dangerous shell characters from input
  • isValidWorkflowId() - Validates workflow filename or numeric ID format
  • isValidCommitType() - Validates conventional commit types
  • assertInput() - Assertion helper with descriptive error messages

src/utils/semver.ts - Semantic versioning utilities:

  • isValidSemVer() - Validates semantic version strings
  • parseSemVer() / formatSemVer() - Parse and format SemVer objects
  • compareSemVer() - Compare two versions (supports prereleases)
  • sortSemVer() - Sort version arrays ascending or descending
  • getHighestVersion() / getLowestVersion() - Find version extremes
  • bumpVersion() - Increment versions (major/minor/patch/pre*)
  • satisfiesGte() / satisfiesLt() - Version range checking
  • isPrerelease() - Detect prerelease versions
  • extractVersionFromTag() - Extract version from git tags like @scope/pkg@1.0.0
  • getStableVersions() / getPrereleaseVersions() - Filter version lists
  • getPrereleaseIdentifier() - Extract prerelease identifier (alpha, beta, etc.)

Test Coverage

  • 47 tests for validation utilities
  • 46 tests for semver utilities
  • All 197 total tests pass

Benefits

  • Input Safety: Helps prevent injection attacks and validate user inputs before processing
  • Version Management: Enables intelligent version handling for release workflows
  • Reusability: Well-typed utilities that can be used across the codebase
  • Maintainability: Follows existing project patterns and code style

- Add validation.ts with input validation utilities:
  - Package name validation (npm naming conventions)
  - Package scope extraction
  - CSV package list validation
  - Git branch name validation
  - GitHub token format validation
  - Workflow ID validation
  - Commit type validation for conventional commits
  - Shell input sanitization

- Add semver.ts with semantic versioning utilities:
  - SemVer parsing and formatting
  - Version comparison and sorting
  - Version bumping (major/minor/patch/pre*)
  - Prerelease detection and filtering
  - Tag version extraction
  - Version range checking

- Add comprehensive test suites:
  - 47 tests for validation utilities
  - 46 tests for semver utilities
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant