Skip to content

Commit b2aba94

Browse files
committed
Add GitHub Actions workflows for SDK testing and setup
- Introduced action.yml for setting up Copilot CLI. - Created sdk-build.yml for end-to-end testing of the Java SDK. - Updated README with build and test instructions. - Enhanced pom.xml to clone the copilot-sdk repository for test resources. - Modified CapiProxy and E2ETestContext to support custom SDK directory.
1 parent 0b56ebf commit b2aba94

6 files changed

Lines changed: 168 additions & 3 deletions

File tree

.github/setup-copilot/action.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "Setup Copilot"
2+
description: "Setup Copilot CLI for testing the Java SDK."
3+
runs:
4+
using: "composite"
5+
steps:
6+
- uses: actions/setup-node@v6
7+
with:
8+
node-version: 22
9+
- name: Install Copilot CLI
10+
run: npm install -g @github/copilot
11+
shell: bash
12+
- name: Set CLI path
13+
id: cli-path
14+
run: echo "path=$(which copilot)" >> $GITHUB_OUTPUT
15+
shell: bash
16+
- name: Verify CLI works
17+
run: copilot --version
18+
shell: bash

.github/workflows/sdk-build.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: "SDK E2E Tests"
2+
3+
env:
4+
HUSKY: 0
5+
PYTHONUTF8: 1
6+
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
7+
8+
on:
9+
push:
10+
branches: [main]
11+
pull_request:
12+
workflow_dispatch:
13+
merge_group:
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
20+
java-sdk:
21+
name: "Java SDK Tests"
22+
23+
runs-on: ubuntu-latest
24+
defaults:
25+
run:
26+
shell: bash
27+
steps:
28+
- uses: actions/checkout@v6
29+
- uses: ./.github/actions/setup-copilot
30+
- uses: actions/setup-java@v5
31+
with:
32+
java-version: "17"
33+
distribution: "temurin"
34+
35+
- name: Run spotless check
36+
run: |
37+
mvn spotless:check
38+
if [ $? -ne 0 ]; then
39+
echo "❌ spotless:check failed. Please run 'mvn spotless:apply' in java"
40+
exit 1
41+
fi
42+
echo "✅ spotless:check passed"
43+
44+
- name: Build SDK
45+
run: mvn compile
46+
47+
- name: Run Java SDK tests
48+
env:
49+
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }}
50+
COPILOT_CLI_PATH: ${{ steps.cli-path.outputs.path }}
51+
run: mvn verify

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Java SDK for programmatic control of GitHub Copilot CLI.
88

99
- Java 17 or later
1010
- GitHub Copilot CLI installed and in PATH (or provide custom `cliPath`)
11+
- Node.js and npm (required for running tests - the test harness is implemented in Node.js)
1112

1213
## Installation
1314

