Skip to content

Commit 5210d74

Browse files
Theory updates (#2)
1 parent 16c67a4 commit 5210d74

File tree

8 files changed

+170
-125
lines changed

8 files changed

+170
-125
lines changed

.github/steps/1-step.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
## Step 1: Initializing the Dad Jokes GitHub Action
1+
## Step 1: Setting up the project
22

3-
Imagine you have a repetitive task that you want to automate. You've searched through the [**GitHub Marketplace**](https://github.com/marketplace?type=actions) to see if there are any existing actions that suit your needs, but found nothing - because your task is very specific: **generating DAD JOKES**! 🎭
3+
Imagine you’ve got a repetitive task you’d love to automate. You've searched through the [**GitHub Marketplace**](https://github.com/marketplace?type=actions) for existing actions that might help, you come up empty-handed…
44

5-
Since no pre-built action exists for your quirky automation needs, it's time to roll up your sleeves and create your own
5+
Maybe that’s because your task is a bit _too_ unique 😆
6+
7+
**GENERATING DAD JOKES**! 🎭
8+
9+
<img width="600" alt="dadjoke-mona" src="https://github.com/user-attachments/assets/46b6b931-8d1f-4a01-88f4-4568704039a0" />
10+
11+
Since no pre-built action exists for your quirky automation needs, it's time to roll up your sleeves and create your own!
612

713
### ⌨️ Activity: Set up your development environment
814

.github/steps/2-step.md

Lines changed: 27 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
## Step 2: Create Source Files & Run Locally
22

3-
### 📖 Theory
3+
Nice! Now that we have the project initialized and dependencies installed, it's time to create the source files for your Dad Jokes GitHub Action.
4+
5+
### 📖 Theory: The GitHub Actions Toolkit
6+
7+
The `@actions/core` library is the main library from the [GitHub Actions Toolkit](https://github.com/actions/toolkit), a collection of packages for building JavaScript GitHub Actions. It provides essential methods to interact with the GitHub Actions runtime environment, accept action inputs, and produce outputs for other workflow steps.
8+
9+
> [!TIP]
10+
> The [GitHub Actions Toolkit](https://github.com/actions/toolkit) includes other useful libraries like `@actions/github` for interacting with the GitHub API and `@actions/artifact` for uploading and downloading artifacts.
11+
>
12+
> Visit the [actions/toolkit](https://github.com/actions/toolkit) repository for more.
413
5-
Author the action’s core logic and verify it runs locally before bundling.
614

715
### ⌨️ Activity: Implement the Dad Jokes Action
816

917
Now that your project is initialized and dependencies are installed, it's time to create the source files for your Dad Jokes GitHub Action.
1018

11-
1219
1. Create `src/` directory to hold your GitHub Action JavaScript files:
1320

1421
```sh
@@ -38,28 +45,34 @@ Now that your project is initialized and dependencies are installed, it's time t
3845
module.exports = getJoke;
3946
```
4047

48+
The `getJoke` function makes an HTTP GET request to the `icanhazdadjoke.com` API and returns a random dad joke.
49+
50+
We export the `getJoke` function so it can be used in other files.
51+
4152
1. Create `src/main.js` that will be the main entry point for your action:
4253

43-
```js
44-
const getJoke = require("./joke");
45-
const core = require("@actions/core");
54+
```js
55+
const getJoke = require("./joke");
56+
const core = require("@actions/core");
4657

47-
async function run() {
48-
const joke = await getJoke();
49-
console.log(joke);
50-
core.setOutput("joke-output", joke);
51-
}
58+
async function run() {
59+
const joke = await getJoke();
60+
console.log(joke);
61+
core.setOutput("joke", joke);
62+
}
5263

53-
run();
54-
```
64+
run();
65+
```
66+
67+
We call the `getJoke` function and call the `core.setOutput()` method to set the `joke` output of your GitHub Action.
5568

5669
1. Run the action locally to verify it works:
5770

5871
```sh
5972
node src/main.js
6073
```
6174

62-
<!-- TODO: Add screenshot example -->
75+
<!-- TODO: ADD SCREENSHOT -->
6376

6477
1. Commit and push:
6578

@@ -68,43 +81,3 @@ Now that your project is initialized and dependencies are installed, it's time t
6881
git commit -m "Add Dad Joke action source files"
6982
git push
7083
```
71-
72-
### 🛠 Activity (Optional): Debug your action
73-
74-
>[!NOTE]
75-
> This activity is optional and not required to complete the exercise.
76-
>
77-
> Learning how to debug your action code can be very helpful!
78-
79-
<details>
80-
<summary>Show steps</summary><br/>
81-
82-
1. Install dev dependency:
83-
84-
```sh
85-
npm install -D @github/local-action
86-
```
87-
88-
1. Create `.vscode/launch.json`:
89-
90-
```json
91-
{
92-
"version": "0.2.0",
93-
"configurations": [
94-
{
95-
"name": "Debug Action",
96-
"type": "node",
97-
"request": "launch",
98-
"runtimeExecutable": "npx",
99-
"cwd": "${workspaceRoot}",
100-
"args": ["@github/local-action", ".", "src/main.js"],
101-
"console": "integratedTerminal",
102-
"skipFiles": ["<node_internals>/**", "node_modules/**"]
103-
}
104-
]
105-
}
106-
```
107-
108-
1. Set breakpoints in `src/main.js` and start the "Debug Action" configuration.
109-
110-
</details>

.github/steps/3-step.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
## Step 3: Bundle the Action
22

3-
### 📖 Theory: Bundling the action
3+
Good job! :tada:
44

5+
Now that you've created the source files for your Dad Jokes GitHub Action and tested it locally, it's time to bundle the action so it can be used in GitHub workflows.
6+
7+
### 📖 Theory: Bundling Your Action
8+
9+
When someone uses your action in their workflow, GitHub downloads and executes it as a complete package of code. This means you must include any package dependencies required to run the JavaScript code, such as the `@actions/core` and `request-promise` packages your action uses.
10+
11+
Rather than committing your `node_modules` directory (which causes problems with repository size and performance), you can use bundling tools like `@vercel/ncc` to combine your code and dependencies into a single `dist/index.js` file for distribution.
512

613

714
### ⌨️ Activity: Build Setup & Bundle
815

916
1. Add a build script to `package.json` (inside the existing scripts block or create one):
1017

11-
```json
12-
"scripts": {
13-
"build": "ncc build src/main.js -o dist"
14-
}
15-
16-
```
18+
```json
19+
"scripts": {
20+
"build": "ncc build src/main.js -o dist"
21+
}
22+
```
1723

1824
1. Run the build command. This should create a `dist/` directory with a bundled `index.js` file:
1925

20-
```sh
21-
npm run build
22-
```
26+
```sh
27+
npm run build
28+
```
29+
30+
1. (optional) Run the bundled action to verify it works:
31+
32+
```sh
33+
node dist/index.js
34+
```
2335

2436
1. Commit and push the changes to the `main` branch:
2537

.github/steps/4-step.md

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,61 @@
11
## Step 4: Add Action Metadata
22

3-
### 📖 Theory
3+
Great work! :tada: You've successfully bundled your Dad Jokes GitHub Action into a single file.
44

5-
Define the action’s interface (name, description, outputs, runtime, main entry) via `action.yml` pointing to the bundled file.
5+
Now it's time to create the **action metadata file** - this special file tells GitHub exactly how to use your action when someone includes it in their workflow!
6+
7+
### 📖 Theory: Action Metadata
8+
9+
Every GitHub Action requires a metadata file that defines how the action should be executed and what parameters it accepts.
10+
11+
#### Metadata File Requirements
12+
13+
The metadata file has specific requirements:
14+
15+
- **Filename**: Must be `action.yml`
16+
- **Required for**: All actions types - JavaScript, Docker container, and composite actions
17+
- **Format**: Written in YAML syntax
18+
19+
#### Core Metadata Parameters
20+
21+
| Parameter | Description | Required |
22+
| ----------------- | -------------------------------------------------------------- | :------: |
23+
| **`name`** | The name of your action. ||
24+
| **`description`** | A short description of what your action does. ||
25+
| **`author`** | The name of the action's author. ||
26+
| **`inputs`** | Data that the action expects to receive. ||
27+
| **`outputs`** | Data that other actions can use after this action runs. ||
28+
| **`runs`** | Tells GitHub how to execute your action. ||
29+
| **`branding`** | Optional color and icon for your action in GitHub Marketplace. ||
30+
31+
#### JavaScript Action `runs` Configuration
32+
33+
For JavaScript actions, the `runs` section needs:
34+
35+
- **`using`**: Which Node.js version to use
36+
- **`main`**: The main JavaScript file to run
37+
38+
> [!TIP]
39+
> For complete details on all available metadata parameters, optional fields, and advanced configurations, see the official [GitHub Actions metadata syntax documentation](https://docs.github.com/en/actions/reference/workflows-and-actions/metadata-syntax).
40+
41+
---
642

743
### ⌨️ Activity: Create Metadata File
844

945
1. Create `action.yml` at the repository root (same level as `package.json`).
1046

11-
```yaml
12-
name: "Joke Action"
13-
description: "Fetches a random joke and exposes it as an output"
14-
15-
outputs:
16-
joke:
17-
description: "The fetched joke text"
47+
```yaml
48+
name: "Joke Action"
49+
description: "Fetches a random joke and exposes it as an output"
1850

19-
runs:
20-
using: node24
21-
main: dist/index.js
22-
```
51+
outputs:
52+
joke:
53+
description: "The fetched joke text"
2354

55+
runs:
56+
using: node24
57+
main: dist/index.js
58+
```
2459
2560
1. Commit and push:
2661

.github/steps/5-step.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
## Step 5: Create Workflow & Consume Output
22

3-
### 📖 Theory
3+
Well done! :clap: You've created the Dad Jokes GitHub Action and defined its metadata.
44

5-
Use a workflow triggered by `issue_comment` to run the local action and then post the retrieved joke as a comment.
5+
Your action should be ready to use in any GitHub repository now!
66

77
### ⌨️ Activity: Author Workflow
88

9+
Let's see your Dad Jokes action in action by creating a GitHub Actions workflow that uses it!
10+
911
1. Create a new GitHub Actions workflow file with the following name
1012

1113
```txt
@@ -17,10 +19,10 @@ Use a workflow triggered by `issue_comment` to run the local action and then pos
1719
```yaml
1820
name: Joke Action
1921
on:
20-
issue_comment:
21-
types: [created]
22+
issue_comment:
23+
types: [created]
2224

23-
permissions:
25+
permissions:
2426
issues: write
2527
contents: read
2628

@@ -40,6 +42,12 @@ Use a workflow triggered by `issue_comment` to run the local action and then pos
4042
body: {% raw %}${{ steps.get-joke.outputs.joke }}{% endraw %}
4143
```
4244
43-
The workflow will run on every issue comment created event. If the comment starts with `/joke`, it will execute the Dad Jokes action and post the joke as a comment in the same issue.
45+
This workflow triggers when someone comments `/joke` on an issue and responds with a joke!
46+
47+
1. Commit and push the workflow file to the `main` branch:
4448

45-
1. Commit and push the workflow file to the `main`:
49+
```sh
50+
git add .github/workflows/joke-action.yml
51+
git commit -m "Add workflow to test joke action"
52+
git push
53+
```

.github/steps/6-step.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
## Step 6: Trigger & Validate
22

3+
Awesome! :rocket: You've created the Dad Jokes GitHub Action, defined its metadata, and authored a workflow to use it.
34

5+
The only thing left to do is test it out!
46

5-
### ⌨️ Activity: Try out your action!
7+
### ⌨️ Activity: Try out your action
68

7-
1. Create a comment in this issue (or create a new one) with the text `/joke`
8-
1. Monitor the `actions` tab for the "Joke Action" workflow run to complete.
9-
1. After it completes you should see a new comment posted by the bot with the dad joke!
9+
1. Create a comment in this issue (or create a new one) with the text `/joke`
10+
11+
1. Monitor the **Actions** tab for the "Joke Action" workflow run to complete:
12+
- Click on the **Actions** tab in your repository
13+
- Look for a new workflow run titled "Joke Action"
14+
- The run should show a green checkmark when completed successfully
15+
16+
1. Return to the issue and you should see a new comment posted by `github-actions[bot]` containing a random dad joke!
17+
18+
1. Mona will post the review of the exercise once the workflow completes **successfully**!
19+
20+
<details>
21+
<summary>Having trouble? 🤷</summary><br/>
22+
23+
If the workflow doesn't trigger or fails:
24+
- Make sure your comment starts exactly with `/joke`
25+
- Check the Actions tab for error messages
26+
- Verify that your `dist/index.js` file exists and was committed
27+
- If you did any updates to your source code, ensure you re-bundled with `npm run build` and pushed the changes
28+
- Ensure your `action.yml` file is correctly formatted
29+
30+
</details>

.github/steps/x-review.md

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,23 @@
1-
<!--
2-
<<< Author notes: Finish >>>
3-
Review what we learned, ask for feedback, provide next steps.
4-
-->
1+
## Review
52

6-
## Finish
3+
_Congratulations, you've completed this exercise and learned how to write JavaScript GitHub Actions!_
74

8-
<img src=https://octodex.github.com/images/poptocat_v2.png alt=celebrate width=300 align=right>
5+
<img src="https://octodex.github.com/images/jetpacktocat.png" alt="celebrate" width=200 align=right>
96

10-
### Congratulations, you've completed this course!
7+
Here's a recap of your accomplishments:
118

12-
In this course, you've learned a lot about developing custom actions using JavaScript and Actions Toolkit.
13-
14-
## Publishing your actions
15-
16-
Publishing your actions is a great way to help others in your team and across the GitHub community. Although actions do not need to be published to be consumed, by adding them to the marketplace you make them easier to find.
17-
18-
Some notable actions you will find on the marketplace are:
19-
20-
- [Actions for Discord](https://github.com/marketplace/actions/actions-for-discord)
21-
- [GitHub Action for Slack](https://github.com/marketplace/actions/github-action-for-slack)
22-
- [Jekyll action](https://github.com/marketplace/actions/jekyll-action)
23-
- [Run Jest](https://github.com/marketplace/actions/run-jest)
24-
25-
And that just scratches the surface of the 1600+ and counting actions you will find on the marketplace
26-
27-
Follow [this guide](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/publishing-actions-in-github-marketplace#publishing-an-action) to learn how to publish your actions to the GitHub Marketplace
9+
- **Initialized a Node.js project** with proper dependencies and excluded `node_modules` with a `.gitignore` configuration
10+
- **Created JavaScript source files** implementing a Dad Jokes action and leveraged the `@actions/core` library to handle action outputs
11+
- **Bundled your action** into a single distributable `dist/index.js` file
12+
- **Created action metadata** (`action.yml`) defining name, description, outputs, and execution parameters
13+
- **Authored a GitHub Actions workflow** that uses your custom action
14+
- **Tested your action** by triggering it with issue comments and validating the output
2815

2916
### What's next?
3017

31-
- [Take another GitHub Skills course](https://github.com/skills).
32-
- We'd love to hear what you thought of this course in our [discussion board](https://github.com/orgs/skills/discussions/categories/write-javascript-actions).
33-
- [Read the GitHub Getting Started docs](https://docs.github.com/en/get-started).
34-
- To find projects to contribute to, check out [GitHub Explore](https://github.com/explore).
18+
- Check out the other [GitHub Skills exercises](https://learn.github.com/skills).
19+
- Try using your Dad Jokes action in your other repositories to add some humor to your workflows!
20+
21+
- **Create your next action** using GitHub's template repositories with best practices like tests and linting already built-in:
22+
- [actions/javascript-action](https://github.com/actions/javascript-action) template repository
23+
- [actions/typescript-action](https://github.com/actions/typescript-action) template repository

0 commit comments

Comments
 (0)