๐ Integrating the Early CLI in Any CI/CD
The Early CLI lets you run AI-powered test generation on any CI/CD platform โ Jenkins, CircleCI, GitLab CI, Bitbucket Pipelines, and more. It mirrors the GitHub Action's logic and behavior but runs as a standalone CLI.
๐ฆ Setup Overviewโ
To get started, follow these steps:
1. Install the CLIโ
- JavaScript / TypeScript
- Python
npm install -g @earlyai/cli
See NPM Installation
npm install -g @earlyai/cli
pip install py-agent
Both packages are required: @earlyai/cli is the main CLI, and py-agent is the Python test generation engine.
2. Configure Required Inputsโ
All inputs are passed as environment variables:
API_KEYโ Your Early API keyTOKENโ SCM token (e.g., GitHub PAT, Bitbucket App Password) โ See SCM Support and Token PermissionsREF_NAMEโ Branch nameSCM_PROVIDERโ e.g.,githuborbitbucket
- JavaScript / TypeScript
- Python
Optional: AUTO_COMMIT, MAX_CONCURRENCY, NODE_OPTIONS, LINT_COMMAND, BASE_REF
- See Memory Tuning
- See Lint & Formatting
Optional: AUTO_COMMIT, AUTO_COMMIT_SKIP_CI, MAX_CONCURRENCY, TEST_FRAMEWORK (defaults to pytest), BASE_REF
The CLI auto-detects Python projects from file extensions and project markers (pyproject.toml, setup.py, requirements.txt).
3. Run the CLIโ
Use this command:
early generate-pr
๐งช GitHub Actions Exampleโ
- JavaScript / TypeScript
- Python
name: Early PR Test Generation
permissions:
contents: write
pull-requests: write
packages: read
on:
pull_request:
types: [opened]
branches:
- master
jobs:
early-test-generation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm clean-install
- name: Install Early CLI
run: npm install -g @earlyai/cli
- name: Early PR Test Generation
continue-on-error: true
env:
API_KEY: ${{ secrets.EARLY_API_KEY }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REF_NAME: ${{ github.head_ref }}
BASE_REF: ${{ github.base_ref }}
NODE_OPTIONS: "--max-old-space-size=5120"
run: early generate-pr
name: Early PR Test Generation
permissions:
contents: write
pull-requests: write
packages: read
on:
pull_request:
types: [opened]
branches:
- master
jobs:
early-test-generation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install project dependencies
run: pip install -r requirements.txt
- name: Install Early CLI and py-agent
run: |
npm install -g @earlyai/cli
pip install py-agent
- name: Early PR Test Generation
continue-on-error: true
env:
API_KEY: ${{ secrets.EARLY_API_KEY }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REF_NAME: ${{ github.head_ref }}
BASE_REF: ${{ github.base_ref }}
TEST_FRAMEWORK: pytest
MAX_CONCURRENCY: "3"
run: early generate-pr
๐งช Jenkins Exampleโ
- JavaScript / TypeScript
- Python
pipeline {
agent any
environment {
API_KEY = credentials('early-api-key')
TOKEN = credentials('github-pat')
REF_NAME = 'main'
SCM_PROVIDER = 'github'
AUTO_COMMIT = 'true'
NODE_OPTIONS = '--max-old-space-size=5120'
LINT_COMMAND = 'npx --no eslint $early_filename --fix'
PRETTIER_COMMAND = 'npx --no prettier $early_filename --write'
}
stages {
stage('Install CLI') {
steps {
sh 'npm install -g @earlyai/cli'
}
}
stage('Run CLI') {
steps {
sh 'early generate-pr'
}
}
}
}
pipeline {
agent any
environment {
API_KEY = credentials('early-api-key')
TOKEN = credentials('github-pat')
REF_NAME = 'main'
SCM_PROVIDER = 'github'
AUTO_COMMIT = 'true'
TEST_FRAMEWORK = 'pytest'
MAX_CONCURRENCY = '3'
}
stages {
stage('Install CLI and py-agent') {
steps {
sh 'npm install -g @earlyai/cli'
sh 'pip install py-agent'
}
}
stage('Install Python Dependencies') {
steps {
sh 'pip install -r requirements.txt'
}
}
stage('Run CLI') {
steps {
sh 'early generate-pr'
}
}
}
}
๐ CircleCI Exampleโ
- JavaScript / TypeScript
- Python
jobs:
generate-tests:
docker:
- image: cimg/node:20.5
steps:
- checkout
- run:
name: Install CLI
command: npm install -g @earlyai/cli
- run:
name: Generate Tests
command: early generate-pr
environment:
API_KEY: $EARLY_API_KEY
TOKEN: $GITHUB_TOKEN
REF_NAME: main
SCM_PROVIDER: github
AUTO_COMMIT: true
NODE_OPTIONS: "--max-old-space-size=5120"
LINT_COMMAND: "npx --no eslint $early_filename --fix"
PRETTIER_COMMAND: "npx --no prettier $early_filename --write"
jobs:
generate-tests:
docker:
- image: cimg/python:3.11-node
steps:
- checkout
- run:
name: Install CLI and py-agent
command: |
npm install -g @earlyai/cli
pip install py-agent
- run:
name: Install Python Dependencies
command: pip install -r requirements.txt
- run:
name: Generate Tests
command: early generate-pr
environment:
API_KEY: $EARLY_API_KEY
TOKEN: $GITHUB_TOKEN
REF_NAME: main
SCM_PROVIDER: github
AUTO_COMMIT: true
TEST_FRAMEWORK: pytest
MAX_CONCURRENCY: "3"
๐ป Local Run Exampleโ
- JavaScript / TypeScript
- Python
export API_KEY=xxx
export TOKEN=xxx
export REF_NAME=main
export SCM_PROVIDER=github
export AUTO_COMMIT=true
early generate-pr
export API_KEY=xxx
export TOKEN=xxx
export REF_NAME=main
export SCM_PROVIDER=github
export AUTO_COMMIT=true
export TEST_FRAMEWORK=pytest
early generate-pr
โ Success Criteriaโ
- JavaScript / TypeScript
- Python
- New test files appear alongside source files
- Logs include coverage analysis and test generation
- Pipeline exits cleanly with no errors
- Coverage improves for previously low-tested areas
- New test files appear in
.early.test/sibling folders (e.g.,src/utils.early.test/test_my_func_early.py) - Logs show file scanning, function extraction, and test generation progress
- Generated test files are auto-committed and pushed to the branch (when
AUTO_COMMIT=true) - Pipeline exits cleanly with no errors
โ Exit Codesโ
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Configuration or environment issue |
| 2 | Generation or validation failure |
| 3 | Commit/push failure |