Adding Your First Step
00:00 In GitHub Actions, a trigger is an event that causes a GitHub workflow to run. There are many kinds of triggers, for example, when a pull request is created, when you push a commit, or when someone opens a new issue.
00:14 But GitHub offers way more options like tag commits, requests by another workflow, or even manual triggers that don’t run automatically.
00:25 If you’re curious, you can check out the GitHub Actions documentation and look for the events that trigger workflows document. On the screen on the right side, you can see all the events that you can use to trigger workflows.
00:40 To get started, you’ll implement a push trigger for your workflow.
00:44
Hop over to your editor again and open the hello_world.yaml
file. In the first line, write on: push
. This means whenever you push something on any branch, the workflow should run.
00:58 Now, you could commit this change, push it, and see what GitHub makes out of it. But I save you this step and just let you know that GitHub will complain and say that it needs a job to run.
01:09
Because each workflow must have a single job section. So in the next line, write jobs:
, and inside the jobs section, you can define one or more jobs.
01:22
Well, let me be clear here. You must define at least one job, and you must give it a name right away. Here it’s a good idea to be descriptive. For example, say_hello
.
01:34
The say_hello
line needs to end with a colon because you’re opening a new section, and don’t forget to indent the content because similarly to Python, indentation is hugely important in YAML.
01:46 As a rule of thumb, every time a line ends with a colon, you must indent the next line. When you’re creating a job, the first thing to do is to define the runner you want to use to run your job.
01:58 A runner is a GitHub-hosted virtual machine that executes the job for you. GitHub will provision and deprovision the virtual machine, so you don’t have to worry about maintaining any infrastructure for your GitHub Actions.
02:12 You can use Windows, macOS, or Linux as virtual machines, but generally it’s a good idea to use Linux unless you have good reasons to use Windows or macOS.
02:23
To define your runner, add a runs-on
property with the virtual machine. So runs-on:
, and as the virtual machine, use ubuntu-latest
.
02:36
So that way you are telling GitHub to use the latest Ubuntu version. You could be more specific with the Ubuntu version, but since you’re not doing anything Ubuntu-specific, it’s usually okay to just use ubuntu-latest
.
02:50
Then in the next line, this time, in the same indentation level as runs-on
, add steps:
. Steps are the main part of a job. So while jobs are the main part of a workflow’s file, steps are kind of like the main part of a job.
03:09
They are the actions that need to be performed when executing the workflow. So for example, this. After steps:
, indent the line again, add a - run:
and then echo "Hello, World!"
. With the dash at the beginning, you tell YAML that the value of the steps property is a list.
03:31 Later you’ll work with multiple steps, but for now, this one step is okay, and I would say we’re good for now, ready to commit and push the changes.
03:53 And we’ve got a green dot. That means your workflow ran successfully. Let’s have a look at what exactly GitHub did. When you click on the commit message of a workflow, you can see the detail page of it.
04:07
You can see that the workflow belongs to the hello_world.yaml
file, and that you ran a job named say_hello
that was triggered on push.
04:17
If you click the say_hello
box, then you can see the logs of the workflow. You can see how GitHub set up the job, and what operating system was used exactly. In the run run: echo "Hello, World!"
section, you can see your echo command and the “Hello, World!” output below.
04:35 And finally, you can see that the job was completed successfully.
04:40 And if an error occurs while your workflow runs, you can always go into these logs to investigate what went wrong.
04:49 In the next lesson, you will polish your workflow a little bit more.
Become a Member to join the conversation.