|
| 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 | + # npm install updates package.json and package-lock.json to the new |
| 40 | + # version; npm ci (below) then does a clean, reproducible install from |
| 41 | + # the updated lock file. Both steps are required: npm install alone |
| 42 | + # leaves leftover packages, while npm ci alone cannot change the pinned |
| 43 | + # version in the lock file. |
| 44 | + run: npm install "@github/copilot@$VERSION" |
| 45 | + |
| 46 | + - name: Install codegen dependencies |
| 47 | + working-directory: ./scripts/codegen |
| 48 | + run: npm ci |
| 49 | + |
| 50 | + - name: Run codegen |
| 51 | + working-directory: ./scripts/codegen |
| 52 | + run: npm run generate |
| 53 | + |
| 54 | + - uses: ./.github/actions/setup-copilot |
| 55 | + |
| 56 | + - name: Verify generated code against schema |
| 57 | + env: |
| 58 | + COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }} |
| 59 | + run: | |
| 60 | + cat > /tmp/verify-codegen-prompt.txt << 'PROMPT_EOF' |
| 61 | + You are running inside the copilot-sdk-java repository. |
| 62 | + The code generator has just run and produced Java source files under |
| 63 | + src/generated/java/com/github/copilot/sdk/generated/rpc/. |
| 64 | +
|
| 65 | + Your task is to spot-check the generated API classes against the source |
| 66 | + JSON schema to verify the generator produced correct output. |
| 67 | +
|
| 68 | + **Critical constraint: Do NOT modify any files. This is a read-only |
| 69 | + verification. Use only read/inspect operations.** |
| 70 | +
|
| 71 | + **Steps:** |
| 72 | + 1. Read the API schema at: |
| 73 | + scripts/codegen/node_modules/@github/copilot/schemas/api.schema.json |
| 74 | +
|
| 75 | + 2. Pick these 3 generated API classes to verify: |
| 76 | + - src/generated/java/com/github/copilot/sdk/generated/rpc/SessionToolsApi.java |
| 77 | + - src/generated/java/com/github/copilot/sdk/generated/rpc/SessionUiApi.java |
| 78 | + - src/generated/java/com/github/copilot/sdk/generated/rpc/SessionPermissionsApi.java |
| 79 | +
|
| 80 | + 3. For each class, verify: |
| 81 | + - Every RPC method in the schema's corresponding namespace has a |
| 82 | + matching Java method in the generated class |
| 83 | + - Parameter record fields match the JSON schema property names |
| 84 | + - Java types are consistent with JSON schema types (String for |
| 85 | + "string", Integer/int for "integer", Boolean/boolean for |
| 86 | + "boolean", List for "array", Map or a generated class for |
| 87 | + "object", etc.) |
| 88 | + - No extra methods exist in the Java class that are not in the |
| 89 | + schema |
| 90 | +
|
| 91 | + 4. Print a summary table of what was checked and the result for each |
| 92 | + method. |
| 93 | +
|
| 94 | + 5. If ANY mismatch is found, print the details and exit with a |
| 95 | + non-zero code. |
| 96 | + If all checks pass, print "Schema verification passed" and exit 0. |
| 97 | + PROMPT_EOF |
| 98 | +
|
| 99 | + copilot --yolo --prompt "$(cat /tmp/verify-codegen-prompt.txt)" |
| 100 | +
|
| 101 | + - name: Create pull request |
| 102 | + env: |
| 103 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + VERSION: ${{ inputs.version }} |
| 105 | + run: | |
| 106 | + BRANCH="update-copilot-$VERSION" |
| 107 | + git config user.name "github-actions[bot]" |
| 108 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 109 | +
|
| 110 | + if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then |
| 111 | + git checkout "$BRANCH" |
| 112 | + git reset --hard HEAD |
| 113 | + else |
| 114 | + git checkout -b "$BRANCH" |
| 115 | + fi |
| 116 | +
|
| 117 | + git add -A |
| 118 | +
|
| 119 | + if git diff --cached --quiet; then |
| 120 | + echo "No changes detected; skipping commit and PR creation." |
| 121 | + exit 0 |
| 122 | + fi |
| 123 | +
|
| 124 | + git commit -m "Update @github/copilot to $VERSION |
| 125 | +
|
| 126 | + - Updated @github/copilot in scripts/codegen |
| 127 | + - Re-ran Java code generator" |
| 128 | + git push origin "$BRANCH" --force-with-lease |
| 129 | +
|
| 130 | + if gh pr view "$BRANCH" >/dev/null 2>&1; then |
| 131 | + echo "Pull request for branch '$BRANCH' already exists; updated branch only." |
| 132 | + else |
| 133 | + gh pr create \ |
| 134 | + --title "Update @github/copilot to $VERSION" \ |
| 135 | + --body "Automated update of \`@github/copilot\` to version \`$VERSION\`. |
| 136 | +
|
| 137 | + ### Changes |
| 138 | + - Updated \`@github/copilot\` in \`scripts/codegen/package.json\` |
| 139 | + - Re-ran Java code generator (\`scripts/codegen\`) |
| 140 | +
|
| 141 | + > Created by the **Update @github/copilot Dependency** workflow." \ |
| 142 | + --base main \ |
| 143 | + --head "$BRANCH" |
| 144 | + fi |
0 commit comments