Skip to content

Commit b82ac87

Browse files
committed
Add basic hands-on
1 parent d85be7c commit b82ac87

File tree

4 files changed

+38
-198
lines changed

4 files changed

+38
-198
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: Hands-on Structure
3+
parent: Architecture
4+
---

docs/contributing/exercise.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ nav_order: 2
1212
If you are proposing a new exercise (i.e., not implementing an [already approved exercise proposal](https://github.com/git-mastery/exercises/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22exercise%20discussion%22%20label%3A%22help%20wanted%22)) make sure that you have done the following:
1313

1414
- [ ] Create an [exercise discussion](https://github.com/git-mastery/exercises/issues/new?template=exercise_discussion.yaml)
15-
- [ ] Obtained approval on the exercise
15+
- [ ] Obtain approval on the exercise
1616
- [ ] File a [remote repository request](https://github.com/git-mastery/exercises/issues/new?template=request_exercise_repository.yaml)
1717

1818
## Create a new exercise

docs/contributing/hands-on.md

Lines changed: 33 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -4,190 +4,59 @@ parent: Contributing
44
nav_order: 1
55
---
66

7-
# Contributing an exercise
7+
1. TOC
8+
{:toc}
89

910
## Before contributing
1011

11-
If you are proposing a new exercise (i.e., not implementing an [already approved exercise proposal](https://github.com/git-mastery/exercises/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22exercise%20discussion%22%20label%3A%22help%20wanted%22)) make sure that you have done the following:
12-
- [ ] Create an [exercise discussion](https://github.com/git-mastery/exercises/issues/new?template=exercise_discussion.yaml)
13-
- [ ] Obtained approval on the exercise
14-
- [ ] File a [remote repository request](https://github.com/git-mastery/exercises/issues/new?template=request_exercise_repository.yaml)
15-
16-
## Prerequisites
17-
18-
- Bash environment
19-
- Python 3.13
20-
- Github CLI [installed and authenticated](https://github.com/cli/cli#installation) for testing the download script
21-
22-
## Setup
23-
24-
1. Fork this repository
25-
2. Clone the fork
26-
27-
```bash
28-
git clone https://github.com/<username>/exercises
29-
```
30-
31-
3. Setup a virtual environment
32-
33-
```bash
34-
python -m venv venv
35-
```
36-
37-
4. Activate the virtual environment
38-
39-
```bash
40-
source venv/bin/activate
41-
```
42-
43-
If you are using Windows, you should run the following instead:
44-
45-
```bash
46-
source venv/Scripts/activate
47-
```
12+
If you are proposing a new hands-on (i.e., not implementing an [already approved hands-on proposal](https://github.com/git-mastery/exercises/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22hands-on%20discussion%22%20label%3A%22help%20wanted%22)) make sure that you have done the following:
4813

49-
5. Install all dependencies
50-
51-
```bash
52-
pip install -r requirements.txt
53-
```
14+
- [ ] Create an [hands-on discussion](https://github.com/git-mastery/exercises/issues/new?template=hands_on_discussion.yaml)
15+
- [ ] Obtain approval on the hands-on
16+
- [ ] File a [remote repository request](https://github.com/git-mastery/exercises/issues/new?template=request_exercise_repository.yaml)
5417

55-
## Create a new exercise
18+
## Create a new hands-on
5619

5720
Use the provided `new.sh` script to generate the scaffolding for a new exercise:
5821

5922
```bash
6023
./new.sh
6124
```
6225

63-
This script will prompt you for:
64-
65-
1. The name of the exercise -- likely to be specified in the corresponding exercise discussion
66-
2. The exercise tags (split by space) -- likely to be specified in the corresponding exercise discussion
67-
3. The exercise configuration (read the [`.gitmastery-exercise.json` configuration](#gitmastery-exercisejson-configuration) section for more info on this)
68-
69-
> [!TIP]
70-
> You should use kebab case for the exercise name.
71-
72-
It then generates the following directory structure:
73-
74-
```text
75-
<exercise name>
76-
├── .gitmastery-exercise.json
77-
├── README.md
78-
├── __init__.py
79-
├── download.py
80-
├── res
81-
│ └── ...
82-
├── tests
83-
│ ├── specs
84-
│ │ └── base.yml
85-
│ └── test_verify.py
86-
└── verify.py
87-
```
26+
The script will first prompt if you want to create a hands-on or exercise:
8827

89-
- `.gitmastery-exercise.json`: contains the exercise configuration
90-
- `README.md`: contains the instructions for the exercise for the students to attempt
91-
- `download.py`: contains the download instructions to setup the student's exercise
92-
- `verify.py`: contains the verification script for the exercise attempt
93-
- `res/`: contains resources that are available to students (see this section about [types of resources](#types-of-resources))
94-
- `tests/specs/`: contains specification files written using [`repo-smith`](https://github.com/git-mastery/git-autograder)
95-
- `tests/test_verify.py`: contains unit tests for verification script
28+
Enter `hands-on` or `h` to create a new hands-on.
9629

97-
### `.gitmastery-exercise.json` configuration
30+
Then, the script will prompt you for:
9831

99-
The `.gitmastery-exercise.json` is used to tell the [Git-Mastery app](https://git-mastery.github.io/app) how to setup the student's exercise.
32+
1. The name of the hands-on -- likely to be specified in the corresponding hands-on discussion (you should be using kebab case for the hands-on name)
33+
2. Does the exercise require Git?
34+
3. Does the exercise require Github?
10035

101-
The `new.sh` script should have already generated one for you, but you may change your mind with the configuration and modify the file directly:
36+
{: .reference }
10237

103-
- `exercise_name`: raw exercise name that will be indexed; recommended to use [kebab case](https://developer.mozilla.org/en-US/docs/Glossary/Kebab_case)
104-
- `tags`: used during indexing on the [exercise directory](https://git-mastery.github.io/exercises)
105-
- `requires_git`: performs a check to ensure that Git is installed and the user has already configured their `user.name` and `user.email`
106-
- `requires_github`: performs a check to ensure that Github CLI is installed and the user has already authenticated themselves
107-
- `base_files`: specifies the files from `res/` to be downloaded into the exercise root; typically used for the `answers.txt` (more about grading types [here]())
108-
- `exercise_repo`: controls the sub-folder that is generated; this is where students work on the exercise
109-
- `repo_type`: `local` or `remote`; if `remote`, then the sub-folder is generated from a remote repository
110-
- `repo_name`: name of the sub-folder; required for both `repo_type`
111-
- `init`: determines if `git init` is run for the sub-folder; required only for `local`
112-
- `create_fork`: determines if a fork is created on the user's Github account; required only for `remote`
113-
- `repo_title`: name of the remote repository to fork + clone; required only for `remote`
38+
Refer to the [hands-on structure document](/developers/docs/architecture/hands-on-structure) for more information about the folder structure generated.
11439

115-
## Designing download process
40+
## Download setup
11641

11742
The `download.py` contains the instructions to setup the local repository.
11843

119-
This is the sequence in which the Git-Mastery app downloads an exercise for a student:
120-
121-
```mermaid
122-
flowchart
123-
a[Download exercise] --> b[Create exercise folder]
124-
b --> c[Download base files to exercise root]
125-
c --> d[Check Git if toggled]
126-
d --> e[Check Github if toggled]
127-
e -- local --> f[Create local repo folder with repo_name]
128-
e -- remote --> g[Fork repository if toggled]
129-
g --> h[Clone repository with repo_name]
130-
f --> i[Download resources]
131-
h --> i
132-
i --> j[Create initial commit if init toggled]
133-
j --> k[Execute download function]
134-
```
135-
136-
As a result, the `download` function is the last step after you have already setup the folder structures and downloaded the base files and resources.
137-
138-
The default download script comes with a helper function to `run_command` to run local commands.
139-
140-
> [!NOTE]
141-
> You should be using OS-agnostic commands in the download script
142-
143-
The initial download script also includes a command to attach a tag as the "start tag". This is only useful if you want to iterate through the user's commits in your verification script. Otherwise, this can be removed.
144-
145-
Refer to existing `download.py` for reference on how to setup the download script.
146-
147-
### What students see
148-
149-
When a student downloads an exercise, they will see the following folder structure:
44+
{: .reference }
15045

151-
```text
152-
<exercise name>
153-
├── .gitmastery-exercise.json
154-
├── README.md
155-
└── <sub folder name>
156-
├── .git
157-
└── ...
158-
```
159-
160-
The root of the exercise will contain the `README.md` and `.gitmastery-exercise.json` configured from your template.
161-
162-
It also contains the sub-folder configured in `.gitmastery-exercise.json`, which is where students will attempt the exercise.
46+
For more information about how Git-Mastery downloads exercises, refer to the [Download Workflow](/developers/docs/architecture/download-workflow)
16347

164-
### Types of resources
48+
The default download script comes with a helper function to `run_command` to run local command, and a command to attach a tag as the "start tag". This is only useful if you want to iterate through the user's commits in your verification script. Otherwise, this can be removed.
16549

166-
There are two distinct types of resources:
50+
These are some references for download setups for other exercises:
16751

168-
1. Base files: configured through the `base_files` property in `.gitmastery-exercise.json` in your template; files located in `res/` are downloaded to the root of the exercise folder
52+
- [ignoring-somethings](https://raw.githubusercontent.com/git-mastery/exercises/refs/heads/main/ignoring_somethings/download.py)
53+
- [branch-bender](https://raw.githubusercontent.com/git-mastery/exercises/refs/heads/main/branch_bender/download.py)
16954

170-
```text
171-
<exercise name>
172-
├── .gitmastery-exercise.json
173-
├── README.md
174-
├── <base files> <-- here
175-
└── <sub folder name>
176-
├── .git
177-
└── ...
178-
```
55+
### Download conventions
17956

180-
2. Resources: configured through the `__resources__` field in `download.py`; supporting files for the exercise with files located in `res/` downloaded into the sub folder
181-
182-
```text
183-
<exercise name>
184-
├── .gitmastery-exercise.json
185-
├── README.md
186-
├── <base files>
187-
└── <sub folder name>
188-
├── .git
189-
└── <resources> <-- here
190-
```
57+
1. Any operations should use OS agnostic options (e.g. opting to use `shutil.rmtree` over `run_command(["rm"])`)
58+
2. If you need to compare the states before and after the student has started to add commits, use the given "start tag" as `git-autograder` is designed to read that if necessary
59+
3. For any commands that require `gh` (Github CLI), make sure that the `requires_github` configuration is set to `true` so that the app will automatically check that the student has correctly setup Github CLI
19160

19261
### Testing downloads
19362

@@ -199,47 +68,15 @@ To test that your download script works, we have provided a script to simulate t
19968

20069
You can find the downloaded repository under the `test-downloads/` folder.
20170

202-
> [!NOTE]
203-
> If you wish to support a remote repository and require the Git-Mastery team to create a new repository, create an issue and we will assess the request accordingly
204-
205-
206-
## Designing verification process
71+
## Submitting the hands-on for review
20772

208-
The verification process is controlled by the `verify.py`:
209-
210-
```mermaid
211-
flowchart
212-
a[Verify exercise] --> b["Check if in exercise (using .gitmastery-exercise.json)"]
213-
b -- not in exercise --> c[Cancel]
214-
b -- in exercise --> d[Execute verification script on exercise folder]
215-
```
216-
217-
The [`git-autograder`](https://github.com/git-mastery/git-autograder) is built as a wrapper around [`GitPython`](https://github.com/gitpython-developers/GitPython). As a result, if you are writing any verification scripts and there is no available helper function with `git-autograder`, you can fall back to the underlying `Repo` object:
218-
219-
```python
220-
def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
221-
# Access the underlying GitPython repo:
222-
exercise.repo.repo
223-
224-
return exercise.to_output([], GitAutograderStatus.SUCCESSFUL)
225-
```
226-
227-
Refer to existing `verify.py` scripts to understand what are the available helper functions to streamline the grading. Open an issue if there is something that is not yet supported or if you have a question.
228-
229-
### Testing verification
230-
231-
To test the verification, we rely on [`repo-smith`](https://github.com/git-mastery/repo-smith) to simulate exercise states and write unit tests to verify the verification script's behavior. You don't need to simulate the entire flow, just the end states that you require for your verification script.
232-
233-
Refer to existing `test_verify.py` to see examples of unit testing the verification script.
234-
235-
You can run the unit tests of your exercise via:
73+
Create a pull request from your fork using the provided pull request template.
23674

237-
```bash
238-
./test.sh <your exercise folder>
239-
```
75+
Fill in all of the details necessary.
24076

241-
## Submitting the exercise for review
77+
## Example
24278

243-
Create a pull request from your fork using the provided pull request template.
79+
1. Hands-on discussion: <https://github.com/git-mastery/exercises/issues/44>
80+
2. Remote repository request: <https://github.com/git-mastery/exercises/issues/25>
81+
3. Hands-on PR:
24482

245-
Fill in all of the details necessary.

index.markdown

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ Developer documentation about all things Git-Mastery.
1313

1414
Git-Mastery is a Git education tool developed by the National University of Singapore School of Computing to help students master Git through hands-on, guided tours with real-world scenario exercises.
1515

16-
##

0 commit comments

Comments
 (0)