forked from 0GiS0/ADO_CodingAgent
-
Notifications
You must be signed in to change notification settings - Fork 3
410 lines (346 loc) · 15.8 KB
/
copilot-coder-master.yml
File metadata and controls
410 lines (346 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
name: 🤖 GitHub Copilot Coder (Master)
# This is a reusable workflow that can be called from other repositories.
# It contains the full implementation logic for the Copilot Coder.
#
# To use this workflow from another repository, create a caller workflow:
# jobs:
# copilot:
# uses: <org>/GHES_CodingAgent/.github/workflows/copilot-coder-master.yml@main
# secrets: inherit
on:
# Direct trigger (for this repository)
issues:
types: [labeled]
# Reusable workflow trigger (for other repositories)
workflow_call:
secrets:
GH_TOKEN:
description: 'Classic PAT with repo and workflow scopes'
required: true
COPILOT_TOKEN:
description: 'Token for GitHub Copilot API access'
required: true
CONTEXT7_API_KEY:
description: 'API key for Context7 documentation service'
required: false
jobs:
copilot-cli:
# Only run when the issue has the 'copilot' label
if: contains(github.event.issue.labels.*.name, 'copilot')
runs-on: self-hosted
permissions:
contents: write
issues: write
pull-requests: write
env:
MODEL: claude-haiku-4.5
COPILOT_VERSION: 0.0.352
# Extract hostname from server URL (removes https:// prefix)
GHES_HOSTNAME: ${{ github.server_url }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_BODY: ${{ github.event.issue.body }}
ISSUE_ASSIGNEE: ${{ github.event.issue.assignee.login }}
ISSUE_CREATOR: ${{ github.event.issue.user.login }}
REPO_NAME: ${{ github.repository }}
BRANCH_NAME: copilot/${{ github.event.issue.number }}
steps:
- name: 🚀 Start Workflow
run: |
echo "🚀 GitHub Copilot Coder workflow started!"
echo "═══════════════════════════════════════════════════════════"
echo "📋 Issue: #${ISSUE_NUMBER}"
echo "📌 Title: ${ISSUE_TITLE}"
echo "👤 Creator: ${ISSUE_CREATOR}"
echo "📦 Repository: ${REPO_NAME}"
echo "🌿 Branch: ${BRANCH_NAME}"
echo "═══════════════════════════════════════════════════════════"
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_CREATOR: ${{ github.event.issue.user.login }}
REPO_NAME: ${{ github.repository }}
BRANCH_NAME: copilot/${{ github.event.issue.number }}
- name: 🔐 Configure Git Credentials for GHES
run: |
# Extract hostname from server URL (remove https:// prefix)
GHES_HOST=$(echo "${{ github.server_url }}" | sed 's|https://||')
echo "GHES_HOST=${GHES_HOST}" >> $GITHUB_ENV
git config --global credential.helper store
echo "https://x-access-token:${{ github.token }}@${GHES_HOST}" >> ~/.git-credentials
chmod 600 ~/.git-credentials
echo "✅ Git credentials configured for GHES (${GHES_HOST})"
- name: 📥 Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ github.token }}
persist-credentials: true
- name: 🔐 Configure GitHub CLI for GHES
run: |
# Configure gh to use GHES instance (GHES_HOST set in previous step)
gh auth login --hostname "${GHES_HOST}" --with-token <<< "${{ secrets.GH_TOKEN }}"
gh auth status --hostname "${GHES_HOST}"
echo "✅ GitHub CLI configured for GHES (${GHES_HOST})"
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
- name: 🏷️ Update Issue Labels - In Progress
run: |
gh issue edit ${{ env.ISSUE_NUMBER }} \
--add-label "in-progress" \
--remove-label "copilot"
# Add comment to notify that Copilot is working on this issue
COMMENT="## 🤖 Copilot is on it!
Copilot has been assigned to work on this issue. You can view progress under [GitHub Actions](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}), and once completed a PR will be linked here."
gh issue comment "${{ env.ISSUE_NUMBER }}" --body "${COMMENT}"
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
- name: 🐍 Setup Python (Latest)
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: 📦 Install uv/uvx
run: |
echo "Installing uvx (pipx runner)..."
pip install --upgrade pip
pip install uv
echo "✅ Python and uv installed"
python --version
uv --version
- name: ⚙️ Setup Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: '22.x'
- name: 🔍 Detect NPM Global Path
id: npm-path
run: |
NPM_PREFIX=$(npm config get prefix)
echo "NPM_GLOBAL_PATH=${NPM_PREFIX}/lib/node_modules" >> $GITHUB_ENV
echo "NPM global path: ${NPM_PREFIX}/lib/node_modules"
- name: 📦 Cache Global NPM Packages
uses: actions/cache@v3
with:
key: npm-global-${{ runner.os }}-copilot-${{ env.COPILOT_VERSION }}
path: ${{ env.NPM_GLOBAL_PATH }}
restore-keys: |
npm-global-${{ runner.os }}-copilot-
- name: 📦 Install Copilot CLI
run: |
if ! command -v copilot &> /dev/null; then
echo "Installing @github/copilot@${{ env.COPILOT_VERSION }}..."
npm install -g @github/copilot@${{ env.COPILOT_VERSION }}
else
echo "✅ @github/copilot already installed (from cache)"
copilot --version
fi
- name: ⚙️ Configure MCP Servers
run: |
mkdir -p ~/.config
# Fetch mcp-config.json from the central GHES_CodingAgent repository
echo "📥 Fetching MCP configuration from GHES_CodingAgent..."
GHES_HOST=$(echo "${{ github.server_url }}" | sed 's|https://||')
OWNER="${{ github.repository_owner }}"
# Determine API base URL
if [[ "$GHES_HOST" == "github.com" ]]; then
API_BASE="https://api.github.com"
else
API_BASE="https://$GHES_HOST/api/v3"
fi
# Download mcp-config.json from GHES_CodingAgent repo
curl -s \
-H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
-H "Accept: application/vnd.github.v3.raw" \
"$API_BASE/repos/$OWNER/GHES_CodingAgent/contents/mcp-config.json" \
> ~/.config/mcp-config.json
if [ -s ~/.config/mcp-config.json ]; then
echo "✅ MCP configuration downloaded to ~/.config/mcp-config.json"
cat ~/.config/mcp-config.json
else
echo "❌ Failed to download MCP configuration"
exit 1
fi
- name: 🧰 Check MCP Access
run: |
echo "🧰 Verifying MCP server access..."
copilot -p "List tools defined in the current chat session (do not run commands, I am asking about tools defined in the LLM). Just the names in a table, nothing else." --allow-all-tools
env:
GH_TOKEN: ${{ secrets.COPILOT_TOKEN }}
CONTEXT7_API_KEY: ${{ secrets.CONTEXT7_API_KEY }}
- name: 🌿 Create Feature Branch
run: |
echo "🌿 Creating feature branch..."
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b ${{ env.BRANCH_NAME }}
echo "✅ Branch ${{ env.BRANCH_NAME }} created"
- name: 🤖 Implement Changes with Copilot
timeout-minutes: 30
working-directory: ${{ github.workspace }}
run: |
echo "🤖 Running GitHub Copilot CLI..."
echo "═══════════════════════════════════════════════════════════"
echo "📋 Issue: #${ISSUE_NUMBER}"
echo "📌 Title: ${ISSUE_TITLE}"
echo "🗂️ Working Directory: $(pwd)"
echo "═══════════════════════════════════════════════════════════"
echo "This is the description that Copilot CLI is going to use to implement the task:"
echo "${ISSUE_BODY}"
mkdir -p logs
# Save issue body to file to avoid injection
printf '%s' "${ISSUE_BODY}" > /tmp/issue_description.txt
# Run Copilot with file input
# Note: -p flag runs in non-interactive mode
# --add-dir allows Copilot to access files in the workspace directory
copilot -p "Implement the GitHub issue following the description details: $(cat /tmp/issue_description.txt)" \
--add-dir "$(pwd)" \
--allow-all-tools \
--log-level all \
--log-dir logs \
--model "${MODEL}"
# Clean up
rm -f /tmp/issue_description.txt
echo "✅ Implementation completed"
env:
GH_TOKEN: ${{ secrets.COPILOT_TOKEN }}
CONTEXT7_API_KEY: ${{ secrets.CONTEXT7_API_KEY }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_BODY: ${{ github.event.issue.body }}
MODEL: ${{ env.MODEL }}
- name: 💾 Commit Changes
run: |
echo "📝 Preparing commit..."
# Co-author info from issue creator
CREATOR_NAME="${ISSUE_CREATOR}"
CREATOR_EMAIL="${ISSUE_CREATOR}@users.noreply.github.com"
echo "👤 Co-author: ${CREATOR_NAME} <${CREATOR_EMAIL}>"
# Add all files except metadata files
git add .
# Exclude metadata files from commit
for file in copilot-summary.md commit-message.md .final-commit-msg.txt .github/copilot-instructions.md; do
if git ls-files --cached "$file" > /dev/null 2>&1; then
git reset HEAD "$file" 2>/dev/null || true
fi
done
# Check if there are any staged changes
if ! git diff --cached --quiet; then
echo "✅ Changes staged for commit"
else
echo "⚠️ No changes staged for commit"
fi
# Prepare final commit message with co-author
if [ -f "commit-message.md" ]; then
echo "✅ Using Copilot-generated commit message"
{
cat commit-message.md
echo ""
echo ""
echo "Co-authored-by: ${CREATOR_NAME} <${CREATOR_EMAIL}>"
} > .final-commit-msg.txt
else
echo "⚠️ commit-message.md not found, using default message"
{
echo "feat: Implement issue ${ISSUE_NUMBER}"
echo ""
echo "${ISSUE_TITLE}"
echo ""
echo "Changes implemented by GitHub Copilot CLI"
echo ""
echo "Co-authored-by: ${CREATOR_NAME} <${CREATOR_EMAIL}>"
} > .final-commit-msg.txt
fi
# Create commit if there are staged changes
if git diff --cached --quiet; then
echo "⚠️ No staged changes to commit, skipping git commit"
else
git commit -F .final-commit-msg.txt
echo "✅ Changes committed successfully"
fi
# Clean up
rm -f .final-commit-msg.txt
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_CREATOR: ${{ github.event.issue.user.login }}
- name: 🚀 Push Branch
run: |
echo "🚀 Pushing branch to remote..."
# Configure git remote with GH_TOKEN for authentication
REMOTE_URL=$(git remote get-url origin)
if [[ "$REMOTE_URL" == https://* ]]; then
REPO_PATH=$(echo "$REMOTE_URL" | sed 's|https://[^/]*/||')
GITHUB_HOST=$(echo "$REMOTE_URL" | sed 's|https://||' | sed 's|/.*||')
git remote set-url origin "https://x-access-token:${GH_TOKEN}@${GITHUB_HOST}/${REPO_PATH}"
fi
git push -u origin "${{ env.BRANCH_NAME }}"
echo "✅ Branch pushed successfully"
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
- name: 📬 Create Pull Request
id: create-pr
run: |
# Check if copilot-summary.md exists
if [ -f "copilot-summary.md" ]; then
PR_BODY=$(cat copilot-summary.md)
else
PR_BODY="## 🤖 Automated Implementation
This PR was automatically generated by GitHub Copilot CLI.
### 📋 Related Issue
Closes #${ISSUE_NUMBER}
### 📝 Changes
Please review the changes made by Copilot CLI."
fi
# Save PR body to file to avoid injection
printf '%s' "${PR_BODY}" > /tmp/pr_body.txt
# Create PR and capture URL - use file for body
PR_URL=$(gh pr create \
--title "${ISSUE_TITLE}" \
--body-file /tmp/pr_body.txt \
--base main \
--head "${BRANCH_NAME}" \
--assignee "${ISSUE_CREATOR}")
# Clean up
rm -f /tmp/pr_body.txt
echo "PR_URL=${PR_URL}" >> $GITHUB_ENV
echo "✅ Pull Request created: ${PR_URL}"
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_CREATOR: ${{ github.event.issue.user.login }}
BRANCH_NAME: ${{ env.BRANCH_NAME }}
- name: 💬 Add Completion Comment to Issue
run: |
echo "💬 Adding completion comment to issue #${ISSUE_NUMBER}..."
COMMENT="## 🎉 Implementation Complete!
The GitHub Copilot CLI has successfully implemented the changes for this issue.
### 📬 Pull Request
A Pull Request has been created with the implementation:
${PR_URL}
### 👀 Next Steps
1. Review the Pull Request
2. Test the implementation
3. Approve and merge if everything looks good
### 📦 Logs
Workflow logs and Copilot execution logs are available in the workflow run artifacts.
---
*This comment was automatically generated by the GitHub Copilot Coder workflow.*"
gh issue comment "${ISSUE_NUMBER}" --body "${COMMENT}"
echo "✅ Comment added successfully"
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
PR_URL: ${{ env.PR_URL }}
- name: 🏷️ Update Issue Labels - Completed
run: |
gh issue edit ${{ env.ISSUE_NUMBER }} \
--add-label "ready-for-review" \
--remove-label "in-progress"
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
- name: 📦 Publish Logs
uses: actions/upload-artifact@v3
if: always()
with:
name: copilot-logs
path: logs/
retention-days: 30