Skip to content

Commit f4b2d6f

Browse files
committed
Add more docs
1 parent 9f56120 commit f4b2d6f

File tree

7 files changed

+180
-133
lines changed

7 files changed

+180
-133
lines changed

_config.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,16 @@ mermaid:
1212
theme: just-the-docs
1313
plugins:
1414
- jekyll-feed
15+
16+
callouts:
17+
note:
18+
title: Note
19+
color: blue
20+
21+
reference:
22+
title: Reference
23+
color: green
24+
25+
warning:
26+
title: Warning
27+
color: yellow

docs/architecture/deployment-pipeline.md

Whitespace-only changes.

docs/architecture/download-workflow.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,21 @@ title: Download Workflow
33
parent: Architecture
44
---
55

6-
# Download workflow
6+
# Download Workflow
7+
8+
```mermaid
9+
flowchart
10+
a[Download exercise] --> b[Create exercise folder]
11+
b --> c[Download base files to exercise root]
12+
c --> d[Check Git if toggled]
13+
d --> e[Check Github if toggled]
14+
e -- local --> f[Create local repo folder with repo_name]
15+
e -- remote --> g[Fork repository if toggled]
16+
g --> h[Clone repository with repo_name]
17+
f --> i[Download resources]
18+
h --> i
19+
i --> j[Create initial commit if init toggled]
20+
j --> k[Execute download function]
21+
```
22+
23+
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
title: Exercise structure
3+
parent: Architecture
4+
---
5+
6+
# Exercise structure
7+
8+
Exercises follow a fixed structure for the Git-Mastery app to pick up on:
9+
10+
```text
11+
<exercise name>
12+
├── .gitmastery-exercise.json
13+
├── README.md
14+
├── __init__.py
15+
├── download.py
16+
├── res
17+
│ └── ...
18+
├── tests
19+
│ ├── specs
20+
│ │ └── base.yml
21+
│ └── test_verify.py
22+
└── verify.py
23+
```
24+
25+
- `.gitmastery-exercise.json`: contains the exercise configuration
26+
- `README.md`: contains the instructions for the exercise for the students to attempt
27+
- `download.py`: contains the download instructions to setup the student's exercise
28+
- `verify.py`: contains the verification script for the exercise attempt
29+
- `res/`: contains resources that are available to students (see this section about [types of resources](#types-of-resources))
30+
- `tests/specs/`: contains specification files written using [`repo-smith`](https://github.com/git-mastery/git-autograder)
31+
- `tests/test_verify.py`: contains unit tests for verification script
32+
33+
## What students see
34+
35+
When a student downloads an exercise, they will see the following folder structure:
36+
37+
```text
38+
<exercise name>
39+
├── .gitmastery-exercise.json
40+
├── README.md
41+
└── <sub folder name>
42+
├── .git
43+
└── ...
44+
```
45+
46+
The root of the exercise will contain the `README.md` and `.gitmastery-exercise.json` configured from your template.
47+
48+
It also contains the sub-folder configured in `.gitmastery-exercise.json`, which is where students will attempt the exercise.
49+
50+
## Configuration structure
51+
52+
`.gitmastery-exercise.json` is used to tell the [Git-Mastery app](https://git-mastery.github.io/app) how to setup the student's exercise.
53+
54+
{: .note }
55+
56+
We opted to use a standardized configuration for exercises because they often follow a certain shape for being setup so it is easier if the application
57+
standardizes the setup via the exercise configuration.
58+
59+
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:
60+
61+
- `exercise_name`: raw exercise name that will be indexed; recommended to use [kebab case](https://developer.mozilla.org/en-US/docs/Glossary/Kebab_case)
62+
- `tags`: used during indexing on the [exercise directory](https://git-mastery.github.io/exercises)
63+
- `requires_git`: performs a check to ensure that Git is installed and the user has already configured their `user.name` and `user.email`
64+
- `requires_github`: performs a check to ensure that Github CLI is installed and the user has already authenticated themselves
65+
- `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]())
66+
- `exercise_repo`: controls the sub-folder that is generated; this is where students work on the exercise
67+
- `repo_type`: `local` or `remote`; if `remote`, then the sub-folder is generated from a remote repository
68+
- `repo_name`: name of the sub-folder; required for both `repo_type`
69+
- `init`: determines if `git init` is run for the sub-folder; required only for `local`
70+
- `create_fork`: determines if a fork is created on the user's Github account; required only for `remote`
71+
- `repo_title`: name of the remote repository to fork + clone; required only for `remote`
72+
73+
## Exercise resource types
74+
75+
There are two distinct types of resources:
76+
77+
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
78+
79+
```text
80+
<exercise name>
81+
├── .gitmastery-exercise.json
82+
├── README.md
83+
├── <base files> <-- here
84+
└── <sub folder name>
85+
├── .git
86+
└── ...
87+
```
88+
89+
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
90+
91+
```text
92+
<exercise name>
93+
├── .gitmastery-exercise.json
94+
├── README.md
95+
├── <base files>
96+
└── <sub folder name>
97+
├── .git
98+
└── <resources> <-- here
99+
```

docs/architecture/gitmastery-exercise-configuration.md

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: Verification Workflow
3+
parent: Architecture
4+
---
5+
6+
# Verification Workflow
7+
8+
```mermaid
9+
flowchart
10+
a[Verify exercise] --> b["Check if in exercise (using .gitmastery-exercise.json)"]
11+
b -- not in exercise --> c[Cancel]
12+
b -- in exercise --> d[Execute verification script on exercise folder]
13+
```

docs/contributing/exercise.md

Lines changed: 37 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ parent: Contributing
44
nav_order: 2
55
---
66

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

910
## Before contributing
1011

1112
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:
13+
1214
- [ ] Create an [exercise discussion](https://github.com/git-mastery/exercises/issues/new?template=exercise_discussion.yaml)
1315
- [ ] Obtained approval on the exercise
1416
- [ ] File a [remote repository request](https://github.com/git-mastery/exercises/issues/new?template=request_exercise_repository.yaml)
1517

16-
1718
## Create a new exercise
1819

1920
Use the provided `new.sh` script to generate the scaffolding for a new exercise:
@@ -22,117 +23,40 @@ Use the provided `new.sh` script to generate the scaffolding for a new exercise:
2223
./new.sh
2324
```
2425

25-
This script will prompt you for:
26-
27-
1. The name of the exercise -- likely to be specified in the corresponding exercise discussion
28-
2. The exercise tags (split by space) -- likely to be specified in the corresponding exercise discussion
29-
3. The exercise configuration (read the [`.gitmastery-exercise.json` configuration](#gitmastery-exercisejson-configuration) section for more info on this)
30-
31-
{: .note }
32-
33-
You should use kebab case for the exercise name.
34-
35-
It then generates the following directory structure:
36-
37-
```text
38-
<exercise name>
39-
├── .gitmastery-exercise.json
40-
├── README.md
41-
├── __init__.py
42-
├── download.py
43-
├── res
44-
│ └── ...
45-
├── tests
46-
│ ├── specs
47-
│ │ └── base.yml
48-
│ └── test_verify.py
49-
└── verify.py
50-
```
51-
52-
- `.gitmastery-exercise.json`: contains the exercise configuration; refer [here](/developers/docs/architecture/gitmastery-exercise-configuration/) for information about the configuration structure
53-
- `README.md`: contains the instructions for the exercise for the students to attempt
54-
- `download.py`: contains the download instructions to setup the student's exercise
55-
- `verify.py`: contains the verification script for the exercise attempt
56-
- `res/`: contains resources that are available to students (see this section about [types of resources](#types-of-resources))
57-
- `tests/specs/`: contains specification files written using [`repo-smith`](https://github.com/git-mastery/git-autograder)
58-
- `tests/test_verify.py`: contains unit tests for verification script
59-
60-
## Designing download process
61-
62-
The `download.py` contains the instructions to setup the local repository.
63-
64-
This is the sequence in which the Git-Mastery app downloads an exercise for a student:
65-
66-
```mermaid
67-
flowchart
68-
a[Download exercise] --> b[Create exercise folder]
69-
b --> c[Download base files to exercise root]
70-
c --> d[Check Git if toggled]
71-
d --> e[Check Github if toggled]
72-
e -- local --> f[Create local repo folder with repo_name]
73-
e -- remote --> g[Fork repository if toggled]
74-
g --> h[Clone repository with repo_name]
75-
f --> i[Download resources]
76-
h --> i
77-
i --> j[Create initial commit if init toggled]
78-
j --> k[Execute download function]
79-
```
80-
81-
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.
82-
83-
The default download script comes with a helper function to `run_command` to run local commands.
26+
The script will first prompt if you want to create a hands-on or exercise:
8427

85-
> [!NOTE]
86-
> You should be using OS-agnostic commands in the download script
28+
Enter `exercise` or `e` to create a new exercise.
8729

88-
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.
30+
Then, the script will prompt you for:
8931

90-
Refer to existing `download.py` for reference on how to setup the download script.
32+
1. The name of the exercise -- likely to be specified in the corresponding exercise discussion (you should be using kebab case for the exercise name)
33+
2. The exercise tags (split by space) -- likely to be specified in the corresponding exercise discussion
34+
3. The exercise configuration (read the [exercise configuration](/developers/docs/architecture/exercise-structure#configuration-structure) section for more info on this)
9135

92-
### What students see
36+
{: .reference }
9337

94-
When a student downloads an exercise, they will see the following folder structure:
38+
Refer to the [exercise structure document](/developers/docs/architecture/exercise-structure) for more information about the folder structure generated.
9539

96-
```text
97-
<exercise name>
98-
├── .gitmastery-exercise.json
99-
├── README.md
100-
└── <sub folder name>
101-
├── .git
102-
└── ...
103-
```
40+
## Download setup
10441

105-
The root of the exercise will contain the `README.md` and `.gitmastery-exercise.json` configured from your template.
42+
The `download.py` contains the instructions to setup the local repository.
10643

107-
It also contains the sub-folder configured in `.gitmastery-exercise.json`, which is where students will attempt the exercise.
44+
{: .reference }
10845

109-
### Types of resources
46+
For more information about how Git-Mastery downloads exercises, refer to the [Download Workflow](/developers/docs/architecture/download-workflow)
11047

111-
There are two distinct 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.
11249

113-
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
50+
These are some references for download setups for other exercises:
11451

115-
```text
116-
<exercise name>
117-
├── .gitmastery-exercise.json
118-
├── README.md
119-
├── <base files> <-- here
120-
└── <sub folder name>
121-
├── .git
122-
└── ...
123-
```
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)
12454

125-
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
55+
### Download conventions
12656

127-
```text
128-
<exercise name>
129-
├── .gitmastery-exercise.json
130-
├── README.md
131-
├── <base files>
132-
└── <sub folder name>
133-
├── .git
134-
└── <resources> <-- here
135-
```
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
13660

13761
### Testing downloads
13862

@@ -144,20 +68,13 @@ To test that your download script works, we have provided a script to simulate t
14468

14569
You can find the downloaded repository under the `test-downloads/` folder.
14670

147-
> [!NOTE]
148-
> 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
71+
## Verification setup
14972

73+
The verification process is controlled by the `verify.py`.
15074

151-
## Designing verification process
75+
{: .reference }
15276

153-
The verification process is controlled by the `verify.py`:
154-
155-
```mermaid
156-
flowchart
157-
a[Verify exercise] --> b["Check if in exercise (using .gitmastery-exercise.json)"]
158-
b -- not in exercise --> c[Cancel]
159-
b -- in exercise --> d[Execute verification script on exercise folder]
160-
```
77+
For more information about how Git-Mastery verifies exercise attempts, refer to the [Verification Workflow](/developers/docs/architecture/verification-workflow)
16178

16279
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:
16380

@@ -171,6 +88,16 @@ def verify(exercise: GitAutograderExercise) -> GitAutograderOutput:
17188

17289
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.
17390

91+
Some examples of verifications:
92+
93+
- [branch-bender](https://raw.githubusercontent.com/git-mastery/exercises/refs/heads/main/branch_bender/verify.py)
94+
- [conflict-mediator](https://raw.githubusercontent.com/git-mastery/exercises/refs/heads/main/conflict_mediator/verify.py)
95+
96+
### Verification conventions
97+
98+
1. Store the comments of the verification as constants so that they can be imported and used reliably in unit tests
99+
2. For any remote behavior to verify, provide a mock to substitute the behavior in the unit tests
100+
174101
### Testing verification
175102

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

0 commit comments

Comments
 (0)