@@ -433,6 +434,30 @@ try {
433434
}
434435
```
435436

437+
## Building and Testing
438+
439+
### Building the Project
440+
441+
```bash
442+
mvn clean compile
443+
```
444+
445+
### Running Tests
446+
447+
The tests require test resources (snapshots, harness) from the official [copilot-sdk](https://github.com/github/copilot-sdk) repository. The build automatically clones this repository during the `generate-test-resources` phase:
448+
449+
```bash
450+
mvn clean test
451+
```
452+
453+
The official SDK repository is cloned to `target/copilot-sdk/` and the `copilot.tests.dir` property is set to point to its `test/` folder.
454+
455+
If you want to use a different location for the SDK repository (e.g., you already have it cloned locally), you can override the properties:
456+
457+
```bash
458+
mvn test -Dcopilot.sdk.clone.dir=/path/to/copilot-sdk -Dcopilot.tests.dir=/path/to/copilot-sdk/test
459+
```
460+
436461
## License
437462

438463
MIT

pom.xml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
<properties>
4141
<maven.compiler.release>17</maven.compiler.release>
4242
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
43+
<!-- Directory where the copilot-sdk repo will be cloned for tests -->
44+
<copilot.sdk.clone.dir>${project.build.directory}/copilot-sdk</copilot.sdk.clone.dir>
45+
<copilot.tests.dir>${copilot.sdk.clone.dir}/test</copilot.tests.dir>
4346
</properties>
4447

4548
<dependencies>
@@ -76,10 +79,59 @@
7679
<artifactId>maven-compiler-plugin</artifactId>
7780
<version>3.14.1</version>
7881
</plugin>
82+
<!-- Clone the official copilot-sdk repository for test resources -->
83+
<plugin>
84+
<groupId>org.codehaus.mojo</groupId>
85+
<artifactId>exec-maven-plugin</artifactId>
86+
<version>3.6.2</version>
87+
<executions>
88+
<execution>
89+
<id>clone-copilot-sdk</id>
90+
<phase>generate-test-resources</phase>
91+
<goals>
92+
<goal>exec</goal>
93+
</goals>
94+
<configuration>
95+
<executable>git</executable>
96+
<arguments>
97+
<argument>clone</argument>
98+
<argument>--depth</argument>
99+
<argument>1</argument>
100+
<argument>https://github.com/github/copilot-sdk.git</argument>
101+
<argument>${copilot.sdk.clone.dir}</argument>
102+
</arguments>
103+
<successCodes>
104+
<successCode>0</successCode>
105+
<successCode>128</successCode> <!-- Already exists -->
106+
</successCodes>
107+
</configuration>
108+
</execution>
109+
<execution>
110+
<id>install-harness-dependencies</id>
111+
<phase>generate-test-resources</phase>
112+
<goals>
113+
<goal>exec</goal>
114+
</goals>
115+
<configuration>
116+
<executable>npm</executable>
117+
<workingDirectory>${copilot.sdk.clone.dir}/test/harness</workingDirectory>
118+
<arguments>
119+
<argument>install</argument>
120+
</arguments>
121+
</configuration>
122+
</execution>
123+
</executions>
124+
</plugin>
79125
<plugin>
80126
<groupId>org.apache.maven.plugins</groupId>
81127
<artifactId>maven-surefire-plugin</artifactId>
82128
<version>3.5.4</version>
129+
<configuration>
130+
<systemPropertyVariables>
131+
<copilot.tests.dir>${copilot.tests.dir}</copilot.tests.dir>
132+
<copilot.sdk.dir>${copilot.sdk.clone.dir}</copilot.sdk.dir>
133+
</systemPropertyVariables>
134+
</configuration>
83135
</plugin>
84136
<plugin>
85137
<groupId>com.diffplug.spotless</groupId>

src/test/java/com/github/copilot/sdk/CapiProxy.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,17 @@ public void close() throws Exception {
297297
* Finds the test/harness directory by walking up from the current directory.
298298
*/
299299
private Path findHarnessDirectory() {
300-
Path current = Paths.get(System.getProperty("user.dir"));
300+
// First, check for copilot.sdk.dir system property (set by Maven during tests)
301+
String sdkDir = System.getProperty("copilot.sdk.dir");
302+
if (sdkDir != null && !sdkDir.isEmpty()) {
303+
Path harnessDir = Paths.get(sdkDir).resolve("test").resolve("harness");
304+
if (harnessDir.toFile().exists() && harnessDir.resolve("server.ts").toFile().exists()) {
305+
return harnessDir;
306+
}
307+
}
301308

302-
// Walk up the directory tree looking for test/harness
309+
// Fallback: walk up the directory tree looking for test/harness
310+
Path current = Paths.get(System.getProperty("user.dir"));
303311
while (current != null) {
304312
Path harnessDir = current.resolve("test").resolve("harness");
305313
if (harnessDir.toFile().exists() && harnessDir.resolve("server.ts").toFile().exists()) {

src/test/java/com/github/copilot/sdk/E2ETestContext.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,25 @@ public void close() throws Exception {
187187
}
188188

189189
private static Path findRepoRoot() throws IOException {
190+
// First, check for copilot.sdk.dir system property (set by Maven during tests)
191+
String sdkDir = System.getProperty("copilot.sdk.dir");
192+
if (sdkDir != null && !sdkDir.isEmpty()) {
193+
Path sdkPath = Paths.get(sdkDir);
194+
if (Files.exists(sdkPath)) {
195+
return sdkPath;
196+
}
197+
}
198+
199+
// Fallback: search up from current directory
190200
Path dir = Paths.get(System.getProperty("user.dir"));
191201
while (dir != null) {
192202
if (Files.exists(dir.resolve("nodejs")) && Files.exists(dir.resolve("test").resolve("harness"))) {
193203
return dir;
194204
}
195205
dir = dir.getParent();
196206
}
197-
throw new IOException("Could not find repository root");
207+
throw new IOException("Could not find repository root. Either set copilot.sdk.dir system property "
208+
+ "or run from within the copilot-sdk repository.");
198209
}
199210

200211
private static String getCliPath(Path repoRoot) throws IOException {

0 commit comments

Comments
 (0)