Day 10: My first GitHub action

ByteMotiveByteMotive
4 min read

Hello Developers, welcome to the day 10 of 90Days of DevOps challenge where we are going to learn DevOps by following this challenge. So yesterday I explored a completely new topic for me that was GitHub action. And I was amazed to know that how easy it is to automate repetitive tasks just by using GitHub actions. Let me tell you how I learned it - It took my whole Saturday just to explore things and learn it by LinkedIn course which was Practical GitHub Actions by Ray Villalobos. And project is still in process, and I will definitely share it to you once it got completely deployed. So, let’s get started on this amazing journey and explore the world of GitHub Action.

What is GitHub Action and why it is important?

GitHub Action is a powerful automation tool which is helps you to automate your repetitive tasks like testing, building and deploying your code. Let’s understand it with a very simple example let say you have a GitHub repo, and many developers are working on that same project and now you want to run a script “Hello, GitHub Action” every time when someone push to the main branch. But is it possible manually to echo this message every time? No, it might be possible for small projects but not for a large one so here comes the GitHub Action which will help you in automating this task. We will discuss later how does this work but for now we will understand why it is important. Have you heard about pipelines (no I am not talking about water pipeline😂) it’s CI/CD pipeline that is it but inside your repository. Whether it’s Continuous Integration or Continuous Deployment, GitHub Actions helps you build a full CI/CD pipeline with ease — no extra tools needed.

How does GitHub Action works?

Here we will know how GitHub action really works is it that simple to automate tasks? Ok so one of the first thing in GitHub action is workflows, which are defined in YAML files which is defined by .yml inside your repository. We can run these workflows based on push, pull or even a scheduled time. So workflow is an automated process defined in .yml file which is located in your .github/workflows/. Here you will often listen some words let me explain that one by one

(i) Event: This is what triggers the workflow. Common events are:

  • push

  • pull_request

  • issue_comment

  • schedule (cron jobs)

    (ii)Job:
    A job is a group of steps that run on the same machine (called a runner). Each job runs in a fresh environment.

    (iii)Step
    A step is a single task — like running a command or script — within a job. Steps are executed in order.

    Now let’s move ahead with creating our first GitHub action.

Creating My first GitHub Action:

we will start by creating a simple .yml file in our repo. This would look something like this in your repository .github/workflows/main.yml

In second step we will write the workflow (hello- world.yml)
Here a simple example:Here’s a simple example:

yamlCopy codename: Hello World Workflow

on: [push]

jobs:
  say-hello:
    runs-on: ubuntu-latest
    steps:
      - name: Print greeting
        run: echo "Hello, world! This is my first GitHub Action "

Here it should look like this in next step we will push it into GitHub by using commands git add.
git commit -m "Added first GitHub Action"
git push
and that’s it! It was this simple and now you can check in your action tab and see your workflow running live. Here we have took a very simple example as you and me are completely beginner, but we can also automate complex workflows with multiple jobs. But we will try it later on when we got enough understanding about this.

Resources which helped me …

I want to share some resources which I found helpful, and which helped me understand and implement GitHub Action. You can trust on me as whether you're a beginner or someone polishing your DevOps skills, these links are gold!

GitHub Actions documentation - GitHub Docs
This is the official documentation and complete guide directly from GitHub which is truly amazing.

Creating a Marketplace GitHub action | LinkedIn Learning
This is one of the resources which I followed, and it is available on LinkedIn learning website. You can go through this amazing course you will not only gain knowledge you will also get a free certificate after attending this session.

There are numbers of resources available on YouTube which you may consider boosting your knowledge.

Conclusion:

Before concluding this, I would only say that it is a game-changer when it comes to automation in development. You can just deploy it directly from your GitHub repository doesn’t matter you are deploying applications, running test, or automating task. You can just try it by deploying a very simple project but later on once you get master it you would be able to deploy complex tasks also. It is helpful in both situations If you're just starting your DevOps journey like me, exploring GitHub Actions is a perfect step toward understanding real-world automation or you are an experienced developer. Comment down if I miss anything I would love to work on it, and we’ll meet in next blog. Thanks for reading.

0
Subscribe to my newsletter

Read articles from ByteMotive directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

ByteMotive
ByteMotive