Skip to main content

πŸ§ͺ 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​

  1. You provide:
    • The current commit SHA
    • The branch name (e.g., main)
    • A valid API_KEY
    • A TOKEN for GitHub or another SCM
  2. The CLI scans the changed files in the commit.
  3. It finds low-covered functions and generates tests.
  4. 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 secret
    • TOKEN β€” 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_OPTIONS to avoid memory issues β†’ Memory Tuning β†’
  • βœ… For GitHub Packages, configure .npmrc properly β†’ 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

⏭️ What’s Next?​