π§ͺ Commit CLI β For Push-Based Workflows
The Early Commit CLI brings AI-powered unit test generation to pipelines triggered by code commits rather than pull requests.
Itβs perfect for environments that donβt operate on PR metadata β like Jenkins or GitHub Actions with on: push.
π When to Useβ
Use the Commit CLI agent when:
- You use push-based CI triggers (e.g.,
on: push) - Your workflow runs without pull request context
- You use Jenkins, GitHub Actions, or custom CI/CD tools
- You want to continuously generate tests for new commits
βοΈ How It Worksβ
- You provide:
- The current commit SHA
- The branch name (e.g.,
main) - A valid API_KEY
- A TOKEN for GitHub or another SCM
- The CLI scans the changed files in the commit.
- It finds low-covered functions and generates tests.
- If
AUTO_COMMIT=true, the files are committed automatically.
π Requirementsβ
Before using this agent:
- β Install the CLI β NPM Authentication β
- β
Set these required environment variables:
API_KEYβ Your Early-provided secretTOKENβ SCM token with access to repo (GitHub PAT, Bitbucket App PW) β Token Permissions βREF_NAMEβ The name of the branch (e.g.,main)COMMIT_HASHβ The commit SHA to analyze
- β
Configure
NODE_OPTIONSto avoid memory issues β Memory Tuning β - β
For GitHub Packages, configure
.npmrcproperly β NPM Authentication β
π§ͺ First Integration Stepβ
A GitHub Actions example:
name: early-catch
permissions:
contents: write
packages: read
on:
push:
branches:
- main
jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- run: |
echo "@earlyai:registry=https://npm.pkg.github.com" >> ~/.npmrc
echo "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
- run: npm install -g @earlyai/cli
- name: Generate tests
env:
API_KEY: ${{ secrets.EARLY_SECRET_TOKEN }}
TOKEN: ${{ secrets.REPO_TOKEN }}
REF_NAME: ${{ github.ref_name }}
COMMIT_HASH: ${{ github.sha }}
NODE_OPTIONS: --max-old-space-size=5120
run: early generate-commit