Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.github/workflows/*.lock.yml linguist-generated=true merge=ours
.github/workflows/*.lock.yml linguist-generated=true merge=ours
src/generated/java/** eol=lf linguist-generated=true
44 changes: 44 additions & 0 deletions .github/workflows/codegen-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: "Codegen Check"

on:
push:
branches:
- main
pull_request:
paths:
- 'scripts/codegen/**'
- 'src/generated/java/**'
- '.github/workflows/codegen-check.yml'
workflow_dispatch:

permissions:
contents: read

jobs:
check:
name: "Verify generated files are up-to-date"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
with:
node-version: 22

- name: Install codegen dependencies
working-directory: ./scripts/codegen
run: npm ci

- name: Run codegen
working-directory: ./scripts/codegen
run: npm run generate

- name: Check for uncommitted changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "::error::Generated files are out of date. Run 'cd scripts/codegen && npm run generate' and commit the changes."
git diff --stat
git diff
exit 1
fi
echo "✅ Generated files are up-to-date"
92 changes: 92 additions & 0 deletions .github/workflows/update-copilot-dependency.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: "Update @github/copilot Dependency"

on:
workflow_dispatch:
inputs:
version:
description: 'Target version of @github/copilot (e.g. 1.0.24)'
required: true
type: string

permissions:
contents: write
pull-requests: write

jobs:
update:
name: "Update @github/copilot to ${{ inputs.version }}"
runs-on: ubuntu-latest
steps:
- name: Validate version input
env:
VERSION: ${{ inputs.version }}
run: |
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9._-]+)?$ ]]; then
echo "::error::Invalid version format '$VERSION'. Expected semver (e.g. 1.0.24)."
exit 1
fi

- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
with:
node-version: 22

- name: Update @github/copilot in scripts/codegen
env:
VERSION: ${{ inputs.version }}
working-directory: ./scripts/codegen
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot add a comment explaining the necessity of the unusual step of running npm install before npm ci

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment in 6e3c50c explaining the two-step approach: npm install updates package.json and package-lock.json to pin the new version, then npm ci does a clean reproducible install from the updated lock file. Running npm ci alone would fail because it cannot change a pinned version, and npm install alone leaves behind stale packages.

run: npm install "@github/copilot@$VERSION"

- name: Install codegen dependencies
working-directory: ./scripts/codegen
run: npm ci

- name: Run codegen
working-directory: ./scripts/codegen
run: npm run generate

- name: Create pull request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ inputs.version }}
run: |
BRANCH="update-copilot-$VERSION"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then
git checkout "$BRANCH"
git reset --hard HEAD
else
git checkout -b "$BRANCH"
fi

git add -A

if git diff --cached --quiet; then
echo "No changes detected; skipping commit and PR creation."
exit 0
fi

git commit -m "Update @github/copilot to $VERSION

- Updated @github/copilot in scripts/codegen
- Re-ran Java code generator"
git push origin "$BRANCH" --force-with-lease

if gh pr view "$BRANCH" >/dev/null 2>&1; then
echo "Pull request for branch '$BRANCH' already exists; updated branch only."
else
gh pr create \
--title "Update @github/copilot to $VERSION" \
--body "Automated update of \`@github/copilot\` to version \`$VERSION\`.

### Changes
- Updated \`@github/copilot\` in \`scripts/codegen/package.json\`
- Re-ran Java code generator (\`scripts/codegen\`)

> Created by the **Update @github/copilot Dependency** workflow." \
--base main \
--head "$BRANCH"
fi
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ changebundle.txt*
.classpath
.project
.settings
scripts/codegen/node_modules/
4 changes: 2 additions & 2 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<property name="charset" value="UTF-8"/>
<property name="severity" value="error"/>

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

<module name="TreeWalker">
Expand Down
38 changes: 38 additions & 0 deletions docs/WORKFLOWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
| Workflow | Description | Triggers | Schedule |
|----------|-------------|----------|----------|
| [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 |
| [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` | — |
| [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` | — |
| [Deploy Documentation](workflows/deploy-site.yml) | Generates and deploys versioned docs to GitHub Pages | `workflow_run` (after Build & Test), `release`, `workflow_dispatch` | — |
| [Publish to Maven Central](workflows/publish-maven.yml) | Releases the SDK to Maven Central and creates a GitHub Release | `workflow_dispatch` | — |
| [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 |
Expand Down Expand Up @@ -87,6 +89,42 @@ Auto-generated compiled workflow produced by `gh aw compile` from the correspond

---

## Codegen Check

**File:** [`codegen-check.yml`](workflows/codegen-check.yml)

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.

Steps:
1. Installs the codegen dependencies from `scripts/codegen/`
2. Runs the Java code generator (`npm run generate`)
3. Fails with a diff if any generated file differs from what is committed

Run this locally with:
```bash
cd scripts/codegen && npm ci && npm run generate
```

If changes appear, commit the updated generated files.

---

## Update @github/copilot Dependency

**File:** [`update-copilot-dependency.yml`](workflows/update-copilot-dependency.yml)

Manual workflow triggered when a new version of the `@github/copilot` npm package is published. Accepts a `version` input (e.g. `1.0.25`).

Steps:
1. Updates `@github/copilot` in `scripts/codegen/package.json`
2. Re-runs the Java code generator
3. Commits the updated `package.json`, `package-lock.json`, and all regenerated Java files
4. Opens (or updates) a pull request for review

The resulting PR will be automatically validated by the **Codegen Check** workflow.

---

## Copilot Setup Steps

**File:** [`copilot-setup-steps.yml`](workflows/copilot-setup-steps.yml)
Expand Down
23 changes: 23 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,35 @@
</systemPropertyVariables>
</configuration>
</plugin>
<!-- Add src/generated/java as an additional source root -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.6.1</version>
<executions>
<execution>
<id>add-generated-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/src/generated/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.44.5</version>
<configuration>
<java>
<excludes>
<exclude>src/generated/java/**/*.java</exclude>
</excludes>
<eclipse>
<version>4.33</version>
</eclipse>
Expand Down
1 change: 1 addition & 0 deletions scripts/codegen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
Loading
Loading