Skip to content
Open
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
13 changes: 10 additions & 3 deletions .github/actions/setup-copilot/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ outputs:
cli-path:
description: "Path to the Copilot CLI"
value: ${{ steps.cli-path.outputs.path }}
javascript-cli-path:
description: "Path to the JavaScript Copilot CLI entrypoint"
value: ${{ steps.cli-path.outputs.javascript-path }}
runs:
using: "composite"
steps:
Expand All @@ -28,10 +31,14 @@ runs:
echo "Could not prepare the Copilot CLI runtime" >&2
exit 1
fi
javascript_cli_path=$(npm --prefix "$(pwd)/nodejs" run --silent prepare:runtime -- --print-legacy-path)
if [ -z "$javascript_cli_path" ]; then
echo "Could not prepare the Copilot CLI JavaScript entrypoint" >&2
exit 1
fi
echo "path=$cli_path" >> $GITHUB_OUTPUT
echo "javascript-path=$javascript_cli_path" >> $GITHUB_OUTPUT
shell: bash
- name: Verify CLI works
run: |
legacy_cli=$(npm --prefix "$(pwd)/nodejs" run --silent prepare:runtime -- --print-legacy-path)
node "$legacy_cli" --version
run: node "${{ steps.cli-path.outputs.javascript-path }}" --version
shell: bash

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: |
Adapt handwritten Java SDK code to work with regenerated types after a
@github/copilot version bump. Assumes codegen succeeded and generated code
Copilot CLI release update. Assumes codegen succeeded and generated code
compiles. Fixes handwritten source and tests only.

on:
Expand Down Expand Up @@ -45,14 +45,13 @@ safe-outputs:

# Java Handwritten Code Adaptation After CLI Upgrade

You are an automation agent that fixes handwritten Java SDK source and test code after a `@github/copilot` version bump has regenerated the typed schemas.
You are an automation agent that fixes handwritten Java SDK source and test code after a Copilot CLI release update has regenerated the typed schemas.

## Assumptions

- The branch `${{ inputs.branch }}` already has:
- Updated `java/scripts/codegen/package.json` with the new version
- Updated the shared CLI release pin in `nodejs/package.json`
- Regenerated `java/sdk/src/generated/java/` code that compiles successfully
- Updated the Java POM CLI/version pin property
- Your job is ONLY to fix **handwritten** code, NOT generated code.

## Boundaries
Expand Down Expand Up @@ -147,7 +146,7 @@ If this passes, commit and push:

