You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
-->
8
+
9
+
## Step 1: Create a workflow file
10
+
11
+
_Welcome to "Hello GitHub Actions"! :wave:_
12
+
13
+
**What is _GitHub Actions_?**: GitHub Actions is a flexible way to automate nearly every aspect of your team's software workflow. You can automate testing, continuously deploy, review code, manage issues and pull requests, and much more. The best part, these workflows are stored as code in your repository and easily shared and reused across teams. To learn more, check out these resources:
14
+
15
+
- The GitHub Actions feature page, see [GitHub Actions](https://github.com/features/actions).
16
+
- The "GitHub Actions" user documentation, see [GitHub Actions](https://docs.github.com/actions).
17
+
18
+
**What is a _workflow_?**: A workflow is a configurable automated process that will run one or more jobs. Workflows are defined in special files in the `.github/workflows` directory and they execute based on your chosen event. For this exercise, we'll use a `pull_request` event.
19
+
20
+
- To read more about workflows, jobs, and events, see "[Understanding GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions)".
21
+
- If you want to learn more about the `pull_request` event before using it, see "[pull_request](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request)".
22
+
23
+
To get you started, we used actions to go ahead and made a branch and pull request for you.
24
+
25
+
### :keyboard: Activity: Create a workflow file
26
+
27
+
1. Open a new browser tab, and navigate to this same repository. Then, work on the steps in your second tab while you read the instructions in this tab.
28
+
1. Create a pull request to view all the changes you'll make throughout this course. Click the **Pull Requests** tab, click **New pull request**, set `base: main` and `compare:welcome-workflow`, click **Create pull request**.
29
+
1. Navigate to the **Code** tab.
30
+
1. From the **main** branch dropdown, click on the **welcome-workflow** branch.
31
+
1. Navigate to the `.github/workflows/` folder, then select **Add file** and click on **Create new file**.
32
+
1. In the **Name your file...** field, enter `welcome.yml`.
33
+
1. Add the following content to the `welcome.yml` file:
34
+
```yaml
35
+
name: Post welcome comment
36
+
on:
37
+
pull_request:
38
+
types: [opened]
39
+
permissions:
40
+
pull-requests: write
41
+
```
42
+
1. To commit your changes, click **Commit new file**.
43
+
1. Wait about 20 seconds for actions to run, then refresh this page (the one you're following instructions from) and an action will automatically close this step and open the next one.
Start this step by acknowledging the previous step.
4
+
Define terms and link to docs.github.com.
5
+
Historic note: The previous course had troubleshooting steps for people not using the GitHub UI.
6
+
-->
7
+
8
+
## Step 2: Add a job to your workflow file
9
+
10
+
_Nice work! :tada: You added a workflow file!_
11
+
12
+
Here's what it means:
13
+
14
+
-`name: Post welcome comment` gives your workflow a name. This name appears on any pull request or in the Actions tab of your repository.
15
+
-`on: pull_request: types: [opened]` indicates that your workflow will execute anytime a pull request opens in your repository.
16
+
-`permissions` assigns the workflow permissions to operate on the repository
17
+
-`pull-requests: write` gives the workflow permission to write to pull requests. This is needed to create the welcome comment.
18
+
19
+
Next, we need to specify jobs to run.
20
+
21
+
**What is a _job_?**: A job is a set of steps in a workflow that execute on the same runner (a runner is a server that runs your workflows when triggered). Workflows have jobs, and jobs have steps. Steps are executed in order and are dependent on each other. We'll add steps in the next step of this exercise. To read more about jobs, see "[Jobs](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions#jobs)".
22
+
23
+
In this step of our exercise, we will add a "build" job. We will specify `ubuntu-latest` as the fastest and cheapest job runner available. If you want to read more about why we'll use that runner, see the code explanation for the line `runs-on: ubuntu-latest` in the "[Understanding the workflow file](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions#understanding-the-workflow-file)" article.
24
+
25
+
### :keyboard: Activity: Add a job to your workflow file
26
+
27
+
1. Open your `welcome.yml` file.
28
+
2. Update the contents of the file to:
29
+
```yaml
30
+
name: Post welcome comment
31
+
on:
32
+
pull_request:
33
+
types: [opened]
34
+
permissions:
35
+
pull-requests: write
36
+
jobs:
37
+
build:
38
+
name: Post welcome comment
39
+
runs-on: ubuntu-latest
40
+
```
41
+
3. Click **Start commit** in the top right of the workflow editor.
42
+
4. Type your commit message and commit your changes directly to your branch.
43
+
5. Wait about 20 seconds for actions to run, then refresh this page (the one you're following instructions from) and an action will automatically close this step and open the next one.
Start this step by acknowledging the previous step.
4
+
Define terms and link to docs.github.com.
5
+
-->
6
+
7
+
## Step 3: Add actions to your workflow file
8
+
9
+
_Nice work adding a job to your workflow! :dancer:_
10
+
11
+
Workflows have jobs, and jobs have steps. So now we'll add steps to your workflow.
12
+
13
+
**What are _steps_?**: Actions steps will run during our job in order. Each step is either a shell script that will be executed, or an action that will be run. Each step must pass for the next step to run. Actions steps can be used from within the same repository, from any other public repository, or from a published Docker container image.
14
+
15
+
In our action, we post a comment on the pull request using a [bash](https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29) script and [GitHub CLI](https://cli.github.com/).
16
+
17
+
### :keyboard: Activity: Add Actions steps to your workflow file
18
+
19
+
1. Open your `welcome.yml` file.
20
+
2. Update the contents of the file to:
21
+
```yaml
22
+
name: Post welcome comment
23
+
on:
24
+
pull_request:
25
+
types: [opened]
26
+
permissions:
27
+
pull-requests: write
28
+
jobs:
29
+
build:
30
+
name: Post welcome comment
31
+
runs-on: ubuntu-latest
32
+
steps:
33
+
- run: gh pr comment $PR_URL --body "Welcome to the repository!"
34
+
env:
35
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36
+
PR_URL: ${{ github.event.pull_request.html_url }}
37
+
```
38
+
3. Click **Start commit** in the top right of the workflow editor.
39
+
4. Type your commit message and commit your changes directly to your branch.
40
+
5. Wait about 20 seconds for actions to run, then refresh this page (the one you're following instructions from) and an action will automatically close this step and open the next one.
Start this step by acknowledging the previous step.
4
+
Define terms and link to docs.github.com.
5
+
-->
6
+
7
+
## Step 4: Merge your workflow file
8
+
9
+
_You're now able to write and run an Actions workflow! :sparkles:_
10
+
11
+
Merge your changes so the action will be a part of the `main` branch.
12
+
13
+
### :keyboard: Activity: Merge your workflow file
14
+
15
+
1. In your repo, click on the **Pull requests** tab.
16
+
1. Click on the pull request you created in step 1.
17
+
1. Click **Merge pull request**, then click **Confirm merge**.
18
+
1. Optionally, click **Delete branch** to delete your `welcome-workflow` branch.
19
+
1. Wait about 20 seconds for actions to run, then refresh this page (the one you're following instructions from) and an action will automatically close this step and open the next one.
Start this step by acknowledging the previous step.
4
+
Define terms and link to docs.github.com.
5
+
-->
6
+
7
+
## Step 5: Trigger the workflow
8
+
9
+
_You've now got a fully functioning workflow! :smile:_
10
+
11
+
Your new action will run any time a pull request has been opened.
12
+
13
+
**Seeing your _action_ in action**: The status of your action is shown in a pull request before you merge, look for **All checks have passed** when you try out the steps below. You can also view them from the **Actions** tab in your repository. From there, you will see all the actions that have run, and you can click on each action to view details and access log files.
14
+
15
+

16
+
17
+
### :keyboard: Activity: Trigger the workflow
18
+
19
+
1. Make a new branch named `test-workflow`.
20
+
1. Commit any change to your branch, such as adding an emoji to your README.md file.
21
+
1. Create the pull request on your branch.
22
+
1. See your action run on your pull request.
23
+
1. Wait about 20 seconds for actions to run, then refresh this page (the one you're following instructions from) and an action will automatically close this step and open the next one.
0 commit comments