Skip to main content

GitHub Actions + GitHub – PR Test Generation

This example shows how to run the Early Agent using GitHub Actions for a GitHub repository, generating tests automatically for pull requests using the generate-pr command.

The workflow:

  • Runs on pull requests
  • Installs project dependencies
  • Configures authentication
  • Invokes Early to generate and commit tests back to the PR branch

This setup is intentionally minimal and can be adapted to your existing GitHub Actions workflows.


🧩 How It Works

At a high level, the workflow performs the following steps:

  1. Checks out the repository
  2. Sets up Node.js
  3. Configures npm authentication for Early
  4. Installs dependencies
  5. Sets required environment variables
  6. Runs early generate-pr against the active pull request

Early detects changed files in the PR, evaluates coverage, and generates tests where needed.


🛠️ Example GitHub Actions Workflow

Below is a complete GitHub Actions workflow that integrates Early with GitHub:

name: early-pr-test-generation

on:
pull_request:

jobs:
early-test-generation:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
packages: read

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm

- name: Install dependencies
run: npm clean-install

- name: Install @earlyai/cli
run: npm install -g @earlyai/cli

- name: Setup environment variables and run Early
env:
API_KEY: ${{ secrets.EARLY_API_KEY }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
SCM_PROVIDER: github
PR_NUMBER: ${{ github.event.pull_request.number }}
REF_NAME: ${{ github.head_ref }}
TEST_FRAMEWORK: jest
NODE_OPTIONS: --max-old-space-size=5120
run: early generate-pr

🔐 Required Secrets

This workflow assumes the following secret is configured in your repository:

  • EARLY_API_KEY – Early API key

The built-in GITHUB_TOKEN is used for:

  • Pull request access
  • Committing generated test files
  • npm package authentication

✅ Notes

  • The workflow runs on every pull request.
  • PR_NUMBER is derived from the GitHub pull request context.
  • Generated tests are committed back to the PR branch.
  • Jest is explicitly set as the test framework (even though it is the default).
  • Memory limits are increased to support larger repositories.

This guide follows the general Integration Guide and adapts it specifically for GitHub Actions and GitHub.