Skip to content

Commit 1449a19

Browse files
committed
Restructure and other updates
1 parent 215818e commit 1449a19

File tree

7 files changed

+85
-291
lines changed

7 files changed

+85
-291
lines changed

.github/.copilotignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- content/**/*
Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ CI/CD fosters a culture of rapid development, collaboration, and continuous impr
1313

1414
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!
1515

16-
## Exploring the test
16+
## Exploring the test and project
1717

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.
2219

2320
1. Return to your codespace, or reopen it by navigating to your repository and selecting **Code** > **Codespaces** and the name of your codespace.
2421
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.
2627

2728
## Understanding workflows
2829

@@ -39,55 +40,50 @@ Creating a YML file can be a little tricky. Fortunately, GitHub Copilot can help
3940

4041
## Create the workflow file
4142

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+
4246
Now that we have an overview of the structure of a workflow, let's ask Copilot to generate it for us!
4347

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:
5051

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.
5353

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:
5555

5656
```yml
5757
name: Server Tests
5858

5959
on:
6060
push:
61-
branches: [ main ]
62-
paths:
63-
- 'server/**'
61+
branches: [main]
6462
pull_request:
65-
branches: [ main ]
66-
paths:
67-
- 'server/**'
63+
branches: [main]
64+
65+
permissions:
66+
contents: read
6867

6968
jobs:
70-
server-test:
69+
server-tests:
70+
name: Run Server Unit Tests
7171
runs-on: ubuntu-latest
7272

7373
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
85-
pip install pytest
86-
87-
- name: Run tests
88-
working-directory: ./server
89-
run: |
90-
python -m pytest test_app.py -v
74+
- name: Checkout code
75+
uses: actions/checkout@v4
76+
77+
- name: Set up Python
78+
uses: actions/setup-python@v5
79+
with:
80+
python-version: '3.13'
81+
82+
- name: Make scripts executable
83+
run: chmod +x scripts/run-server-tests.sh scripts/setup-environment.sh
84+
85+
- name: Run server tests
86+
run: ./scripts/run-server-tests.sh
9187
```
9288
9389
> [!IMPORTANT]
@@ -104,26 +100,26 @@ With the workflow created, let's push it to the repository. Typically you would
104100
> All commands are entered using the terminal window in the codespace.
105101
106102
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:
108104

109105
```bash
110106
gh issue list
111107
```
112108

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:
115111

116112
```bash
117113
git add .
118114
```
119115

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:
121117

122118
```bash
123119
git commit -m "Resolves #<ISSUE_NUMBER>"
124120
```
125121

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:
127123

128124
```bash
129125
git push

content/5-code.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Coding with GitHub Copilot
2+
3+
| [← Helping GitHub Copilot understand context][walkthrough-previous] | [Next: GitHub flow →][walkthrough-next] |
4+
|:-----------------------------------|------------------------------------------:|
5+
6+
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]
32+
- [Copilot Edits][copilot-chat-edits]
33+
- [Copilot Chat cookbook][copilot-chat-cookbook]
34+
35+
| [← Helping GitHub Copilot understand context][walkthrough-previous] | [Next: GitHub flow →][walkthrough-next] |
36+
|:-----------------------------------|------------------------------------------:|
37+
38+
[copilot-chat-cookbook]: https://docs.github.com/en/copilot/copilot-chat-cookbook
39+
[copilot-chat-edits]: https://code.visualstudio.com/docs/copilot/copilot-edits
40+
[copilot-questions]: https://docs.github.com/en/copilot/using-github-copilot/copilot-chat/asking-github-copilot-questions-in-your-ide
41+
[localhost]: http://localhost:4321
42+
[localhost-breeds]: http://localhost:5100/api/breeds
43+
[walkthrough-previous]: 5-context.md
44+
[walkthrough-next]: 7-github-flow.md

0 commit comments

Comments
 (0)