generated from skills/exercise-template
-
Notifications
You must be signed in to change notification settings - Fork 155
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
chriswblake
wants to merge
41
commits into
skills:main
Choose a base branch
from
skills-dev:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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 bcdba47
Add draft workflows to match updated steps
chriswblake 5c37606
remove dependabot config
chriswblake 95247bb
Add gitignore
chriswblake eea5f88
Add sample program
chriswblake f753f33
Add dummy requirements files
chriswblake 9ea6e9c
Add devcontainer config
chriswblake 2aeb989
Remove extra file
chriswblake 5fdc493
Update readme description to match new steps
chriswblake 9a96222
fix workflow to start exercise
chriswblake 9b0508a
Rename workflow files to be examples
chriswblake 8da1936
Filter trigger for step 2
chriswblake 8ccc306
Adjustments from trial run
chriswblake 89194dc
Adjustments from trial run
chriswblake d773361
add image with status checks
chriswblake 2707d2d
escape example code from template replacement
chriswblake 6775720
Adjustments from trial run
chriswblake ec7d56a
Update final review
chriswblake c545f1b
Switch to using pytest
chriswblake 8dd0351
simplify step 2 instructions
chriswblake 9e340ca
Make testing results more realistic and simpler
chriswblake 9f33e95
cleanup
chriswblake 175ba4f
Add minimums to example
chriswblake 245f480
tweak python code to pass flake8
chriswblake e67d5c5
rename file to match default
chriswblake 28d9ebc
cleanup from test run
chriswblake 8b0dbcc
Add coverage config file to enable coverage comment action
chriswblake 2dac763
Fix python-package example to match tutorial
chriswblake 08bc2c2
Configure python-coverage workflow to fail if below limit
chriswblake 4d6bee2
cleanup
chriswblake c15f8be
Add references to example files.
chriswblake 45ea6eb
Cleanup
chriswblake 1d66ffe
Make instructions clearer
chriswblake 889c24c
Clarify final steps
chriswblake d36c9e5
Add note about introduction to repository management
chriswblake a45b91c
fix typo that causes activity to be hidden
chriswblake 761e197
fix typo that breaks details box
chriswblake f4290a3
fix file name trigger in step 2
chriswblake b39dbb6
fix incorrect step name
chriswblake 652a565
fix step number
chriswblake 95c6e86
Adjust installation to use a virtual environment
chriswblake File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[run] | ||
relative_files = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
[](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? | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
|
||
 | ||
|
||
- **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 | ||
chriswblake marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
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] | ||
chriswblake marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> 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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.