|
1 | 1 | <div align="center"> |
2 | | - <h1>JAIPilot - Autogenerate High Coverage Java Unit Tests</h1> |
3 | | - <p><strong>JAIPilot automatically writes high quality unit tests for your PR to achieve high coverage for Java codebases.</strong></p> |
| 2 | + <img src="docs/assets/jaipilot-logo.svg" alt="JAIPilot logo" width="320" /> |
| 3 | + <h1>JAIPilot GitHub Action</h1> |
| 4 | + <p><strong>Automatically generate high-coverage Java unit tests on every pull request.</strong></p> |
4 | 5 | <p> |
5 | 6 | <a href="https://github.com/JAIPilot/jaipilot-cli/actions/workflows/ci.yml"> |
6 | 7 | <img src="https://github.com/JAIPilot/jaipilot-cli/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI"> |
|
13 | 14 | </a> |
14 | 15 | </p> |
15 | 16 | <p> |
16 | | - <a href="#install"><strong>Install</strong></a> |
17 | | - · |
18 | 17 | <a href="#quick-start"><strong>Quick Start</strong></a> |
19 | 18 | · |
| 19 | + <a href="#inputs"><strong>Inputs</strong></a> |
| 20 | + · |
| 21 | + <a href="#outputs"><strong>Outputs</strong></a> |
| 22 | + · |
20 | 23 | <a href="#how-it-works"><strong>How It Works</strong></a> |
21 | 24 | </p> |
22 | 25 | </div> |
23 | 26 |
|
24 | 27 | <p align="center"> |
25 | | - JAIPilot automatically writes high quality unit tests for your PR to achieve high coverage for Java codebases. |
| 28 | + This repository is focused on the JAIPilot GitHub Action for PR automation. |
26 | 29 | </p> |
27 | 30 |
|
28 | 31 | <hr /> |
29 | 32 |
|
30 | | -JAIPilot automatically generates high quality high coverage unit tests for PRs for your Java codebase. |
31 | | - |
32 | | -## Why JAIPilot |
33 | | - |
34 | | -- Automatically generates high quality high coverage unit tests for PRs for your Java codebase |
35 | | -- All generated tests are fully compilable, executable, and maximize line coverage |
36 | | -- Analyzes changed Java code and context for every PR to generate high quality meaningful tests |
37 | | -- Builds, executes, and maximizes line coverage |
38 | | - |
39 | | -## GitHub Action (PR Automation) |
40 | | - |
41 | | -To run JAIPilot automatically on pull requests with this action, you must provide your JAIPilot license key to the workflow. |
42 | | -Get the key by logging in at `https://jaipilot.com` (free credits are available). |
43 | | - |
44 | | -1. Go to your repository `Settings` -> `Secrets and variables` -> `Actions`. |
45 | | -2. Create a repository secret (for example `JAIPILOT_LICENSE_KEY`) and paste your JAIPilot license key as the value. |
46 | | -3. Reference that secret in your workflow input/env for the JAIPilot action. |
47 | | - |
48 | | -Without a valid license key configured in the action, JAIPilot will not auto-execute on PRs. |
49 | | - |
50 | | -## Install |
| 33 | +JAIPilot generates high-quality tests for changed Java production classes in pull requests and pushes the generated changes back to the PR branch. |
51 | 34 |
|
52 | | -Install with: |
| 35 | +## Why This Action |
53 | 36 |
|
54 | | -```sh |
55 | | -curl -fsSL https://jaipilot.com/install.sh | bash |
56 | | -``` |
57 | | - |
58 | | -That installs `jaipilot` into `~/.local/bin` by default, downloads the platform-specific release archive for your machine, and verifies the release archive SHA-256 checksum before unpacking it. |
59 | | - |
60 | | -Bundled-runtime releases target: |
61 | | - |
62 | | -- `linux-x64` |
63 | | -- `linux-aarch64` |
64 | | -- `macos-x64` |
65 | | -- `macos-aarch64` |
66 | | - |
67 | | -Make sure `~/.local/bin` is on your `PATH`. |
| 37 | +- Generates and updates tests for changed Java production classes in a PR |
| 38 | +- Commits generated tests back to the PR branch automatically |
| 39 | +- Supports Maven and Gradle repositories |
| 40 | +- Exposes processed and failed class counts as action outputs |
68 | 41 |
|
69 | | -## Usage Options |
| 42 | +## Prerequisites |
70 | 43 |
|
71 | | -You can use JAIPilot in either of these ways: |
72 | | - |
73 | | -- JAIPilot CLI (run locally with `jaipilot` commands) |
74 | | -- GitHub Action (run automatically on pull requests in GitHub) |
| 44 | +1. Get a JAIPilot license key from `https://jaipilot.com`. |
| 45 | +2. In the target repository, open `Settings -> Secrets and variables -> Actions`. |
| 46 | +3. Create a secret named `JAIPILOT_LICENSE_KEY`. |
| 47 | +4. Ensure your workflow job has `contents: write` permission so the action can push generated commits. |
75 | 48 |
|
76 | 49 | ## Quick Start |
77 | 50 |
|
78 | | -Set your JAIPilot license key: |
79 | | - |
80 | | -```sh |
81 | | -export JAIPILOT_LICENSE_KEY="your-license-key" |
| 51 | +```yaml |
| 52 | +name: JAIPilot Generate Tests |
| 53 | + |
| 54 | +on: |
| 55 | + pull_request: |
| 56 | + types: [opened, synchronize, reopened] |
| 57 | + |
| 58 | +jobs: |
| 59 | + jaipilot: |
| 60 | + runs-on: ubuntu-latest |
| 61 | + permissions: |
| 62 | + contents: write |
| 63 | + pull-requests: write |
| 64 | + |
| 65 | + steps: |
| 66 | + - name: Checkout |
| 67 | + uses: actions/checkout@v4 |
| 68 | + with: |
| 69 | + ref: ${{ github.head_ref }} |
| 70 | + |
| 71 | + - name: Run JAIPilot |
| 72 | + uses: JAIPilot/jaipilot-cli@action-v1 |
| 73 | + with: |
| 74 | + jaipilot-license-key: ${{ secrets.JAIPILOT_LICENSE_KEY }} |
82 | 75 | ``` |
83 | 76 |
|
84 | | -Get your license key by logging in at `https://jaipilot.com` (free credits are available). |
85 | | - |
86 | | -Generate a JUnit test for a class: |
87 | | - |
88 | | -```sh |
89 | | -jaipilot generate src/main/java/org/example/CrashController.java |
90 | | -``` |
| 77 | +## Inputs |
91 | 78 |
|
92 | | -## Commands |
| 79 | +| Input | Required | Default | Description | |
| 80 | +| --- | --- | --- | --- | |
| 81 | +| `working-directory` | No | `.` | Project directory where the action runs. | |
| 82 | +| `java-version` | No | `21` | Temurin Java version to install before generation. | |
| 83 | +| `install-script-url` | No | `https://jaipilot.com/install.sh` | Installer script URL used by the action. | |
| 84 | +| `jaipilot-license-key` | Yes | - | JAIPilot license key used to authorize generation. | |
| 85 | +| `fail-on-generate-error` | No | `true` | Fail the workflow if one or more classes fail generation. | |
| 86 | +| `commit-message` | No | `chore: generate tests with JAIPilot` | Commit message for generated test changes. | |
| 87 | +| `git-user-name` | No | `github-actions[bot]` | Git author name for generated commit. | |
| 88 | +| `git-user-email` | No | `41898282+github-actions[bot]@users.noreply.github.com` | Git author email for generated commit. | |
93 | 89 |
|
94 | | -JAIPilot CLI exposes only one command: |
| 90 | +## Outputs |
95 | 91 |
|
96 | | -- `jaipilot generate <path-to-class>` generates or updates a corresponding test file. |
| 92 | +| Output | Description | |
| 93 | +| --- | --- | |
| 94 | +| `processed-classes` | Number of changed Java production classes processed. | |
| 95 | +| `failed-classes` | Number of classes for which generation failed. | |
| 96 | +| `commit-sha` | Commit SHA pushed by the action; empty when no changes were committed. | |
97 | 97 |
|
98 | 98 | ## How It Works |
99 | 99 |
|
100 | | -`jaipilot generate` reads local source files, calls the backend generation API, polls for completion, writes the returned test file, and validates it with your build tool in three stages: compile, codebase rules, and targeted test execution (`test-compile`/`verify`/targeted `test` for Maven, `testClasses`/`check`/targeted `test --tests` for Gradle). Rule validation is run with full-suite test execution skipped because JAIPilot already runs targeted test validation separately. |
| 100 | +- Detects changed files from PR base branch (or previous commit for push events). |
| 101 | +- Filters to non-test `.java` production classes only. |
| 102 | +- Generates tests for each changed class. |
| 103 | +- Commits and pushes generated tests to the same branch. |
| 104 | +- Optionally fails the job when generation errors occur. |
101 | 105 |
|
102 | | -If validation fails, JAIPilot automatically performs iterative fixing passes using build failure logs. When required context classes are missing from local sources, JAIPilot can trigger dependency source download and retry. |
| 106 | +## Action Publishing |
103 | 107 |
|
104 | | -For Maven wrapper usage, JAIPilot only uses wrapper scripts when `.mvn/wrapper/maven-wrapper.properties` exists; otherwise it falls back to system `mvn`/`mvn.cmd`. |
| 108 | +See [docs/github-action-publishing.md](docs/github-action-publishing.md) for release tagging and publishing flow. |
105 | 109 |
|
106 | 110 | ## License |
107 | 111 |
|
|
0 commit comments