Auto Release Automation CLI
auto is a comprehensive command-line interface (CLI) tool meticulously engineered to automate release workflows by leveraging semantic versioning conventions, primarily driven by GitHub Pull Request labels. As of its current stable version 11.3.6, the project maintains an active release cadence, frequently delivering bug fixes and incremental enhancements, as evidenced by its consistent patch and minor updates. A significant differentiator of `auto` lies in its label-driven methodology, which streamlines the release process without necessitating alterations to your codebase or drastic overhauls of existing development workflows. It integrates seamlessly into continuous integration/continuous delivery (CI/CD) pipelines while also supporting local execution. The tool features a modular architecture, extensible through a rich ecosystem of plugins (e.g., `@auto-it/npm`, `@auto-it/slack`), enabling users to adapt its functionality for diverse package managers and platforms. Furthermore, `auto` ships with robust TypeScript types, facilitating more reliable integration and development processes.
Common errors
-
Error: No GitHub token found. Please set the GH_TOKEN environment variable.
cause The `GH_TOKEN` environment variable is not set or is empty, preventing `auto` from authenticating with GitHub.fixSet the `GH_TOKEN` environment variable with a valid GitHub Personal Access Token (PAT) that has appropriate permissions (repo scope). -
Error: Could not find any valid labels on PR #XYZ to determine version bump.
cause The Pull Request `auto` is inspecting does not have any semantic versioning labels (e.g., `major`, `minor`, `patch`, `release`, `prerelease`, etc.) configured for your project.fixAdd a semantic versioning label to the Pull Request. Refer to your `.autorc` configuration or `auto init` defaults for valid labels. -
Error: Could not push to remote. Check your git credentials.
cause The git push operation failed, likely due to insufficient permissions or incorrect git credentials configured in the environment where `auto` is running.fixEnsure the `GH_TOKEN` has write access to the repository and that git is correctly configured with these credentials, especially in CI environments. -
Error: Could not publish to npm. Check your NPM_TOKEN environment variable.
cause The `NPM_TOKEN` environment variable is missing or invalid, or the npm plugin is misconfigured, preventing package publication.fixSet the `NPM_TOKEN` environment variable with a valid npm publish token. If using a private registry, ensure your `.npmrc` is correctly configured or pass `legacyAuth` option to the npm plugin.
Warnings
- breaking The `auto` CLI requires Node.js version 10 or higher. Older Node.js environments will result in execution failures or unexpected behavior.
- gotcha For `auto` to interact with GitHub (e.g., creating releases, commenting on PRs) and npm (for publishing), `GH_TOKEN` and `NPM_TOKEN` environment variables (respectively) are mandatory. Failure to set them will lead to authentication errors.
- gotcha Configuration options can be set via `.autorc` (camelCase) or CLI flags (snake-case). CLI flags always override `.autorc` settings for overlapping options. This can lead to unexpected behavior if not understood.
- breaking Versions of `auto` prior to v11.3.3 might encounter failures due to changes or deprecations in the GitHub API, as a bug fix to handle these deprecations was introduced in v11.3.3.
- gotcha For `auto` to correctly determine the next version and generate changelogs, your last release on GitHub must be tagged and explicitly marked as the 'Latest Release'. Without this, `auto` may not find a baseline to calculate diffs.
Install
-
npm install auto -
yarn add auto -
pnpm add auto
Imports
- auto
import { auto } from 'auto'npx auto [command]
- Auto, IPlugin
import { Auto, IPlugin } from 'auto'import { Auto, IPlugin } from '@auto-it/core' - NpmPlugin
import { NpmPlugin } from 'auto/npm'import { NpmPlugin } from '@auto-it/npm'
Quickstart
import { Auto, IPlugin } from '@auto-it/core';
import { NpmPlugin } from '@auto-it/npm';
import { GithubPlugin } from '@auto-it/github';
import { execSync } from 'child_process';
async function runAutoProgrammatically() {
// Set up required environment variables (replace with your actual tokens)
process.env.GH_TOKEN = process.env.GH_TOKEN ?? ''; // GitHub Personal Access Token
process.env.NPM_TOKEN = process.env.NPM_TOKEN ?? ''; // NPM Publish Token (if using NpmPlugin)
// Basic configuration for demonstration
const autoOptions = {
owner: 'your-org', // Replace with your GitHub organization/user
repo: 'your-repo', // Replace with your repository name
baseBranch: 'main', // Or your default branch
plugins: [
new NpmPlugin(),
new GithubPlugin(),
// Add other plugins as needed
],
};
try {
// Initialize auto (this usually happens via the CLI `auto init` for .autorc setup)
// For programmatic use, we instantiate `Auto` directly.
const auto = new Auto(autoOptions);
await auto.loadConfig(); // Load default config and apply plugin configs
// Example: Check if a release can be made
console.log('Checking for new releases...');
const newVersion = await auto.getVersion();
console.log(`Calculated next version: ${newVersion}`);
if (newVersion) {
console.log(`
To simulate a release process, run the following commands manually after setting up GitHub labels (major, minor, patch) on a PR:
1. Create a PR with a semantic label (e.g., 'minor')
2. Merge the PR
3. Set GH_TOKEN and NPM_TOKEN (if publishing to npm)
4. Execute 'npx auto shipit' or 'npx auto version' in your CI/local environment.
`);
// Programmatic execution of a 'version' command (simplified)
// In a real CI, this would involve more setup and error handling.
// For demonstration, we'll just show the concept.
// await auto.run('version'); // This would trigger versioning, changelog, etc.
} else {
console.log('No new version detected based on PR labels.');
}
} catch (error) {
console.error('An error occurred:', error instanceof Error ? error.message : error);
process.exit(1);
}
}
// To run the programmatic example:
// 1. npm install auto @auto-it/core @auto-it/npm @auto-it/github
// 2. Set GH_TOKEN and NPM_TOKEN environment variables.
// 3. Replace 'your-org' and 'your-repo'.
// 4. node your_script.js
runAutoProgrammatically();