GitHub basics: What are actions?

I'm a full-stack developer from South Africa πΏπ¦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa πΏπ¦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
In this series we'll cover some basic, but very important topics in Git, GitHub and Open source
Statement: Git is the most powerful tool in modern development. It doesn't matter in what language you develop. If you work on any development, you need Git! Let's have a look at what Git even is and why it's so important. This is a series around Git...
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

Now that we have a broad understanding of what Git is, let's dive deeper into some more specific topics.
IN this article, I'll explain what GitHub actions are and how you can use them.
I choose GitHub as the platform to highlight because I love to use it, and it's the biggest one out there.
Actions are actions that take place on certain activities on GitHub. You can use these actions to automate specific tasks within your development cycle.
These actions can trigger specific events. Some examples might be: After each commit, when a new PR is created, etc.
Let's have a look at the high level overview of a action:
Let's go through these elements as they are pretty essential to understand.
The event is the actual trigger for the workflow. There can be multiple triggers for one action.
Let's say we want to trigger the action when a new push is made to:
on: push
Or run the same action on multiple actions:
on: [push, pull_request]
You can also use a cronjob as an event I use this in my automated deployment process.
on:
schedule:
- cron: '0 4 * * *'
There are many more events that can trigger these actions, including comments, labels, and more.
You can find the complete event list on GitHub.
A job is a list of steps that are run on the same runner. If you have multiple jobs in your action, they will run parallel by default. (You can change this behavior)
We could, for instance, run a lint job, a test job, and a build job.
Jobs also need to run on a specific system. GitHub comes with a complete set of already made runners. They are virtual machines.
For instance, we can run Windows, Ubuntu, or Mac!
Jobs can also have specific names. Let's set up the three jobs we described above.
jobs:
runs-on: ubuntu-latest
lint:
# steps
test:
# steps
build:
# steps
A step is a group of actions inside a specific job. Each item inside a step can share data between them.
An example of a step would be:
jobs:
runs-on: ubuntu-latest
build:
steps:
step-1:
# Actions
Actions are the brains behind the operation. They start to do something.
Let's say we want to add an action that says hello.
jobs:
runs-on: ubuntu-latest
build:
steps:
step-1:
run: echo "Hi there! π"
Let's take the last example and make this into a complete workflow.
The first thing we need to do is set a name for our workflow.
name: Our very first GitHub Action
Then let's determine when our action must run. I want it only to run when we manually tell it to.
on: workflow_dispatch
And the last part is to add jobs and action to it.
jobs:
Testing-Actions:
runs-on: ubuntu-latest
steps:
- name: A action is born
run: |
echo "I'm walking! πΆββοΈ"
echo "Actually, I'm running on ${{ runner.os }} π"
echo "I'm done! My status: ${{ job.status }} π"
Open a new repo on GitHub.
Then click the actions tab on top to add your first action.

Paste the complete workflow as we created above:
name: Our very first GitHub Action
on: workflow_dispatch
jobs:
Testing-Actions:
runs-on: ubuntu-latest
steps:
- name: A action is born
run: |
echo "I'm walking! πΆββοΈ"
echo "Actually, I'm running on ${{ runner.os }} π"
echo "I'm done! My status: ${{ job.status }} π"
To run this workflow, click on the specific workflow and press the "Run workflow" button.

Once it's done, you can open up the workflow and see what went on. You should be able to see the job we defined and the steps it took.

And that's it. We have a working GitHub action. This is a super basic setup, and the possibilities for workflows are endless!
You can view my demo on GitHub as well.
What kind of workflow would you like to see?
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter