Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/actions/test-report/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ inputs:
report-path:
description: "Path to the test report XML files (glob pattern)"
required: false
default: "target/surefire-reports*/TEST-*.xml"
default: "target/{surefire-reports*,failsafe-reports}/TEST-*.xml"
jacoco-path:
description: "Path to the JaCoCo XML report"
required: false
Expand All @@ -17,13 +17,17 @@ inputs:
description: "Name for the check run"
required: false
default: "Java SDK Test Results"
title:
description: "Title for the test report summary"
required: false
default: "Copilot Java SDK :: Test Results"
runs:
using: "composite"
steps:
- name: Generate Test Summary
shell: bash
run: |
echo "## 🧪 Copilot Java SDK :: Test Results" >> $GITHUB_STEP_SUMMARY
echo "## 🧪 ${{ inputs.title }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

if ls ${{ inputs.report-path }} 1>/dev/null 2>&1; then
Expand Down Expand Up @@ -148,7 +152,7 @@ runs:
if [ -f "$JACOCO_CSV" ]; then
extract_instruction_scope() {
local scope=$1
awk -F',' -v scope="$scope" -v generated_prefix="com.github.copilot.sdk.generated" '
awk -F',' -v scope="$scope" -v generated_prefix="com.github.copilot.generated" '
NR > 1 {
is_generated = index($2, generated_prefix) == 1
if ((scope == "generated" && is_generated) ||
Expand Down
83 changes: 55 additions & 28 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}

java-sdk:
name: "Java SDK Tests"
name: "Java SDK Tests (JDK ${{ matrix.test-jdk }})"
needs: smoke-test
if: ${{ always() && needs.smoke-test.result != 'failure' }}
permissions:
Expand All @@ -39,23 +39,40 @@ jobs:
pull-requests: write

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
test-jdk: ["25", "17"]
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 22

- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: "17"
java-version: "25"
distribution: "microsoft"
cache: "maven"

- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 22

- name: Build SDK and set up test harness
run: mvn test-compile jar:jar

- name: Verify Javadoc generation
if: matrix.test-jdk == '25'
run: mvn javadoc:javadoc -q

- name: Verify CLI works
run: node target/copilot-sdk/nodejs/node_modules/@github/copilot/index.js --version

- name: Run spotless check
if: matrix.test-jdk == '25'
run: |
mvn spotless:check
if [ $? -ne 0 ]; then
Expand All @@ -64,30 +81,27 @@ jobs:
fi
echo "✅ spotless:check passed"

- name: Build SDK and clone test harness
run: mvn test-compile

- name: Verify Javadoc generation
run: mvn javadoc:javadoc -q

- name: Install Copilot CLI from cloned SDK
id: setup-copilot
run: |
# Install dependencies in the cloned SDK's nodejs directory
# This ensures we use the same CLI version as the test harness expects
cd target/copilot-sdk/nodejs
npm ci --ignore-scripts
echo "path=$(pwd)/node_modules/@github/copilot/index.js" >> $GITHUB_OUTPUT
- name: Run Java SDK tests (JDK 25)
if: matrix.test-jdk == '25'
env:
CI: "true"
run: mvn verify -Dskip.test.harness=true

- name: Verify CLI works
run: node ${{ steps.setup-copilot.outputs.path }} --version
- name: Switch to JDK 17
if: matrix.test-jdk == '17'
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: "17"
distribution: "microsoft"

- name: Run Java SDK tests
- name: Run Java SDK tests (JDK 17, no recompilation)
if: matrix.test-jdk == '17'
env:
CI: "true"
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
COPILOT_CLI_PATH: ${{ steps.setup-copilot.outputs.path }}
run: mvn verify
run: |
echo "Running tests against JDK 25-built classes using JDK 17 runtime..."
java -version
mvn jacoco:prepare-agent@wire-up-coverage-instrumentation antrun:run@print-test-jdk-banner surefire:test failsafe:integration-test failsafe:verify jacoco:report@build-coverage-report-from-tests -Denforcer.skip=true

- name: Validate reference-impl-sync completeness
if: >-
Expand Down Expand Up @@ -123,7 +137,7 @@ jobs:
fi

- name: Upload test results for site generation
if: success() && github.ref == 'refs/heads/main'
if: success() && github.ref == 'refs/heads/main' && matrix.test-jdk == '25'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: test-results-for-site
Expand All @@ -134,11 +148,11 @@ jobs:
retention-days: 1

- name: Generate JaCoCo badge
if: success() && github.ref == 'refs/heads/main'
if: success() && github.ref == 'refs/heads/main' && matrix.test-jdk == '25'
run: .github/scripts/generate-coverage-badge.sh

- name: Create PR for JaCoCo badge update
if: success() && github.ref == 'refs/heads/main'
if: success() && github.ref == 'refs/heads/main' && matrix.test-jdk == '25'
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v7
with:
commit-message: "Update JaCoCo coverage badge"
Expand All @@ -151,3 +165,16 @@ jobs:
- name: Generate Test Report Summary
if: always()
uses: ./.github/actions/test-report
with:
title: "Copilot Java SDK :: Test Results JDK ${{ matrix.test-jdk }}"

- name: Upload test results on failure
if: failure()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: test-results-jdk-${{ matrix.test-jdk }}
path: |
target/surefire-reports/
target/surefire-reports-isolated/
Comment thread
edburns marked this conversation as resolved.
target/failsafe-reports/
retention-days: 7
80 changes: 31 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# GitHub Copilot SDK for Java

[![Build](https://github.com/github/copilot-sdk-java/actions/workflows/build-test.yml/badge.svg)](https://github.com/github/copilot-sdk-java/actions/workflows/build-test.yml)
[![Site](https://github.com/github/copilot-sdk-java/actions/workflows/deploy-site.yml/badge.svg)](https://github.com/github/copilot-sdk-java/actions/workflows/deploy-site.yml)
[![Handwritten Coverage](.github/badges/jacoco-handwritten.svg)](https://github.github.io/copilot-sdk-java/snapshot/jacoco/index.html)
[![Generated Coverage](.github/badges/jacoco-generated.svg)](https://github.github.io/copilot-sdk-java/snapshot/jacoco/index.html)
[![Documentation](https://img.shields.io/badge/docs-online-brightgreen)](https://github.github.io/copilot-sdk-java/)
[![Build](https://github.com/github/copilot-sdk/actions/workflows/java-sdk-tests.yml/badge.svg)](https://github.com/github/copilot-sdk/actions/workflows/java-sdk-tests.yml)
[![Java 17+](https://img.shields.io/badge/Java-17%2B-blue?logo=openjdk&logoColor=white)](https://openjdk.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

#### Latest release
[![GitHub Release Date](https://img.shields.io/github/release-date/github/copilot-sdk-java)](https://github.com/github/copilot-sdk-java/releases)
[![GitHub Release](https://img.shields.io/github/v/release/github/copilot-sdk-java)](https://github.com/github/copilot-sdk-java/releases)

[![GitHub Release Date](https://img.shields.io/github/release-date/github/copilot-sdk)](https://github.com/github/copilot-sdk/releases)
[![GitHub Release](https://img.shields.io/github/v/release/github/copilot-sdk)](https://github.com/github/copilot-sdk/releases)
[![Maven Central](https://img.shields.io/maven-central/v/com.github/copilot-sdk-java)](https://central.sonatype.com/artifact/com.github/copilot-sdk-java)
[![Documentation](https://img.shields.io/badge/docs-latest-brightgreen)](https://github.github.io/copilot-sdk-java/latest/)
[![Javadoc](https://javadoc.io/badge2/com.github/copilot-sdk-java/javadoc.svg?q=1)](https://javadoc.io/doc/com.github/copilot-sdk-java/latest/index.html)

## Background
Expand All @@ -23,21 +19,27 @@ Java SDK for programmatic control of GitHub Copilot CLI, enabling you to build A

## Installation

### Requirements
### Runtime requirements

- Java 17 or later. **JDK 25 recommended**. Selecting JDK 25 enables the use of virtual threads, as shown in the [Quick Start](#quick-start).
- GitHub Copilot CLI 1.0.17 or later installed and in `PATH` (or provide custom `cliPath`)
- Java 17 or later. **JDK 25 recommended**. The distributed jar is a multi-release jar (MR-JAR) and is compiled on JDK 25 with `maven.compiler.release` set to 17. This means, when run on JDK 25 and later, the SDK automatically uses virtual threads for its default internal executor.
- GitHub Copilot CLI 1.0.55-5. or later installed and in `PATH` (or provide custom `cliPath`)

### Maven

```xml
<dependency>
<groupId>com.github</groupId>
<artifactId>copilot-sdk-java</artifactId>
<version>1.0.0-beta-8-java.0</version>
<version>1.0.0-beta-10-java.0</version>
</dependency>
```

### Gradle

```groovy
implementation 'com.github:copilot-sdk-java:1.0.0-beta-10-java.0'


Comment thread
edburns marked this conversation as resolved.
#### Snapshot Builds

Snapshot builds of the next development version are published to Maven Central Snapshots. To use them, add the repository and update the dependency version in your `pom.xml`:
Expand All @@ -54,14 +56,14 @@ Snapshot builds of the next development version are published to Maven Central S
<dependency>
<groupId>com.github</groupId>
<artifactId>copilot-sdk-java</artifactId>
<version>1.0.0-beta-8-java.1-SNAPSHOT</version>
<version>1.0.0-beta-10-java.0-SNAPSHOT</version>
</dependency>
```

### Gradle

```groovy
implementation 'com.github:copilot-sdk-java:1.0.0-beta-8-java.0'
implementation 'com.github:copilot-sdk-java:1.0.0-beta-10-java.0-SNAPSHOT'
```

## Quick Start
Expand All @@ -70,23 +72,16 @@ implementation 'com.github:copilot-sdk-java:1.0.0-beta-8-java.0'
import com.github.copilot.CopilotClient;
import com.github.copilot.generated.AssistantMessageEvent;
import com.github.copilot.generated.SessionUsageInfoEvent;
import com.github.copilot.rpc.CopilotClientOptions;
import com.github.copilot.rpc.MessageOptions;
import com.github.copilot.rpc.PermissionHandler;
import com.github.copilot.rpc.SessionConfig;

import java.util.concurrent.Executors;

public class CopilotSDK {
public static void main(String[] args) throws Exception {
var lastMessage = new String[]{null};

// Create and start client
try (var client = new CopilotClient()) { // JDK 25+: comment out this line
// JDK 25+: uncomment the following 3 lines for virtual thread support
// var options = new CopilotClientOptions()
// .setExecutor(Executors.newVirtualThreadPerTaskExecutor());
// try (var client = new CopilotClient(options)) {
try (var client = new CopilotClient()) {
client.start().get();

// Create a session
Expand Down Expand Up @@ -130,31 +125,20 @@ See the full source of [`jbang-example.java`](jbang-example.java) for a complete
Or run it directly from the repository:

```bash
jbang https://github.com/github/copilot-sdk-java/blob/latest/jbang-example.java
jbang https://github.com/github/copilot-sdk/blob/main/java/jbang-example.java
```

## Documentation

📚 **[Full Documentation](https://github.github.io/copilot-sdk-java/)** — Complete API reference, advanced usage examples, and guides.

### Quick Links

- [Getting Started](https://github.github.io/copilot-sdk-java/latest/documentation.html)
- [Javadoc API Reference](https://github.github.io/copilot-sdk-java/latest/apidocs/)
- [MCP Servers Integration](https://github.github.io/copilot-sdk-java/latest/mcp.html)
- [Cookbook](src/site/markdown/cookbook/) — Practical recipes for common use cases

## Projects Using This SDK

| Project | Description |
|---------|-------------|
| Project | Description |
| ----------------------------------------------------------------------------- | ------------------------------------------ |
| [JMeter Copilot Plugin](https://github.com/brunoborges/jmeter-copilot-plugin) | JMeter plugin for AI-assisted load testing |

> Want to add your project? Open a PR!

## CI/CD Workflows

This project uses several GitHub Actions workflows for building, testing, releasing, and syncing with the reference implementation SDK.
This project uses several GitHub Actions workflows for building, testing, releasing, and syncing with the reference implementation SDK.

See [WORKFLOWS.md](docs/WORKFLOWS.md) for a full overview and details on each workflow.

Expand All @@ -169,21 +153,28 @@ This SDK tracks the official [Copilot SDK](https://github.com/github/copilot-sdk
**Automated sync** — A [scheduled GitHub Actions workflow](.github/workflows/reference-impl-sync.yml) runs on the schedule specified in that file. It checks for new reference implementation commits since the last merge (tracked in [`.lastmerge`](.lastmerge)), and if changes are found, creates an issue labeled `reference-impl-sync` and assigns it to the GitHub Copilot coding agent. Any previously open `reference-impl-sync` issues are automatically closed. The sync also updates the `@github/copilot` version in both `pom.xml` and `scripts/codegen/package.json` to keep schemas and test CLI in lockstep.

**Reusable prompt** — The merge workflow is defined in [`agentic-merge-reference-impl.prompt.md`](.github/prompts/agentic-merge-reference-impl.prompt.md). It can be triggered manually from:

- **VS Code Copilot Chat** — type `/agentic-merge-reference-impl`
- **GitHub Copilot CLI** — use `copilot` CLI with the same skill reference

### Development Setup

Requires JDK 25 or later for development.

```bash
# Clone the repository
git clone https://github.com/github/copilot-sdk-java.git
cd copilot-sdk-java
git clone https://github.com/github/copilot-sdk.git
cd copilot-sdk/java

# Enable git hooks for code formatting
git config core.hooksPath .githooks

# Build and test
# Build and test with JDK 25
mvn clean verify

# Set your paths for JDK 17
# Run the JDK 25 built jar with JDK 17 JVM for tests. Do not re-compile the jar.
mvn jacoco:prepare-agent@wire-up-coverage-instrumentation antrun:run@print-test-jdk-banner surefire:test failsafe:integration-test failsafe:verify jacoco:report@build-coverage-report-from-tests -Denforcer.skip=true
```

The tests require the official [copilot-sdk](https://github.com/github/copilot-sdk) test harness, which is automatically cloned during build.
Expand All @@ -204,12 +195,3 @@ See [SECURITY.md](SECURITY.md) for reporting security vulnerabilities.

MIT — see [LICENSE](LICENSE) for details.

## Acknowledgement

- Initially developed with Copilot and [Bruno Borges](https://www.linkedin.com/in/brunocborges/).

## Star History

[![Star History Chart](https://api.star-history.com/svg?repos=github/copilot-sdk-java&type=Date)](https://www.star-history.com/#github/copilot-sdk-java&Date)

⭐ Drop a star if you find this useful!
2 changes: 1 addition & 1 deletion jbang-example.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS com.github:copilot-sdk-java:1.0.0-beta-8-java.0
//DEPS com.github:copilot-sdk-java:1.0.0-beta-java.4
import com.github.copilot.CopilotClient;
import com.github.copilot.generated.AssistantMessageEvent;
import com.github.copilot.generated.SessionUsageInfoEvent;
Expand Down
Loading
Loading