Skip to content

feat: Migrate exercise to issue-based flow #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ec1b0b1
Add draft of updated exercise steps
chriswblake Jul 7, 2025
bcdba47
Add draft workflows to match updated steps
chriswblake Jul 7, 2025
5c37606
remove dependabot config
chriswblake Jul 7, 2025
95247bb
Add gitignore
chriswblake Jul 7, 2025
eea5f88
Add sample program
chriswblake Jul 7, 2025
f753f33
Add dummy requirements files
chriswblake Jul 7, 2025
9ea6e9c
Add devcontainer config
chriswblake Jul 7, 2025
2aeb989
Remove extra file
chriswblake Jul 7, 2025
5fdc493
Update readme description to match new steps
chriswblake Jul 7, 2025
9a96222
fix workflow to start exercise
chriswblake Jul 7, 2025
9b0508a
Rename workflow files to be examples
chriswblake Jul 7, 2025
8da1936
Filter trigger for step 2
chriswblake Jul 7, 2025
8ccc306
Adjustments from trial run
chriswblake Jul 8, 2025
89194dc
Adjustments from trial run
chriswblake Jul 8, 2025
d773361
add image with status checks
chriswblake Jul 8, 2025
2707d2d
escape example code from template replacement
chriswblake Jul 8, 2025
6775720
Adjustments from trial run
chriswblake Jul 8, 2025
ec7d56a
Update final review
chriswblake Jul 8, 2025
c545f1b
Switch to using pytest
chriswblake Jul 13, 2025
8dd0351
simplify step 2 instructions
chriswblake Jul 13, 2025
9e340ca
Make testing results more realistic and simpler
chriswblake Jul 13, 2025
9f33e95
cleanup
chriswblake Jul 13, 2025
175ba4f
Add minimums to example
chriswblake Jul 13, 2025
245f480
tweak python code to pass flake8
chriswblake Jul 13, 2025
e67d5c5
rename file to match default
chriswblake Jul 13, 2025
28d9ebc
cleanup from test run
chriswblake Jul 13, 2025
8b0dbcc
Add coverage config file to enable coverage comment action
chriswblake Jul 14, 2025
2dac763
Fix python-package example to match tutorial
chriswblake Jul 14, 2025
08bc2c2
Configure python-coverage workflow to fail if below limit
chriswblake Jul 14, 2025
4d6bee2
cleanup
chriswblake Jul 14, 2025
c15f8be
Add references to example files.
chriswblake Jul 14, 2025
45ea6eb
Cleanup
chriswblake Jul 14, 2025
1d66ffe
Make instructions clearer
chriswblake Jul 14, 2025
889c24c
Clarify final steps
chriswblake Jul 14, 2025
d36c9e5
Add note about introduction to repository management
chriswblake Jul 14, 2025
a45b91c
fix typo that causes activity to be hidden
chriswblake Jul 14, 2025
761e197
fix typo that breaks details box
chriswblake Jul 14, 2025
f4290a3
fix file name trigger in step 2
chriswblake Jul 14, 2025
b39dbb6
fix incorrect step name
chriswblake Jul 14, 2025
652a565
fix step number
chriswblake Jul 14, 2025
95c6e86
Adjust installation to use a virtual environment
chriswblake Jul 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
relative_files = True
14 changes: 14 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Python 3",
"image": "mcr.microsoft.com/vscode/devcontainers/python:3.13",
"postCreateCommand": "pip install -r requirements.txt&& pip install pytest coverage pytest-cov",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.debugpy",
"github.vscode-github-actions"
]
}
}
}
6 changes: 0 additions & 6 deletions .github/dependabot.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .github/script/merge-branch.sh

This file was deleted.

1 change: 0 additions & 1 deletion .github/steps/-step.txt

This file was deleted.

1 change: 0 additions & 1 deletion .github/steps/0-welcome.md

This file was deleted.

45 changes: 0 additions & 45 deletions .github/steps/1-add-a-test-workflow.md

This file was deleted.

55 changes: 55 additions & 0 deletions .github/steps/1-step.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## Step 1: Continuous Integration

GitHub Actions is a great way to automate several of your recurring tasks, saving you time to work on the more challenging and fun problems!

One of the most common tasks a developer deals with is testing their code. Unfortunately, this is often tedious and things get skipped or simply overlooked. Even more so, we often need to test against many frameworks, operating systems, and other situations, exaggerating the problem.

Let's learn how to automate this ever-growing need for testing our code by using workflows in GitHub Actions.

### What is Continuous Integration?

[Continuous integration](https://en.wikipedia.org/wiki/Continuous_integration) can help you stick to your team’s quality standards by running tests and reporting the results on GitHub. CI tools run builds and tests, triggered by commits. The quality results post back to GitHub in the pull request. The goal is fewer issues in `main` and faster feedback as you work.

### ⌨️ Activity: Start our sample Python application

1. Use the below button to open the **Create Codespace** page in a new tab. Use the default configuration.

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/{{full_repo_name}}?quickstart=1)

1. Confirm the **Repository** field is your copy of the exercise, not the original, then click the green **Create Codespace** button.

- ✅ Your copy: `/{{full_repo_name}}`
- ❌ Original: `/skills/test-with-actions`

1. Wait a moment for Visual Studio Code to load in your browser.

1. In the left navigation, select the **Explorer** tab to show the project files.

1. Open the `src/calculations.py` and `tests/calculation_tests.py` files.

1. Take a moment to read these files to become familiar.

1. Expand VS Code's built-in terminal panel.

> 💡 **Tip**: The keyboard shortcut is `CTRL` + `J`.

1. Run the below command to install the required Python libraries and tools to show code coverage.

```bash
pip install -r requirements.txt
pip install pytest coverage pytest-cov
```