```bash
git add java/sdk/src/main/java java/sdk/src/test/java
git commit -m "Fix handwritten Java code for @github/copilot schema changes
git commit -m "Fix handwritten Java code for CLI schema changes

Adapt constructor calls, enum references, and test assertions to match
regenerated types after CLI version bump."
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/java-codegen-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ on:
branches:
- main
paths:
- 'nodejs/package.json'
- 'java/scripts/codegen/**'
- 'java/sdk/src/generated/**'
- '.github/workflows/java-codegen-check.yml'
pull_request:
paths:
- 'nodejs/package.json'
- 'java/scripts/codegen/**'
- 'java/sdk/src/generated/**'
- '.github/workflows/java-codegen-check.yml'
Expand Down Expand Up @@ -48,9 +50,13 @@ jobs:
working-directory: ./java/scripts/codegen
run: npm ci

- name: Test schema fetcher
working-directory: ./java/scripts/codegen
run: npm test

- name: Run codegen
working-directory: ./java/scripts/codegen
run: npx tsx java.ts
run: npm run generate

- name: Check for uncommitted changes
id: check-changes
Expand All @@ -68,7 +74,7 @@ jobs:
- name: Fail on stale generated files (push to main)
if: steps.check-changes.outputs.changed == 'true' && github.event_name != 'pull_request'
run: |
echo "::error::Generated files are out of date. Run 'cd java/scripts/codegen && npx tsx java.ts' and commit the changes."
echo "::error::Generated files are out of date. Run 'cd java/scripts/codegen && npm run generate' and commit the changes."
git diff
exit 1

Expand All @@ -93,7 +99,7 @@ jobs:
if: steps.push-regen.outcome == 'failure'
run: |
echo "::error::Could not push regenerated files to the PR branch. This is expected for Dependabot PRs (read-only token) and fork PRs."
echo "To fix: check out this PR branch locally, run 'cd java/scripts/codegen && npx tsx java.ts', commit, and push."
echo "To fix: check out this PR branch locally, run 'cd java/scripts/codegen && npm run generate', commit, and push."
exit 1

- uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/java-codegen-fix.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions .github/workflows/java-codegen-fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ You are an automation agent that fixes Java compilation and test failures caused

## Context

A Dependabot PR bumped the `@github/copilot` npm dependency in `java/scripts/codegen/package.json`. The `java-codegen-check` workflow ran the code generator (`java/scripts/codegen/java.ts`) against the new schemas and `mvn verify` subsequently failed. Your job is to fix **both** the code generator script (if needed) and the handwritten SDK/test source code so the build passes.
A Copilot CLI release pin update fetched new schemas from GitHub Releases. The `java-codegen-check` workflow ran the code generator (`java/scripts/codegen/java.ts`) against those schemas and `mvn verify` subsequently failed. Your job is to fix **both** the code generator script (if needed) and the handwritten SDK/test source code so the build passes.

**❌❌❌ YOU MUST NEVER EDIT any of the java source code in `java/sdk/src/generated/` directly.** ✅✅Rather, the way to affect changes in these files is to change the code generator script and re-generate the classes in `java/sdk/src/generated`.

Expand All @@ -66,9 +66,9 @@ ${{ inputs.error_summary }}

## Architecture overview

The code generator (`java/scripts/codegen/java.ts`) reads JSON schemas from `node_modules/@github/copilot/schemas/` and produces Java source files under `java/sdk/src/generated/java/`. These generated types are consumed by handwritten code in `java/sdk/src/main/java/` (primarily `CopilotSession.java`) and tested by handwritten tests in `java/sdk/src/test/java/`.
The code generator (`java/scripts/codegen/java.ts`) reads JSON schemas from `java/scripts/codegen/target/schemas/`. The schemas are extracted from the pinned `github-copilot-<version>-linux-x64.tgz` GitHub Release asset by `fetch-schemas.mjs`. The generator produces Java source files under `java/sdk/src/generated/java/`. These generated types are consumed by handwritten code in `java/sdk/src/main/java/` (primarily `CopilotSession.java`) and tested by handwritten tests in `java/sdk/src/test/java/`.

When `@github/copilot` is bumped, the schemas may change in ways the code generator does not yet handle. Common schema changes include:
When the Copilot CLI release pin is bumped, the schemas may change in ways the code generator does not yet handle. Common schema changes include:

- **`$ref` references**: Inline nested type definitions replaced with `$ref` pointers to `#/definitions/` entries. The code generator must resolve these references and emit standalone Java types instead of nested records.
- **Field type changes**: Numeric fields changing between `double`, `Long`, `int`, etc.
Expand Down Expand Up @@ -97,10 +97,10 @@ mvn --version
node --version
```

Install codegen dependencies:
Install codegen dependencies and fetch the pinned release schemas:

```bash
cd java/scripts/codegen && npm ci && cd ../../..
cd java/scripts/codegen && npm ci && npm run fetch:schemas && cd ../../..
```

### Step 1: Reproduce the failure
Expand Down Expand Up @@ -135,13 +135,13 @@ To diagnose, compare the current schemas with the generated output:

```bash
# List available schemas
ls java/scripts/codegen/node_modules/@github/copilot/schemas/
ls java/scripts/codegen/target/schemas/

# Check for $ref usage in schemas (indicates the codegen may need $ref resolution)
grep -r '"$ref"' java/scripts/codegen/node_modules/@github/copilot/schemas/ | head -20
grep -r '"$ref"' java/scripts/codegen/target/schemas/ | head -20

# Look at a specific schema that relates to failing types
cat java/scripts/codegen/node_modules/@github/copilot/schemas/<relevant-schema>.json | head -80
head -80 java/scripts/codegen/target/schemas/<relevant-schema>.json
```

### Step 3: Fix the code generator (if needed)
Expand All @@ -157,7 +157,7 @@ If the diagnosis shows the code generator does not handle the new schema format:

3. **Re-run code generation** to produce updated generated files:
```bash
cd java/scripts/codegen && npx tsx java.ts && cd ../../..
cd java/scripts/codegen && npm run generate && cd ../../..
```

4. **Verify the generated output** looks reasonable:
Expand Down Expand Up @@ -213,7 +213,7 @@ After `mvn verify` passes, commit all changes and use the `push-to-pull-request-

```bash
git add -A
git commit -m "Fix Java codegen and build failures after @github/copilot update
git commit -m "Fix Java codegen and build failures after CLI update

Automated fix applied by java-codegen-fix workflow."
```
Expand All @@ -236,7 +236,7 @@ Do **NOT** push broken code.

## Important constraints

- **NEVER** hand-edit files under `java/sdk/src/generated/java/` — these are auto-generated. They are updated by running `cd java/scripts/codegen && npx tsx java.ts`.
- **NEVER** hand-edit files under `java/sdk/src/generated/java/` — these are auto-generated. They are updated by running `cd java/scripts/codegen && npm run generate`.
- **NEVER** modify `java/sdk/pom.xml` — build config is not in scope
- **NEVER** modify `java/scripts/codegen/package.json` or `java/scripts/codegen/package-lock.json` — dependency versions are not in scope
- **NEVER** modify files under `.github/` — workflow files are not in scope
Expand Down
Loading
Loading