DEV Community

Cover image for GitHub Actions : Zero to Hero
RITIKA SINGH
RITIKA SINGH

Posted on

GitHub Actions : Zero to Hero

What Are Github Actions?

GitHub Actions are packaged scripts to automate tasks in a software development workflow in GitHub.

That is all the processes (or GitHub Events) like the creation of a pull request, committing your code, pushing into the production/ any branch, etc can be monitored by GitHub actions, and hence when an event occurs the workflow is triggered.

Github Actions Workflow

A GitHub Actions Workflow is a process that you set up in your repository to automate software development life cycle tasks. It is a configurable automated process made up of one or more jobs.

Each repository has this actions tab in which the defined actions run :

Each repository has this actions tab in which the defined actions run

One must create a YAML file to define the workflow configuration. If you’re new to YAML and want to learn more, see Learn YAML in Y minutes.

GitHub actions are categorized as Container actions and JavaScript actions.

Container actions
As the name suggests in container actions, the environment is part of the action’s code. These actions can only be executed in Linux-based runners that GitHub hosts. Or if one wants to create a Self -hosted runner (read about runners) make sure it uses Linux OS and has Docker installed. Container actions support many different languages for execution.

JavaScript actions
They do not include the environment in the code. This means that one has to specify the environment to execute these actions. They can run in a VM in the cloud or on-premises. They not only support Linux but macOS and Windows environments also.

Let’s Start by Creating A Simple Workflow:

  1. Create a new repository and then create a workflow (say action.yml) in the workflows folder so the final path of your workflow will be like .github/workflows/action.yml

  2. Now, our first job is to add the on and name attribute to our workflow.

name: defines the name of your workflow.
on: defines the event on which the workflow has to be triggered.

There are plenty of Github events that trigger any workflow (read about GitHub events that trigger workflows)

  1. Next essential requirement of a workflow is the job that it has to do (a workflow has to have a minimum of one job!)

  2. One can define multiple jobs for a workflow. Each job has sundry attributes the major are name, runs-on, steps.

name: defines the name of that particular job in a workflow.
runs-on: defines the runner of that job. (runner can be a Github Hosted Runner or a self-hosted Runner)
steps: defines the steps to be taken in that job.

5 . Commit the code, open the Actions tab in your repository and see your actions running!

Actions tab

So here you can see that all your jobs in the action.yml file ran successfully. And our job named custom3 (line 38) ran and gave us a DateTime output!

And Done! Aren’t GitHub Actions cool 😎!

Let me know in the comments if you have any doubts or face issues, hope it helps you. 😀

Do check out my session on Git & GitHub actions : (Jump to 17:17 for the real fun 😉)

You can also reach out to me on LinkedIn , Twitter , GitHub.

Top comments (0)