Skip to content

Commit 38aad54

Browse files
authored
Initial commit
0 parents  commit 38aad54

File tree

16 files changed

+1003
-0
lines changed

16 files changed

+1003
-0
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"

.github/steps/1-step.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## Step 1: Create a workflow file
2+
3+
### 📖 Theory: Introduction to workflows
4+
5+
A **workflow** is an automated process that you define in your repository. Workflows are described in YAML files stored in the `.github/workflows` directory. Each workflow is triggered by specific [events](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows) happening in your repository such as opening a pull request, pushing code, or creating an issue.
6+
7+
Workflows let you automate tasks like building, testing, or deploying your code, and can respond to almost any activity in your project.
8+
9+
> [!NOTE]
10+
> If you want to learn more check out these resources:
11+
> - [Understanding GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions)
12+
> - [Events that trigger workflows](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows)
13+
14+
### ⌨️ Activity: Create a workflow file
15+
16+
1. Open this repository in a new browser tab so you can work on the steps while you read the instructions in this tab.
17+
18+
1. In the **Code** tab of your repository, create a new branch named `welcome-workflow`.
19+
20+
<img width="400" alt="create branch screenshot" src="https://github.com/user-attachments/assets/8aa4a918-c877-4214-9efe-c9a99ca6421b" />
21+
22+
1. In the `welcome-workflow` branch, navigate to the `.github/workflows` directory.
23+
24+
1. Create a new file named `welcome.yml` in the `.github/workflows` directory with the following content:
25+
26+
```yaml
27+
name: Post welcome comment
28+
on:
29+
pull_request:
30+
types: [opened]
31+
permissions:
32+
pull-requests: write
33+
```
34+
35+
> [!NOTE]
36+
> This is an incomplete workflow file. It is normal if you receive an error message. One step at a time! 😎
37+
38+
1. Commit your changes directly to the `welcome-workflow` branch.
39+
40+
1. With your workflow file committed, Mona will check your work and prepare the next step in this exercise!
41+
42+
<details>
43+
<summary>Having trouble? 🤷</summary><br/>
44+
45+
- Make sure you are on the `welcome-workflow` branch when creating the workflow file.
46+
- Double-check the file path and YAML indentation.
47+
48+
</details>

.github/steps/2-step.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## Step 2: Add a job to your workflow file
2+
3+
Nice work! :tada: You added a workflow file!
4+
5+
### 📖 Theory: Introduction to jobs
6+
7+
A [job](https://docs.github.com/en/actions/about-github-actions/understanding-github-actions#jobs) is a group of steps that run together on the same [runner](https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners) within a workflow. Each job is defined under the `jobs` section and runs independently and in parallel by default.
8+
9+
Jobs help you organize your workflow into logical units, such as building, testing, or deploying your code.
10+
11+
> [!Tip]
12+
> You can define a job to run with multiple [variations using a matrix strategy](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow).
13+
14+
### ⌨️ Activity: Add a job to your workflow file
15+
16+
1. In the `welcome-workflow` branch, open your `.github/workflows/welcome.yml` file.
17+
18+
1. Edit the file to add the `jobs` section and 1 job named `welcome`, which will run on the latest Ubuntu operating system.
19+
20+
```yaml
21+
name: Post welcome comment
22+
on:
23+
pull_request:
24+
types: [opened]
25+
permissions:
26+
pull-requests: write
27+
jobs:
28+
welcome:
29+
name: Post welcome comment
30+
runs-on: ubuntu-latest
31+
```
32+
33+
1. Commit your changes to the `welcome-workflow` branch.
34+
35+
1. With the job information added, Mona will review your work and prepare the next step in this exercise!
36+
37+
<details>
38+
<summary>Having trouble? 🤷</summary><br/>
39+
40+
- Make sure the `jobs` section is properly indented in your YAML file.
41+
- Confirm you are editing the correct file and branch.
42+
43+
</details>

.github/steps/3-step.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## Step 3: Add a step to your workflow file
2+
3+
_Nice work adding a job to your workflow! :dancer:_
4+
5+
### 📖 Theory: Introduction to steps in jobs
6+
7+
[Steps](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idsteps) are the building blocks of jobs, allowing you to automate tasks like checking out code, running commands, or using open source Actions. They run sequentially in the job's environment but as independent processes. Unlike traditional code with a shared variable space, [inputs](https://docs.github.com/en/actions/sharing-automations/creating-actions/metadata-syntax-for-github-actions#inputs) and [outputs](https://docs.github.com/en/actions/sharing-automations/creating-actions/metadata-syntax-for-github-actions#outputs-for-docker-container-and-javascript-actions) must be explicitly declared.
8+
9+
> [!TIP]
10+
> The best part of GitHub Actions is the [marketplace](https://github.com/marketplace?type=actions) where the community has already built many free useful tools to [find and customize](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/using-pre-written-building-blocks-in-your-workflow)!
11+
12+
### ⌨️ Activity: Add a step to your workflow file
13+
14+
1. In the `welcome-workflow` branch, open your `.github/workflows/welcome.yml` file.
15+
16+
1. Add a step to the `welcome` job to post a comment on new pull requests using GitHub CLI:
17+
18+
```yaml
19+
name: Post welcome comment
20+
on:
21+
pull_request:
22+
types: [opened]
23+
permissions:
24+
pull-requests: write
25+
jobs:
26+
welcome:
27+
name: Post welcome comment
28+
runs-on: ubuntu-latest
29+
steps:
30+
- run: gh pr comment "$PR_URL" --body "Welcome to the repository!"
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
PR_URL: ${{ github.event.pull_request.html_url }}
34+
```
35+
36+
1. Commit your changes directly to `welcome-workflow` branch.
37+
38+
1. With the step information added, Mona will review your work and prepare the next step in this exercise!
39+
40+
<details>
41+
<summary>Having trouble? 🤷</summary><br/>
42+
43+
- Make sure the `steps` section is under the `welcome` job and properly indented.
44+
- Ensure you have the correct environment variables set.
45+
46+
</details>

.github/steps/4-step.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## Step 4: Trigger the workflow
2+
3+
_You've now added a fully functioning workflow to your repository! :smile:_
4+
5+
### 📖 Theory: Seeing your workflow in action
6+
7+
All the running and finished workflows can be seen on the **Actions** tab of your repository.
8+
9+
Because you set the workflow to run on the `pull_request` event, it will automatically trigger when a pull request is opened.
10+
11+
> [!TIP]
12+
> Workflow associated to pull request can also be seen on the pull request log near the merge button. You can even [create a rule](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/available-rules-for-rulesets#require-status-checks-to-pass-before-merging) that prevents merging if the workflow fails!
13+
14+
### ⌨️ Activity: Trigger the workflow
15+
16+
1. In the **Pull requests** tab, create a pull request from `welcome-workflow` branch into `main`.
17+
18+
1. Notice the comment that the workflow adds to the pull request.
19+
20+
1. Notice the area near the merge button that "All checks have passed".
21+
22+
1. With the pull request created and our workflow triggered, Mona will prepare the next step in this exercise!
23+
24+
### ⌨️ Activity: (optional) Inspect the workflow
25+
26+
1. At the top of the repository, select the **Actions** tab.
27+
28+
1. In the left sidebar, select the workflow named **Post welcome comment**.
29+
30+
> 💡 **Tip:** You can ignore the other actions. Those were for teaching this exercise.
31+
32+
1. Click the first run entry titled **Welcome workflow** to show a diagram of the run's jobs.
33+
34+
1. Click on the job named **Post welcome comment** to see the full logs.
35+
36+
37+
<details>
38+
<summary>Having trouble? 🤷</summary><br/>
39+
40+
- Check the **Actions** tab for workflow run details and errors.
41+
42+
</details>

.github/steps/5-step.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Step 5: Merge and experiment
2+
3+
_Great job! You have created and tested your first GitHub Actions workflow!_ :rocket:
4+
5+
### 📖 Theory: When workflows run
6+
7+
When you create a workflow in a branch, it is only enabled for that branch until you merge it into the default branch (`main`). When a workflow is in the default branch it applies to the entire repository.
8+
9+
Every new pull request regardless of branch will now automatically trigger the workflow you created.
10+
11+
> [!TIP]
12+
> Some event triggers, like [workflow_dispatch](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_dispatch) and [schedule](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#schedule) will only work if the workflow file exists in default branch.
13+
14+
### ⌨️ Activity: Merging your pull request
15+
16+
1. Merge your pull request into the `main` branch.
17+
18+
1. (Optional) Try opening another pull request to see your workflow run again!
19+

.github/steps/x-review.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Finish
2+
3+
_Congratulations friend, you've completed this exercise!_
4+
5+
<img src="https://octodex.github.com/images/jetpacktocat.png" alt="Mona the Octocat wearing a jetpack and smiling." width="300" align="right"/>
6+
7+
Here's a recap of all the tasks you've accomplished in your repository:
8+
9+
1. You've created your first GitHub Actions workflow file.
10+
1. You learned where to make your workflow file.
11+
1. You defined an event trigger, a job, and a step for your workflow.
12+
1. You're ready to automate anything you can dream of.
13+
14+
### What's next?
15+
16+
- Take another exercise on [GitHub Learn](https://learn.github.com/skills)
17+
- Take the [AI in Actions](https://github.com/skills/ai-in-actions) exercise to learn how to leverage AI models within your GitHub Actions workflows
18+
- [Learn more about GitHub Actions](https://docs.github.com/actions/)
19+
- [Awesome Actions](https://github.com/sdras/awesome-actions)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Step 0 # Start Exercise
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
actions: write
11+
issues: write
12+
13+
env:
14+
STEP_1_FILE: ".github/steps/1-step.md"
15+
16+
jobs:
17+
start_exercise:
18+
name: Start Exercise
19+
uses: skills/exercise-toolkit/.github/workflows/[email protected]
20+
with:
21+
exercise-title: "Hello GitHub Actions"
22+
intro-message: "Create and run a GitHub Actions workflow."
23+
24+
post_next_step_content:
25+
name: Post next step content
26+
runs-on: ubuntu-latest
27+
needs: [start_exercise]
28+
env:
29+
ISSUE_URL: ${{ needs.start_exercise.outputs.issue-url }}
30+
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
35+
- name: Get response templates
36+
uses: actions/checkout@v4
37+
with:
38+
repository: skills/exercise-toolkit
39+
path: exercise-toolkit
40+
ref: v0.6.0
41+
42+
- name: Build comment - add step content
43+
id: build-comment
44+
uses: skills/action-text-variables@v2
45+
with:
46+
template-file: ${{ env.STEP_1_FILE }}
47+
template-vars: |
48+
login: ${{ github.actor }}
49+
full_repo_name: ${{ github.repository }}
50+
51+
- name: Create comment - add step content
52+
run: |
53+
gh issue comment "$ISSUE_URL" \
54+
--body "$ISSUE_BODY"
55+
env:
56+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
ISSUE_BODY: ${{ steps.build-comment.outputs.updated-text }}
58+
59+
- name: Create comment - watching for progress
60+
run: |
61+
gh issue comment "$ISSUE_URL" \
62+
--body-file "exercise-toolkit/markdown-templates/step-feedback/watching-for-progress.md"
63+
env:
64+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
66+
- name: Enable next step workflow
67+
run: |
68+
gh workflow enable "Step 1"
69+
env:
70+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)