releaser package provides utilities for fetching release information from GitHub and comparing versions. It’s useful for building CLI tools that need to notify users about available updates.
Overview
The releaser package offers:- Fetching latest release information from GitHub repositories
- Semantic version comparison
- Update check functionality for CLI tools
Key Features
Release Information
Fetch latest release details from GitHub repositories including version and download URLs
Version Comparison
Compare semantic versions to determine if updates are available
Update Notifications
Generate user-friendly update messages for CLI tools
Configurable Timeout
Control HTTP request timeouts for release checks
Types
Info
Holds information about a software release:Functions
FetchInfo
Fetches the latest release information from a GitHub repository:url: GitHub API URL (e.g.,https://api.github.com/repos/owner/repo/releases/latest)
*Info: Release information containing version and tarball URLerror: Error if the request fails or response is invalid
CompareVersions
Compares two semantic versions:current: Current version string (e.g.,"v1.0.0")latest: Latest version string (e.g.,"v1.2.0")
bool:trueif current version is greater than or equal to latest versionerror: Error if version parsing fails
CheckForUpdate
Convenience function that fetches the latest release and generates an update message:currentVersion: Current version of your application (e.g.,"v1.0.0")repo: GitHub repository in format"owner/repo"
string: Update message if a newer version is available, empty string otherwise
Configuration
Timeout
Control the HTTP client timeout for release checks:API Format
The GitHub API URL template (can be customized if needed):Complete Example
Here’s a complete example showing how to check for updates in a CLI tool:Advanced Usage
Custom Release Information
Fetch and process release information manually:Error Handling
The releaser package returns errors in several scenarios:- HTTP request failures: Network issues or invalid URLs
- Non-200 status codes: Repository not found or API rate limits
- JSON parsing errors: Invalid response format
- Version parsing errors: Invalid semantic version format
Best Practices
Background checks
Background checks
Run update checks in the background to avoid blocking application startup:
Cache results
Cache results
Cache update check results to avoid excessive API calls:
Handle rate limits
Handle rate limits
GitHub API has rate limits. Handle errors gracefully:
User-Agent header
User-Agent header
The package automatically sets a User-Agent header (
raystack/salt) for GitHub API requests. This helps with rate limiting and tracking.See Also
- Commander - CLI command management
- Printer - Terminal output utilities
- API Reference - Complete API documentation