|
| 1 | +## Step 1: Setting up the project |
| 2 | + |
| 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… |
| 4 | + |
| 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! |
| 12 | + |
| 13 | +### ⌨️ Activity: Set up your development environment |
| 14 | + |
| 15 | +Let's use **GitHub Codespaces** to set up a cloud-based development environment and work in it for the remainder of the exercise! |
| 16 | + |
| 17 | +1. Right-click the below button to open the **Create Codespace** page in a new tab. Use the default configuration. |
| 18 | + |
| 19 | + [](https://codespaces.new/{{full_repo_name}}?quickstart=1) |
| 20 | + |
| 21 | +1. Confirm the **Repository** field is your copy of the exercise, not the original, then click the green **Create Codespace** button. |
| 22 | + |
| 23 | + - ✅ Your copy: `/{{full_repo_name}}` |
| 24 | + - ❌ Original: `/skills/write-javascript-actions` |
| 25 | + |
| 26 | +1. Wait a moment for Visual Studio Code to load in your browser. |
| 27 | + |
| 28 | +1. Verify that **Node.js** is available by opening a terminal and running: |
| 29 | + |
| 30 | + ```sh |
| 31 | + node --version |
| 32 | + npm --version |
| 33 | + ``` |
| 34 | + |
| 35 | + <details> |
| 36 | + <summary>Having trouble? 🤷</summary><br/> |
| 37 | + |
| 38 | + - Make sure you selected your personal copy of the repository, not the original template. |
| 39 | + - If the Codespace fails to start, try refreshing the page and creating a new one. |
| 40 | + - Node.js and npm should be pre-installed in the development environment. |
| 41 | + |
| 42 | + </details> |
| 43 | + |
| 44 | +### ⌨️ Activity: Initialize Project |
| 45 | + |
| 46 | +Now that your Codespace is ready, let's initialize a new Node.js project and install the dependencies needed for your Dad Jokes action. |
| 47 | + |
| 48 | +1. Within your GitHub Codespace terminal window initialize a new project: |
| 49 | + |
| 50 | + ```sh |
| 51 | + npm init -y |
| 52 | + ``` |
| 53 | + |
| 54 | +1. Install the required dependencies: |
| 55 | + |
| 56 | + ```sh |
| 57 | + npm install request request-promise @actions/core @vercel/ncc |
| 58 | + ``` |
| 59 | + |
| 60 | + > 🪧 **Note:** You will learn each library purpose in the next steps |
| 61 | +
|
| 62 | +1. Review `package.json` to confirm dependencies are listed in the `dependencies` section. |
| 63 | + |
| 64 | +1. Open the `.gitignore` file and add an entry to exclude the `node_modules` directory from being tracked by Git: |
| 65 | + |
| 66 | + ```text |
| 67 | + node_modules/ |
| 68 | + ``` |
| 69 | + |
| 70 | + We don't want to commit `node_modules` because it contains thousands of files that would bloat the repository. |
| 71 | + |
| 72 | + > 🪧 **Note:** Instead, later in the exercise you will bundle your action into a single JavaScript file with all dependencies included. |
| 73 | +
|
| 74 | +1. Commit and push your changes: |
| 75 | + |
| 76 | + ```sh |
| 77 | + git status |
| 78 | + git add . |
| 79 | + git commit -m "Initialize project" |
| 80 | + git push |
| 81 | + ``` |
| 82 | + |
| 83 | +1. With the changes pushed to GitHub, Mona will check your work and share the next steps. |
| 84 | + |
| 85 | +<details> |
| 86 | +<summary>Having trouble? 🤷</summary><br/> |
| 87 | + |
| 88 | +- Ensure you are at the repository root before running `npm init -y`. |
| 89 | +- Do not commit `node_modules/` to the repository; ensure it's listed in `.gitignore`. |
| 90 | + |
| 91 | +</details> |
0 commit comments