GitHub Actions : Zero to Hero
Tags: github, git, devops, githubaction
Published: 2022-10-08 05:51:16

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/024if6543dnt9570r12q.png)

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](https://learnxinyminutes.com/docs/yaml/).

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](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-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](https://docs.github.com/en/actions/reference/events-that-trigger-workflows))

{% embed https://gist.github.com/RitikaSingh02/be21fbd04a1b60e0597419083f63ab1a %}

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

4. 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.

{% embed https://gist.github.com/RitikaSingh02/09a5e5f1d70b056df1427d7a9c4dd478 %}


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


![Actions tab](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmvkgngbkwsndhrkswsw.png)

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 😉)
{% youtube https://youtu.be/yQTy24gdzPU %}

You can also reach out to me on [LinkedIn](https://www.linkedin.com/in/ritika-singh02/) , [Twitter](https://twitter.com/Ritika_Singh02) , [GitHub](https://github.com/RitikaSingh02).