Skip to content

Commit 58455ec

Browse files
patnikoCopilot
andauthored
Add workflow to update @github/copilot dependency (#604)
* Add workflow to update @github/copilot dependency Adds a workflow_dispatch workflow that: - Accepts a target version of @github/copilot - Updates the dependency in nodejs/ and test/harness/ - Re-runs all code generators - Formats generated output - Pushes a branch and opens a PR for review Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Also refresh nodejs/samples lockfile during dependency update The samples package-lock.json picks up @github/copilot transitively through the file:.. link to the nodejs SDK and needs refreshing too. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address PR review feedback - Add version input validation (semver regex) to prevent injection - Pass version via env var instead of direct interpolation in shell - Add actions/setup-dotnet for dotnet format step - Restrict formatting to generated files only (src/generated/**) - Handle idempotent re-runs: reuse existing branch, skip empty commits, detect existing PRs - Use --force-with-lease for safe branch updates Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 117eaf8 commit 58455ec

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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. 0.0.420)'
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. 0.0.420)."
26+
exit 1
27+
fi
28+
29+
- uses: actions/checkout@v4
30+
31+
- uses: actions/setup-node@v4
32+
with:
33+
node-version: 22
34+
35+
- uses: actions/setup-go@v5
36+
with:
37+
go-version: '1.22'
38+
39+
- uses: actions/setup-dotnet@v5
40+
with:
41+
dotnet-version: "8.0.x"
42+
43+
- name: Update @github/copilot in nodejs
44+
env:
45+
VERSION: ${{ inputs.version }}
46+
working-directory: ./nodejs
47+
run: npm install "@github/copilot@$VERSION"
48+
49+
- name: Update @github/copilot in test harness
50+
env:
51+
VERSION: ${{ inputs.version }}
52+
working-directory: ./test/harness
53+
run: npm install "@github/copilot@$VERSION"
54+
55+
- name: Refresh nodejs/samples lockfile
56+
working-directory: ./nodejs/samples
57+
run: npm install
58+
59+
- name: Install codegen dependencies
60+
working-directory: ./scripts/codegen
61+
run: npm ci
62+
63+
- name: Run codegen
64+
working-directory: ./scripts/codegen
65+
run: npm run generate
66+
67+
- name: Format generated code
68+
run: |
69+
cd nodejs && npx prettier --write "src/generated/**/*.ts"
70+
cd ../dotnet && dotnet format src/GitHub.Copilot.SDK.csproj
71+
72+
- name: Create pull request
73+
env:
74+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
VERSION: ${{ inputs.version }}
76+
run: |
77+
BRANCH="update-copilot-$VERSION"
78+
git config user.name "github-actions[bot]"
79+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
80+
81+
if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then
82+
git checkout "$BRANCH"
83+
git reset --hard HEAD
84+
else
85+
git checkout -b "$BRANCH"
86+
fi
87+
88+
git add -A
89+
90+
if git diff --cached --quiet; then
91+
echo "No changes detected; skipping commit and PR creation."
92+
exit 0
93+
fi
94+
95+
git commit -m "Update @github/copilot to $VERSION
96+
97+
- Updated nodejs and test harness dependencies
98+
- Re-ran code generators
99+
- Formatted generated code"
100+
git push origin "$BRANCH" --force-with-lease
101+
102+
if gh pr view "$BRANCH" >/dev/null 2>&1; then
103+
echo "Pull request for branch '$BRANCH' already exists; updated branch only."
104+
else
105+
gh pr create \
106+
--title "Update @github/copilot to $VERSION" \
107+
--body "Automated update of \`@github/copilot\` to version \`$VERSION\`.
108+
109+
### Changes
110+
- Updated \`@github/copilot\` in \`nodejs/package.json\` and \`test/harness/package.json\`
111+
- Re-ran all code generators (\`scripts/codegen\`)
112+
- Formatted generated output
113+
114+
> Created by the **Update @github/copilot Dependency** workflow." \
115+
--base main \
116+
--head "$BRANCH"
117+
fi

0 commit comments

Comments
 (0)