You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/4-continuous-integration.md
+40-44Lines changed: 40 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,16 +13,17 @@ CI/CD fosters a culture of rapid development, collaboration, and continuous impr
13
13
14
14
A set of unit tests exist for the Python server for the project. You want to ensure those tests are run whenever someone makes a [pull request][about-prs] (PR). To meet this requirement, you'll need to define a workflow for the project, and ensure there is a [trigger][workflow-triggers] for pull requests to main. Fortunately, [GitHub Copilot][copilot] can aid you in creating the necessary YML file!
15
15
16
-
## Exploring the test
16
+
## Exploring the test and project
17
17
18
-
Let's take a look at the tests defined for the project.
19
-
20
-
> [!NOTE]
21
-
> There are only a few tests defined for this project. Many projects will have hundreds or thousands of tests to ensure reliability.
18
+
Let's take a look at the tests defined for the project, and the supporting script.
22
19
23
20
1. Return to your codespace, or reopen it by navigating to your repository and selecting **Code** > **Codespaces** and the name of your codespace.
24
21
2. In **Explorer**, navigate to **server** and open **test_app.py**.
25
-
3. Open GitHub Copilot Chat and, in your own words, ask for an explanation of the tests in the file.
22
+
3. Open GitHub Copilot Chat.
23
+
4. Utilizing the dropdowns below the prompt window, ensure **Ask** and **GPT-4.1** are selected for the mode and model respectively.
24
+
5. In your own words, ask for an explanation of the tests in the file.
25
+
6. In **Explorer**, navigate to **scripts** and open **run-server-tests.sh**.
26
+
7. Open GitHub Copilot Chat and, in your own words, ask for an explanation of the script which is used to run the Python tests for our Flask server.
26
27
27
28
## Understanding workflows
28
29
@@ -39,55 +40,50 @@ Creating a YML file can be a little tricky. Fortunately, GitHub Copilot can help
39
40
40
41
## Create the workflow file
41
42
43
+
> [!NOTE]
44
+
> You will notice a workflow already exists to run Playwright tests. These are part of the project to streamline library version updates. For this exercise you can ignore those tests, but we'll refer to them in a later exercise.
45
+
42
46
Now that we have an overview of the structure of a workflow, let's ask Copilot to generate it for us!
43
47
44
-
1. Create a new folder under **.github** named **workflows**.
45
-
2. Create a new file named **server-test.yml** and ensure the file is open.
46
-
3. If prompted to install the **GitHub Actions** extension, select **Install**.
47
-
4. Open GitHub Copilot Chat.
48
-
5. Add the test file **test_app.py** to the context by using the `#` in the Chat dialog box and beginning to type **test_app.py**, and pressing <kbd>enter</kbd> when it's highlighted.
49
-
6. Prompt Copilot to create a GitHub Action workflow to run the tests. Use natural language to describe the workflow you're looking to create (to run the tests defined in test_app.py), and that you want it to run on merge (for when new code is pushed), when a PR is made, and on demand.
48
+
1. Return to your codespace.
49
+
2. Ensure **run-server-tests.sh** is the active editor so Copilot will utilize the file for context when performing the task.
50
+
3. Use the following prompt to ask Copilot to create a new GitHub Actions workflow to run the tests, or modify it into your own words:
50
51
51
-
> [!IMPORTANT]
52
-
> A prescriptive prompt isn't provided as part of the exercise is to become comfortable interacting with GitHub Copilot.
52
+
Create a new GitHub Actions workflow to run the run-server-tests script for any PR or merge into main. Ensure least privilege is used in the workflow.
53
53
54
-
7. Add the generated code to the new file by hovering over the suggested code and selecting the **Insert at cursor** button. The generated code should resemble the following:
54
+
3. Copilot will explore the project, and generate the necessary YAML for the workflow. It should look like the example below:
55
55
56
56
```yml
57
57
name: Server Tests
58
58
59
59
on:
60
60
push:
61
-
branches: [ main ]
62
-
paths:
63
-
- 'server/**'
61
+
branches: [main]
64
62
pull_request:
65
-
branches: [ main ]
66
-
paths:
67
-
- 'server/**'
63
+
branches: [main]
64
+
65
+
permissions:
66
+
contents: read
68
67
69
68
jobs:
70
-
server-test:
69
+
server-tests:
70
+
name: Run Server Unit Tests
71
71
runs-on: ubuntu-latest
72
72
73
73
steps:
74
-
- uses: actions/checkout@v3
75
-
76
-
- name: Set up Python
77
-
uses: actions/setup-python@v4
78
-
with:
79
-
python-version: '3.10'
80
-
81
-
- name: Install dependencies
82
-
run: |
83
-
python -m pip install --upgrade pip
84
-
if [ -f server/requirements.txt ]; then pip install -r server/requirements.txt; fi
@@ -104,26 +100,26 @@ With the workflow created, let's push it to the repository. Typically you would
104
100
> All commands are entered using the terminal window in the codespace.
105
101
106
102
1. Use the open terminal window in your codespace, or open it (if necessary) by pressing <kbd>Ctl</kbd> + <kbd>`</kbd>.
107
-
1. List all issues for the repository by entering the following command in the terminal window:
103
+
2. List all issues for the repository by entering the following command in the terminal window:
108
104
109
105
```bash
110
106
gh issue list
111
107
```
112
108
113
-
1. Note the issue number for the one titled **Implement testing**.
114
-
1. Stage all files by entering the following command in the terminal window:
109
+
3. Note the issue number for the one titled **Implement testing**.
110
+
4. Stage all files by entering the following command in the terminal window:
115
111
116
112
```bash
117
113
git add .
118
114
```
119
115
120
-
1. Commit all changes with a message by entering the following command in the terminal window, replacing **<ISSUE_NUMBER>** with the number for the **Implement testing** issue:
116
+
5. Commit all changes with a message by entering the following command in the terminal window, replacing **<ISSUE_NUMBER>** with the number for the **Implement testing** issue:
121
117
122
118
```bash
123
119
git commit -m "Resolves #<ISSUE_NUMBER>"
124
120
```
125
121
126
-
1. Push all changes to the repository by entering the following command in the terminal window:
122
+
6. Push all changes to the repository by entering the following command in the terminal window:
We've explored how we can use GitHub Copilot to explore our project and to provide context to ensure the suggestions we receive are to the quality we expect. Now let's turn our attention to putting all this prep work into action by generating new code! We'll use GitHub Copilot to aid us in adding functionality to our website and generate the necessary unit tests.
7
+
8
+
> [!IMPORTANT]
9
+
> Something something, we're not going too deep into copilot, check out our other amazing workshop!!
10
+
11
+
## Scenario
12
+
13
+
The website currently lists all dogs in the database. While this was appropriate when the shelter only had a few dogs, as time has gone on the number has grown and it's difficult for people to sift through who's available to adopt. The shelter has asked you to add filters to the website to allow a user to select a breed of dog and only display dogs which are available for adoption.
14
+
15
+
## Overview of this exercise
16
+
17
+
To streamline the creation of both the feature and required infrastructure you'll utilize GitHub Copilot agent mode to generate the code and tests.
18
+
19
+
## GitHub Copilot agent mode
20
+
21
+
In the [prior exercise][walkthrough-previous], you utilized **ask mode** in GitHub Copilot. Ask mode is focused on "single-turn" operations, where you ask a question, receive an answer, and then repeat the flow as needed. Ask mode is great for generating individual files, learning about your project, and generic code-related questions.
22
+
23
+
**Agent mode** allows Copilot to act more like a peer programmer, both generating code suggestions and performing tasks on your behalf. Agent mode will explore your project, build an approach of how to resolve a problem, generate the code, perform supporting operations like running tests, and even self-heal should it find any problems.
24
+
25
+
By using agent mode, we'll be able to both create the code and tests, but have Copilot run the tests and correct any mistakes it might find.
26
+
27
+
## Summary and next steps
28
+
Congratulations! You've worked with GitHub Copilot to add new features to the website - the ability to filter the list of dogs. Let's close out by [creating a pull request with our new functionality][walkthrough-next]!
29
+
30
+
## Resources
31
+
-[Asking GitHub Copilot questions in your IDE][copilot-questions]
0 commit comments