Skip to content

Commit 3ef1b22

Browse files
Copilotedburns
andauthored
Add Java code generation from JSON schemas
- Add scripts/codegen/java.ts - Java code generator from session-events and api schemas - Add scripts/codegen/package.json with @github/copilot dependency - Add scripts/codegen/package-lock.json - Generate src/generated/java/com/github/copilot/sdk/generated/ - 76 session event files - Generate src/generated/java/com/github/copilot/sdk/generated/rpc/ - 111 RPC type files - Update pom.xml: add build-helper-maven-plugin, exclude generated from Spotless - Update config/checkstyle/checkstyle.xml: exclude generated packages - Update .gitattributes: mark src/generated/java/** as generated - Add .github/workflows/codegen-check.yml - CI check workflow - Add .github/workflows/update-copilot-dependency.yml - update workflow - Update docs/WORKFLOWS.md with new workflow documentation - Update .gitignore to exclude scripts/codegen/node_modules/" Agent-Logs-Url: https://github.com/github/copilot-sdk-java/sessions/aee4deda-40d4-4ecd-a831-2af9cb9461e7 Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
1 parent 6561490 commit 3ef1b22

File tree

198 files changed

+11799
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+11799
-3
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.github/workflows/*.lock.yml linguist-generated=true merge=ours
1+
.github/workflows/*.lock.yml linguist-generated=true merge=ours
2+
src/generated/java/** eol=lf linguist-generated=true
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: "Codegen Check"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
paths:
9+
- 'scripts/codegen/**'
10+
- 'src/generated/java/**'
11+
- '.github/workflows/codegen-check.yml'
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
check:
19+
name: "Verify generated files are up-to-date"
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
23+
24+
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
25+
with:
26+
node-version: 22
27+
28+
- name: Install codegen dependencies
29+
working-directory: ./scripts/codegen
30+
run: npm ci
31+
32+
- name: Run codegen
33+
working-directory: ./scripts/codegen
34+
run: npm run generate
35+
36+
- name: Check for uncommitted changes
37+
run: |
38+
if [ -n "$(git status --porcelain)" ]; then
39+
echo "::error::Generated files are out of date. Run 'cd scripts/codegen && npm run generate' and commit the changes."
40+
git diff --stat
41+
git diff
42+
exit 1
43+
fi
44+
echo "✅ Generated files are up-to-date"
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: "Update @github/copilot Dependency"
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Target version of @github/copilot (e.g. 1.0.24)'
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
update:
17+
name: "Update @github/copilot to ${{ inputs.version }}"
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Validate version input
21+
env:
22+
VERSION: ${{ inputs.version }}
23+
run: |
24+
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9._-]+)?$ ]]; then
25+
echo "::error::Invalid version format '$VERSION'. Expected semver (e.g. 1.0.24)."
26+
exit 1
27+
fi
28+
29+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
30+
31+
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
32+
with:
33+
node-version: 22
34+
35+
- name: Update @github/copilot in scripts/codegen
36+
env:
37+
VERSION: ${{ inputs.version }}
38+
working-directory: ./scripts/codegen
39+
run: npm install "@github/copilot@$VERSION"
40+
41+
- name: Install codegen dependencies
42+
working-directory: ./scripts/codegen
43+
run: npm ci
44+
45+
- name: Run codegen
46+
working-directory: ./scripts/codegen
47+
run: npm run generate
48+
49+
- name: Create pull request
50+
env:
51+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
VERSION: ${{ inputs.version }}
53+
run: |
54+
BRANCH="update-copilot-$VERSION"
55+
git config user.name "github-actions[bot]"
56+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
57+
58+
if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then
59+
git checkout "$BRANCH"
60+
git reset --hard HEAD
61+
else
62+
git checkout -b "$BRANCH"
63+
fi
64+
65+
git add -A
66+
67+
if git diff --cached --quiet; then
68+
echo "No changes detected; skipping commit and PR creation."
69+
exit 0
70+
fi
71+
72+
git commit -m "Update @github/copilot to $VERSION
73+
74+
- Updated @github/copilot in scripts/codegen
75+
- Re-ran Java code generator"
76+
git push origin "$BRANCH" --force-with-lease
77+
78+
if gh pr view "$BRANCH" >/dev/null 2>&1; then
79+
echo "Pull request for branch '$BRANCH' already exists; updated branch only."
80+
else
81+
gh pr create \
82+
--title "Update @github/copilot to $VERSION" \
83+
--body "Automated update of \`@github/copilot\` to version \`$VERSION\`.
84+
85+
### Changes
86+
- Updated \`@github/copilot\` in \`scripts/codegen/package.json\`
87+
- Re-ran Java code generator (\`scripts/codegen\`)
88+
89+
> Created by the **Update @github/copilot Dependency** workflow." \
90+
--base main \
91+
--head "$BRANCH"
92+
fi

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ changebundle.txt*
1111
.classpath
1212
.project
1313
.settings
14+
scripts/codegen/node_modules/

config/checkstyle/checkstyle.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<property name="charset" value="UTF-8"/>
1212
<property name="severity" value="error"/>
1313

14-
<!-- Exclude json package and events package (self-documenting DTOs) -->
14+
<!-- Exclude json package, events package, and generated package (self-documenting DTOs) -->
1515
<module name="BeforeExecutionExclusionFileFilter">
16-
<property name="fileNamePattern" value=".*[\\/](json|events)[\\/].*\.java$"/>
16+
<property name="fileNamePattern" value=".*[\\/](json|events|generated|rpc)[\\/].*\.java$"/>
1717
</module>
1818

1919
<module name="TreeWalker">

docs/WORKFLOWS.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
| Workflow | Description | Triggers | Schedule |
66
|----------|-------------|----------|----------|
77
| [Build & Test](workflows/build-test.yml) | Builds, lints, and tests the Java SDK | `push` (main), `pull_request`, `merge_group`, `workflow_dispatch` | Sundays at 00:00 UTC |
8+
| [Codegen Check](workflows/codegen-check.yml) | Verifies that generated Java files are up-to-date with the JSON schemas | `push` (main), `pull_request`, `workflow_dispatch` ||
9+
| [Update @github/copilot Dependency](workflows/update-copilot-dependency.yml) | Updates the `@github/copilot` npm package, re-runs code generation, and opens a PR | `workflow_dispatch` ||
810
| [Deploy Documentation](workflows/deploy-site.yml) | Generates and deploys versioned docs to GitHub Pages | `workflow_run` (after Build & Test), `release`, `workflow_dispatch` ||
911
| [Publish to Maven Central](workflows/publish-maven.yml) | Releases the SDK to Maven Central and creates a GitHub Release | `workflow_dispatch` ||
1012
| [Weekly Upstream Sync](workflows/weekly-upstream-sync.yml) | Checks for new upstream commits and creates an issue for Copilot to merge | `workflow_dispatch` | Mondays at 10:00 UTC |
@@ -87,6 +89,42 @@ Auto-generated compiled workflow produced by `gh aw compile` from the correspond
8789
8890
---
8991

92+
## Codegen Check
93+
94+
**File:** [`codegen-check.yml`](workflows/codegen-check.yml)
95+
96+
Verifies that the generated Java source files in `src/generated/java/` are up-to-date with the JSON schemas distributed in the `@github/copilot` npm package.
97+
98+
Steps:
99+
1. Installs the codegen dependencies from `scripts/codegen/`
100+
2. Runs the Java code generator (`npm run generate`)
101+
3. Fails with a diff if any generated file differs from what is committed
102+
103+
Run this locally with:
104+
```bash
105+
cd scripts/codegen && npm ci && npm run generate
106+
```
107+
108+
If changes appear, commit the updated generated files.
109+
110+
---
111+
112+
## Update @github/copilot Dependency
113+
114+
**File:** [`update-copilot-dependency.yml`](workflows/update-copilot-dependency.yml)
115+
116+
Manual workflow triggered when a new version of the `@github/copilot` npm package is published. Accepts a `version` input (e.g. `1.0.25`).
117+
118+
Steps:
119+
1. Updates `@github/copilot` in `scripts/codegen/package.json`
120+
2. Re-runs the Java code generator
121+
3. Commits the updated `package.json`, `package-lock.json`, and all regenerated Java files
122+
4. Opens (or updates) a pull request for review
123+
124+
The resulting PR will be automatically validated by the **Codegen Check** workflow.
125+
126+
---
127+
90128
## Copilot Setup Steps
91129

92130
**File:** [`copilot-setup-steps.yml`](workflows/copilot-setup-steps.yml)

pom.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,35 @@
255255
</systemPropertyVariables>
256256
</configuration>
257257
</plugin>
258+
<!-- Add src/generated/java as an additional source root -->
259+
<plugin>
260+
<groupId>org.codehaus.mojo</groupId>
261+
<artifactId>build-helper-maven-plugin</artifactId>
262+
<version>3.6.1</version>
263+
<executions>
264+
<execution>
265+
<id>add-generated-source</id>
266+
<phase>generate-sources</phase>
267+
<goals>
268+
<goal>add-source</goal>
269+
</goals>
270+
<configuration>
271+
<sources>
272+
<source>${project.basedir}/src/generated/java</source>
273+
</sources>
274+
</configuration>
275+
</execution>
276+
</executions>
277+
</plugin>
258278
<plugin>
259279
<groupId>com.diffplug.spotless</groupId>
260280
<artifactId>spotless-maven-plugin</artifactId>
261281
<version>2.44.5</version>
262282
<configuration>
263283
<java>
284+
<excludes>
285+
<exclude>src/generated/java/**/*.java</exclude>
286+
</excludes>
264287
<eclipse>
265288
<version>4.33</version>
266289
</eclipse>

scripts/codegen/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

0 commit comments

Comments
 (0)