1. Run the below command to run all unit tests and view coverage information.

```bash
pytest --cov=src --verbose
```

1. Add a comment to let Mona know the results of your coverage report. After reviewing, she will provide the next steps.

```md
@professortocat, I've run my coverage report.
Seems there is some opportunity to increase the test coverage. 🧐
What should we do next?
```
35 changes: 0 additions & 35 deletions .github/steps/2-fix-the-test.md

This file was deleted.

165 changes: 165 additions & 0 deletions .github/steps/2-step.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
## Step 2: Workflow files

The best way to add automation to your project's repository is with a GitHub Actions Workflow. Let's look at the anatomy of a workflow then create 2 of them.

### What are the parts of workflow?

![An illustration with a left half and a right half. On the left: illustration of how GitHub Actions terms are encapsulated. At the highest level: workflows and event triggers. Inside workflows: jobs and definition of the build environment. Inside jobs: steps. Inside steps: a call to an action. On the right: the evaluated sequence: workflow, job, step, action.](https://user-images.githubusercontent.com/6351798/88589835-f5ce0900-d016-11ea-8c8a-0e7d7907c713.png)

- **Workflow**: A unit of automation from start to finish. It begins when the trigger (`on`) matches an activity in the repository. It consists of 1 or more jobs.

- **Jobs**: The workflow's jobs each run in their own isolated environments and can be configured differently. They run in parallel unless configured otherwise or dependencies are set.

- **Steps**: The steps area is a series of related actions that achieve a job's goal. A step can be a pre-made _Action_ from the Actions Marketplace, a private Action, a local custom script, or even direct code.

- **Action**: Each step is an _Action_, a piece of automation written in a way that is compatible with workflows. Actions can be written by GitHub, by the open source community, or specific to the project.

In the above `Example Workflow` file, it will start when any commits are pushed to the repository on any branch. It will run 1 job with the name `build`. That job's first step uses a pre-made _Action_ from the `actions` organization named `checkout` that clones the code from the repository into the job's environment.

You can explore all of the configuration options in the [GitHub Actions Docs](https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions).

### ⌨️ Activity: Add a workflow to run tests

1. Open a web browser tab and navigate to this exercise repository. The Codespace is not needed right now.

1. In the top navigation, select the **Actions** tab.

1. In the left navigation, above list of workflows, click the **New workflow** button.

<img width="250" alt="image" src="https://github.com/user-attachments/assets/babb2cec-dc4c-42a2-a28c-69da8e9ea79d" />

1. Enter `python` into the search box and click the **Enter** button.

<img width="300" alt="search box with 'python' value" src="https://github.com/user-attachments/assets/34f2795c-85e8-4dc8-b03b-eac73e70e309" />

1. Find the **Python package** workflow and click the **Configure** button to open a file editor with a pre-made workflow.

<img width="250" alt="image" src="https://github.com/user-attachments/assets/4a2ff616-aedd-41b5-a24c-82014e98bbee" />

1. Around line 6, simplify the `on` trigger. Remove the `push` trigger and keep the `pull_request` trigger.

```yml
on:
pull_request:
branches: ["main"]
```

1. Around line 38, change the command to show more details in the logs.

```yml
- name: Test with pytest
run: |
pytest --verbose
```

1. Above the editor, on the right, click the **Commit changes...** button. Commit directly to the `main` branch.

<details>
<summary>Having trouble? 🤷‍♂️</summary>

Indention of `.yml` files is important. If you are getting syntax errors, that may be the reason.

Finished workflow file: `.github/workflows/python-package.yml.example`

<details>

### ⌨️ Activity: Add a workflow to show test coverage

1. Switch to the VS Code Codespace.

1. Check the status bar for a pending update. Click it to pull your recently committed workflow.

<img width="130" alt="image" src="https://github.com/user-attachments/assets/c3eb17cf-a18e-4fae-bf18-cda900c7c6d3" />

1. In the left navigation, select the **Explorer** tab to show the project files.

1. Expand the `.github/workflows/` folder.

1. Add a new file with the following name and open it.

```txt
python-coverage.yml
```

1. Enter the name and set it to trigger on pull requests targeting the `main` branch.

```yml
name: Python Coverage

on:
pull_request:
branches:
- main

permissions:
pull-requests: write
```

1. Add the `python-coverage` job and a first step that gets the repository content.

```yml
jobs:
python-coverage:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
```

1. Add steps to install Python and required packages.

```yml
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.13

- name: Install dependencies
run: |
pip install -r requirements.txt
pip install pytest==8.4.1
pip install coverage==7.9
pip install pytest-cov==6.2.1
```

1. Add steps to run the coverage report on the `src` folder.

```yml
- name: Run tests and generate coverage details
run: pytest --cov=src
```

1. Add a final step that uses a pre-made GitHub Action to share the coverage report as a comment on the pull request.

{% raw %}

```yml
- name: Coverage comment
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ github.token }}
MINIMUM_GREEN: 90
MINIMUM_ORANGE: 70

- name: Fail if below threshold
run: coverage report --fail-under=90
```

{% endraw %}

1. Commit and push the changes to your `python-coverage.yml` file to the `main` branch.

> [!TIP]
> Dis you notice the `uses:` statements? Those are pre-made steps from the free [Actions Marketplace](https://github.com/marketplace?type=actions). Consider trying one of them out before you create your own custom scripts (to maintain)! There are lots of AWESOME creations from the community!

1. With both new workflows pushed to GitHub, Mona will review your work and post the next steps.

<details>
<summary>Having trouble? 🤷‍♂️</summary>

Indention of `.yml` files is important. If you are getting syntax errors, that may be the reason.

Finished workflow file: `.github/workflows/python-coverage.yml.example`

<details>
Loading