Skip to content

Commit 72bda1d

Browse files
authored
GitHub Cloud Copilot Doc Page (#727)
## 📝 Description Create a page explaining how to set up GitHub Copilot to auto create PRs on CI build failures Addresses: #725 cc @DamjanBecirovic ## ✅ Checklist - [X] I have tested this change - [ ] This change requires documentation update
1 parent 3d4fa49 commit 72bda1d

File tree

7 files changed

+140
-8
lines changed

7 files changed

+140
-8
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
description: Automatically assign issues to GitHub Copilot to fix failed builds
3+
sidebar_position: 4
4+
---
5+
# Copilot Cloud Integration
6+
7+
This page explains how to integrate Semaphore CI pipelines with GitHub's Copilot Agent to automatically fix build errors.
8+
9+
:::note
10+
11+
In this scenario, we use GitHub's Cloud version of Copilot. The Copilot AI Agent runs inside GitHub and creates a draft Pull Request with fixes. If you prefer to run a different AI agent or run the agent inside the CI itself, see [Self-Healing CI](./self-healing-ci).
12+
13+
:::
14+
15+
## Overview
16+
17+
GitHub Copilot can run an AI Agent inside their infrastructure to take actions on the repository. On this page, we describe an integration method that automatically fixes build errors in the CI using Copilot Agents.
18+
19+
The process is as follows:
20+
21+
1. One or more of the jobs in your pipeline fails
22+
2. For each failed job, we create an issue on the repository and assign Copilot
23+
3. GitHub spins up an AI agent and creates a draft Pull Request with a fix
24+
4. You review the Pull Request and mark it as ready if it seems valid
25+
5. Marking the Pull Request valid for review starts a new CI workflow
26+
6. If the build is fixed, you can merge the Pull Request
27+
28+
This process is repeated for every issue opened and assigned to Copilot.
29+
30+
![Copilot Cloud Process Integration](./img/copilot-process.jpg)
31+
32+
## Prerequisites
33+
34+
- A [GitHub Personal Access Token](https://github.com/settings/tokens) with write permissions on the repository and read permissions in the GitHub organization
35+
- Copilot Agents enabled in your GitHub organization (available in GitHub Copilot Pro, GitHub Copilot Pro+, GitHub Copilot Business, and GitHub Copilot Enterprise plans)
36+
37+
## Preventing build loops
38+
39+
To prevent WIP branches created by Copilot from creating a CI loop:
40+
- We only create issues on branches that do not start with `copilot/`
41+
- We do not run workflows on draft Pull Requests
42+
43+
## Preparation
44+
45+
Before you can set up the integration, we must set up a few things.
46+
47+
### Obtain a GitHub Access Token
48+
49+
1. Create a [Personal Access Token](https://github.com/settings/tokens) (classic) in GitHub with:
50+
51+
- write permissions to the repository
52+
- permissions to create pull requests in the repository
53+
- read permissions in the organization
54+
55+
![Creating a GitHub Classic Token](./img/github-pat.jpg)
56+
57+
2. Create a [secret](../secrets) called `gh-cli` with the environment variable `GH_TOKEN` to store your GitHub token
58+
59+
### Enable Copilot Agents in your GitHub Organization
60+
61+
Copilot Agents are available on a set of paid plans. For this integration to work, this feature must be enabled. See [Managing Copilot coding agents](https://docs.github.com/en/copilot/how-tos/use-copilot-agents/manage-agents) to learn how to activate the agent for your project.
62+
63+
### Configure test reports
64+
65+
While not entirely mandatory, it's highly recommended to [configure test reports](../tests/test-reports) to obtain a standardized error report that the AI Agent can use to diagnose and fix build errors.
66+
67+
For the remainder of the tutorial, we'll assume that all tests in the CI create a file called `results.xml` containing the test results.
68+
69+
## Set up Copilot Integration
70+
71+
To set up the integration, follow these steps.
72+
73+
<Steps>
74+
75+
1. Disable draft Pull Requests on Semaphore: open your [project settings] and ensure **Build drafts on Pull Requests** is set to "No"
76+
77+
![Disable Draft PRs](./img/disable-draft-pr.jpg)
78+
79+
2. Create a prompt template file called `prompt-template.txt`. Use this example as a starting point:
80+
81+
```text title="Prompt template for Copilot"
82+
Read the following JUnit test report, diagnose the failure, and create a Pull Request with the fix. Validat
83+
e the fix before creating the Pull Request.
84+
```
85+
86+
3. Push the prompt template file to the repository on GitHub
87+
88+
4. Open the workflow editor for your project in Semaphore. Locate a block that contains tests that might fail.
89+
90+
5. Enable the `gh-cli` secret in the blog
91+
92+
6. Open the **Epilogue** and add the following commands in the **If job has failed** command box
93+
94+
```shell title="Commands to create a GitHub Issue for Copilot"
95+
cp prompt-template.txt prompt-issue.txt
96+
echo '```xml' >> prompt-issue.txt
97+
cat results.xml >> prompt-issue.txt
98+
echo -e '\n```' >> prompt-ussue.txt
99+
[[ ! "$SEMAPHORE_GIT_WORKING_BRANCH" =~ ^copilot/ ]] && gh issue create --assignee "@copilot" --title "Fix failed job: ${SEMAPHORE_JOB_NAME}" -F prompt-issue.txt
100+
```
101+
102+
![Setting up job to create issues on GitHub](./img/epilogue-create-issue-gh.jpg)
103+
104+
7. Repeat steps 4 to 6 for every block with jobs or tests in your pipeline that you wish for Copilot to diagnose and fix
105+
106+
8. Save your changes
107+
108+
</Steps>
109+
110+
## How to follow Copilot activity
111+
112+
With the integration set up, a new issue should be created every time a job or test fails in your pipeline.
113+
114+
You can follow the Copilot activity in the following places:
115+
116+
- [GitHub Copilot Agent dashboard](https://github.com/copilot/agents)
117+
- Your GitHub issues page
118+
- Your GitHub pull request page
119+
120+
While Copilot is working, you may see a draft Pull Request with the title containing "[WIP]". This means that Copilot is still working.
121+
122+
Wait until "[WIP]" disappears from the Pull Request title before marking it as ready for review. Once you mark it ready for review, a new workflow should automatically start in Semaphore. If the build is fixed, you can merge the Pull Request.
123+
124+
## See also
125+
126+
- [MCP Server](./mcp-server)
127+
- [MCP Usage Examples](./mcp-usage-examples)
128+
- [Self-healing CI](./self-healing-ci)
129+
90.9 KB
Loading
67.9 KB
Loading
134 KB
Loading

docs/docs/using-semaphore/ai/mcp-server.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ Client error: HTTP status client error (401 Unauthorized) for url (https://mcp.s
172172
- [Service accounts](../service-accounts)
173173
- [MCP Usage Examples](./mcp-usage-examples)
174174
- [Self-healing CI](./self-healing-ci)
175+
- [Copilot Cloud Integration](./copilot-agent-cloud)
175176
176177
177178

docs/docs/using-semaphore/ai/mcp-usage-examples.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,6 @@ This use case is essentially an AI-driven `tail -f`` or log viewer: you ask in n
150150

151151
- [MCP Server](./mcp-server)
152152
- [Self-healing CI](./self-healing-ci)
153+
- [Copilot Cloud Integration](./copilot-agent-cloud)
153154

154155

docs/docs/using-semaphore/ai/self-healing-ci.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ sidebar_position: 3
77

88
This page shows how to implement self-healing CI pipelines using an AI agent and the [Semaphore MCP server](./mcp-server). If you need a more tailored solution, please get in touch with support, and we can help you set up a self-healing workflow for your projects.
99

10+
:::note
11+
12+
In this scenario, we use OpenAI's Codex inside the CI to fix build errors and automatically create a Pull Request. You can swap Codex with a different AI agent with minimal changes.
13+
14+
If you prefer to use GitHub's Cloud version of Copilot, where the AI Agent runs inside GitHub instead, see [Copilot Agent Integration](./copilot-agent-cloud)
15+
16+
:::
17+
1018
## Overview
1119

1220
AI Agents such as OpenAI Codex or Claude Code can diagnose and fix test errors inside your CI. When coupled with Semaphore's MCP server, these agents can implement, push fixes, and create pull requests automatically when a build fails.
@@ -209,12 +217,5 @@ The second pipeline only creates a pull request if the AI agent successfully fix
209217

210218
- [MCP Server](./mcp-server)
211219
- [MCP Usage Examples](./mcp-usage-examples)
212-
213-
214-
215-
216-
217-
218-
219-
220+
- [Copilot Cloud Integration](./copilot-agent-cloud)
220221

0 commit comments

Comments
 (0)