Skip to content

Commit b9c8505

Browse files
refactor: rewrite the exercise with issue based flow (#181)
* feat: Initial draft of migration to issue-based flow * feat: add path filters to triggers * feat: Revise steps to create less codespaces * feat: Add images for step 1 * feat: Add image for step 2 * feat: Add images to step 3 * feat: Add images for step 4 * fix: remove grading check in step 4 * fix: incorrect vs code launch config * chore: wording tweaks from trial run * chore: wording tweaks from trial run * Stick to the most important features * Test run fixes * Fix edit last commands * Trigger also for postCreate.sh updates * feat: rename step 4 * feat: Prevent running on initial commit * chore: wording tweaks from trial run * fix: pushing stopped working in step 2 (#2) * feat: Change instructions to use universal image * change order of printed versions to look cleaner * tweaks from test run * fix: incorrect activity title (#3) * fix: python version no longer available (#10) * Migrate organization reference from skills-dev to skills --------- Co-authored-by: Christopher W. Blake <chriswblake@github.com>
1 parent a7b3369 commit b9c8505

21 files changed

Lines changed: 923 additions & 590 deletions

.github/dependabot.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/steps/-step.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/steps/0-welcome.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/steps/1-first-codespace.md

Lines changed: 69 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,92 @@
1-
<!--
2-
<<< Author notes: Step 1 >>>
3-
Choose 3-5 steps for your course.
4-
The first step is always the hardest, so pick something easy!
5-
Link to docs.github.com for further explanations.
6-
Encourage users to open new tabs for steps!
7-
-->
1+
## Step 1: Start a codespace and push some code
82

9-
## Step 1: Create your first codespace and push code
3+
### What's the big deal about Codespaces?
104

11-
_Welcome to "Develop code using GitHub Codespaces and Visual Studio Code"! :wave:_
5+
A **codespace** is a development environment hosted in the cloud, defined by configuration files in your repository. This creates a repeatable development environment tailored specifically to the project that simplifies developer onboarding and avoids the famous phrase "It works on my machine!" 😎
126

13-
**What's the big deal about using a codespace for software development?** A codespace is a development environment that's hosted in the cloud. You can customize your project for GitHub Codespaces by committing configuration files to your repository (also known as configuration-as-code), which creates a repeatable codespace configuration for all users of your project. Each codespace you create is hosted by GitHub in a Docker container that runs on a virtual machine. You can choose the type of machine you want to use depending on the resources you need.
7+
Each codespace follows the [Dev Container specification](https://containers.dev/implementors/spec/) and is hosted by GitHub as a [Docker container](https://code.visualstudio.com/docs/devcontainers/containers).
148

15-
GitHub offers a range of features to help your development team customize a codespace to reach peak configuration and performance needs. For example, you can:
9+
But don't worry! You don't need to know Docker or even have it installed on your machine!
1610

17-
- Create a codespace from your repository.
18-
- Push code from the codespace to your repository.
19-
- Use VS Code to develop code.
20-
- Customize the codespace with custom images.
21-
- Manage the codespace.
11+
> [!TIP]
12+
> Since the Dev Container configuration is part of the repository, you can also use it locally with your own Docker host. Nice!
2213
23-
To begin developing using GitHub Codespaces, you can create a codespace from a template or from any branch or commit in a repository. When you create a codespace from a template, you can start from a blank template or choose a template suitable for the work you're doing.
14+
A Codespace has several advantages/features compared to local development. To name a few:
2415

25-
### :keyboard: Activity: Start a codespace
16+
- Start a codespace directly from the repository page.
17+
- Develop in the browser. No IDE installation required.
18+
- Option to use a local install of VS Code to link to the remote Codespace.
19+
- Preconfigure everything you need to run the project:
20+
- Add **[features](https://containers.dev/features)** to install common development needs.
21+
- Run scripts at various steps of the codespace lifecycle _(e.g install python/npm packages)_.
22+
- Setup VS Code settings and extensions to match the project needs.
23+
- Fast internet access (since the container is in the datacenter).
2624

27-
**We recommend opening another browser tab to work through the following activities so you can keep these instructions open for reference.**
25+
> [!TIP]
26+
> Codespaces are even useful in short-lived situations like reviewing a pull request. No need to verify you have the right setup to test out the incoming code changes.
2827
29-
1. Start from the landing page of your repository.
30-
1. Click the green **Code** button located in the middle of the page.
31-
1. Select the **Codespaces** tab in the box that pops up and then click the **Create codespace on main** button.
28+
Let's get started! We'll start up a Codespace, run the application, make a change, and push it. Like normal development! 🤓
3229

33-
> Wait about 2 minutes for the codespace to spin itself up.
34-
> **Note**: It's a virtual machine spinning up in the background.
30+
### ⌨️ Activity: Start a codespace
3531

36-
1. Verify your codespace is running. The browser should contain a VS Code web-based editor and a terminal should be present such as the below:
37-
![codespace1](https://user-images.githubusercontent.com/26442605/207355196-71aab43f-35a9-495b-bcfe-bf3773c2f1b3.png)
32+
1. Open a second tab and navigate to this repository. Ensure you are on the **Code** tab.
3833

39-
### :keyboard: Activity: Push code to your repository from the codespace
34+
1. Above the files list on the right, click the green **<> Code** button.
4035

41-
1. From inside the codespace in the VS Code explorer window, select the `index.html` file.
42-
1. Replace the **h1** header with the below:
36+
<img width="300" alt="green code button" src="https://github.com/user-attachments/assets/a9d80b0d-4614-4b26-83dd-b4b6fefd76c9" />
4337

44-
```html
45-
<h1>Hello from the codespace!</h1>
38+
1. Select the **Codespaces** tab and click the **Create codespace on main** button. A new window will open running VS Code and it will connect to the remote Codespace. Wait a few minutes for the codespace to be created.
39+
40+
1. Look in the bottom left of the VS Code window see the remote connection.
41+
42+
<img width="350" alt="remote connection status in VS Code" src="https://github.com/user-attachments/assets/35fa3230-db51-4a9d-a82b-3a1184e2e9a0"/>
43+
44+
> [!TIP]
45+
> GitHub uses the [universal](https://github.com/devcontainers/images/tree/main/src/universal) Codespace image if the repository doesn't include a configuration. It includes several useful and commonly used tools.
46+
47+
### ⌨️ Activity: Run the application
48+
49+
1. Ensure you are in the VS Code Codespace.
50+
51+
1. In the left sidebar, select the file **Explorer** tab and open the file `src/hello.py`.
52+
53+
<img width="250" alt="vs code explorer tab" src="https://github.com/user-attachments/assets/76af1f05-1fed-43ff-b362-43d1c6c6cc53" />
54+
55+
1. In the lower panel, select the **TERMINAL** tab.
56+
57+
<img width="350" alt="vs code terminal tab" src="https://github.com/user-attachments/assets/9bb493b6-167c-4414-8f39-ab9c4baa5514" />
58+
59+
1. Paste the following command in the Codespace's remote terminal to show the installed versions of several tools. Note the versions for comparison later.
60+
61+
```bash
62+
node --version
63+
dotnet --version
64+
python --version
65+
gh --version
66+
```
67+
68+
1. Paste the following command to run the Python program in the Codespace's remote terminal.
69+
70+
```bash
71+
python src/hello.py
4672
```
4773

48-
1. Save the file.
49-
> **Note**: The file should autosave.
50-
1. Use the VS Code terminal to commit the file change by entering the following commit message:
74+
### ⌨️ Activity: Push changes to your repository from the codespace
5175

52-
```shell
53-
git commit -a -m "Adding hello from the codespace!"
76+
1. Replace the `src/hello.py` file contents with the following and save the file.
77+
78+
```py
79+
print("Hello World!")
5480
```
5581

56-
1. Push the changes back to your repository. From the VS Code terminal, enter:
82+
1. With the message updated, commit the change and push it to GitHub. Use VS Code's source control tools or the below terminal commands.
5783

58-
```shell
84+
```bash
85+
git add 'src/hello.py'
86+
git commit -m 'fix: incomplete hello message'
5987
git push
6088
```
6189

62-
1. Your code has been pushed to your repository!
63-
1. Switch back to the homepage of your repository and view the `index.html` to verify the new code was pushed to your repository.
64-
1. Wait about 20 seconds then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/en/actions) will automatically update to the next step.
90+
1. (optional) Back in your web browser, open the `src/hello.py` file to to verify the change was updated.
91+
92+
1. With the the change pushed to GitHub, Mona will begin checking your work. Give her a moment to provide feedback and the next learning steps.

.github/steps/2-custom-image.md

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,75 @@
1-
<!--
2-
<<< Author notes: Step 2 >>>
3-
Start this step by acknowledging the previous step.
4-
Define terms and link to docs.github.com.
5-
-->
1+
## Step 2: Use a custom image in your codespace
62

7-
## Step 2: Add a custom image to your codespace!
3+
The didn't specify any configuration for the codespace we just created, so GitHub used a default Docker image. While this is very useful, it won't be consistent and it doesn't version lock our runtime environment. Specifying the configuration is important to keep the development environment repeatable.
84

9-
_Nice work! :tada: You created your first codespace and pushed code using VS Code!_
5+
Let's do that now by providing a specific docker container image.
106

11-
You can configure the development container for a repository so that any codespace created for that repository will give you a tailored development environment, complete with all the tools and runtimes you need to work on a specific project.
7+
### How to configure a Codespace?
128

13-
**What are development containers?** Development containers, or dev containers, are Docker containers that are specifically configured to provide a fully featured development environment. Whenever you work in a codespace, you are using a dev container on a virtual machine.
9+
Configuration is provided directly in the repository via the `.devcontainer/devcontainer.json`. You can even add multiple configurations!
1410

15-
A dev container file is a JSON file that lets you customize the default image that runs your codespace, VS code settings, run custom code, forward ports and much more!
11+
Let's create this file and set a few of the most common settings. For other options like setting configuring VS Code, forwarding ports, and running lifecycle scripts, see the [Codespaces documentation](https://docs.github.com/en/codespaces/setting-up-your-project-for-codespaces) on GitHub.
1612

17-
Let's add a `devcontainer.json` file and add a custom image.
13+
### ⌨️ Activity: Customize the codespace
1814

19-
### :keyboard: Activity: Add a .devcontainer.json file to customize your codespace
15+
1. Ensure you are in the VS Code Codespace.
2016

21-
1. Navigating back to your **Code** tab of your repository, click the **Add file** drop-down button, and then click `Create new file`.
22-
1. Type or paste the following in the empty text field prompt to name your file.
17+
1. Use the VS Code file explorer to create the configuration file.
2318

24-
```
19+
```txt
2520
.devcontainer/devcontainer.json
2621
```
2722

28-
1. In the body of the new **.devcontainer/devcontainer.json** file, add the following content:
23+
Alternately, run the below terminal command to create it.
2924

30-
```jsonc
31-
{
32-
// Name this configuration
33-
"name": "Codespace for Skills!",
34-
// Use the base codespace image
35-
"image": "mcr.microsoft.com/vscode/devcontainers/universal:latest",
25+
```bash
26+
mkdir -p .devcontainer
27+
touch .devcontainer/devcontainer.json
28+
```
29+
30+
1. Open the `.devcontainer/devcontainer.json` file and add the following content. Let's start with a basic image.
3631

37-
"remoteUser": "codespace",
38-
"overrideCommand": false
32+
```json
33+
{
34+
"name": "Basic Dev Environment",
35+
"image": "mcr.microsoft.com/vscode/devcontainers/base:debian"
3936
}
4037
```
4138

42-
1. Click **Commit changes** and then select **Commit changes directly to the `main` branch**.
43-
1. Create a new codespace by navigating back to the **Code** tab of your repository.
44-
1. Click the green **Code** button located in the middle of the page.
45-
1. Click the **Codespaces** tab on the box that pops up.
46-
1. Click the **Create codespace on main** button OR click the `+` sign on the tab. This will create a new codespace on the main branch. (Notice your other codespace listed here.)
39+
> 💡 **Tip**: The name is optional but it will help identify the configuration when creating a codespace on GitHub, if there are multiple options.
40+
41+
1. After saving, VS Code likely popped up a notification that it detected a configuration change. You can **Accept** that option to rebuild the development container or manually use the Command Palette (`CTRL`+`Shift`+`P`) and run the command `Codespaces: Rebuild Container`. Select the **Rebuild** option. A full build is not necessary.
42+
43+
<img width="350" alt="rebuild codespace command" src="https://github.com/user-attachments/assets/2b72e1a7-68c4-4c8d-8bf1-5727a520fd0e"/>
44+
45+
1. Wait a few minutes for the Codespace to rebuild and VS Code to reconnect.
4746

48-
> Wait about **2 minutes** for the codespace to spin itself up.
47+
1. Expand the lower panel and select the **TERMINAL** tab.
4948

50-
1. Verify that your new codespace is running, as you did previously.
49+
1. Use the following command to check the tool versions again. Notice that none are installed now!
5150

52-
Note the image being used is the default image provided for GitHub Codespaces. It includes runtimes and tools for Python, Node.js, Docker, and more. See the full list here: https://aka.ms/ghcs-default-image. Your development team can use any custom image that has the necessary prerequisites installed. For more information, see [codespace image](https://aka.ms/configure-codespace).
51+
```bash
52+
node --version
53+
dotnet --version
54+
python --version
55+
gh --version
56+
```
57+
58+
1. ⚠️ There is currently a bug with Codespaces that expects [Git-LFS](https://git-lfs.com/) to be installed. Run the following command to remove the affected Git hooks.
59+
60+
```bash
61+
rm .git/hooks/post-checkout
62+
rm .git/hooks/post-commit
63+
rm .git/hooks/post-merge
64+
rm .git/hooks/pre-push
65+
```
66+
67+
1. With our new configuration verified, let's commit the changes. Use VS Code's source control tools or the below terminal command.
68+
69+
```bash
70+
git add '.devcontainer/devcontainer.json'
71+
git commit -m 'feat: Add codespace configuration'
72+
git push
73+
```
5374

54-
1. Wait about 20 seconds then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/en/actions) will automatically update to the next step.
75+
1. With our dev container configuration committed, Mona will begin checking your work. Give her a moment to provide feedback and the next learning steps.

0 commit comments

Comments
 (0)