Introduction to GitHub Action

ยท

4 min read

Introduction to GitHub Action

Hey Everyone in This Article I am talk about What is GitHub Action what is does and how can you use it in your project how it can save your lot of time

Prerequisite for Learning GitHub Action

Before learning GitHub Actions, it's important to have a foundational understanding

  • Basic of Git and GitHub

  • Basic of YAML Syntax's

  • Basic understand of What is CI CD

  • Basic Workflow Concepts:

  • Docker Basics (Optional)

What is GitHub action? ๐Ÿค”

GitHub Action is an automation Tool developed by GitHub to help the developer. It automates such tasks as deploying and Testing your Code as Developer. Doing this task manual is a waste of time and also a waste of your computer power. whenever new code is pushed to a GitHub repository. This means that whenever you make changes to your code or write new code, GitHub Actions can automatically perform these tasks for you. GitHub Action is automated the CI-CD task for you

GitHub Action are written in YAML file as I say it the prerequisite part it is import that you have basic understanding of YAML what is YAML if you don't know about YAML here is short information about YAML


What is YAML?

YAML is human readable data serialization format. It is commonly used for configuration files and in applications where data is being stored or transmitted. YAML is designed to be easily readable by humans and easily parsed by machines

Here is a basic example of what a YAML file

WHOAMI:
  NAME: NISHIT
  SURNAME: BARIA
  AGE: 20
  ADDRESS:
    CITY: VADODARA
    STATE: GUJARAT
    COUNTRY: INDIA

Component of GitHub Action

So, Let's Talk about Component of GitHub action As of You can see code GitHub action is written in YAML file

Workflows are defined in the .github/workflows directory in a repository, and a repository can have multiple workflows, each of which can perform a different set of tasks. for example, this workflow trigger when code is push on GitHub repository and its print hello world

name: Hello GitHub Actions

on: [push] 
jobs: 
    print-hello-world:
        runs-on: ubuntu-latest
        steps:
            - run: echo "Hello World!"
            - run: echo "Now I can also able to write GitHub Action Code in YMlF"

base on the code now let's talk about component

name

It is an Optional field The name is visible on the action tab on the GitHub Repository if we don't provide name field then its take file name as name

on

It tell the workflow that when the workflow is trigged mean on which event workflow start it is mandatory field because without event workflow is not triggered not it's not work and This example uses the push event, so a workflow run is triggered every time someone pushes a change to the repository or merges a pull request. This is triggered by a push to every branch

jobs

Groups together all the jobs that run in the hello GitHub action workflow

run-on:

runs-on keyword is used to specify the type of virtual environment where the job will run. In your example, runs-on: ubuntu-latest indicates that the job should be executed on the latest version of Ubuntu Linux. GitHub Actions supports various runners including different versions of Ubuntu, Windows, and macOS. Choosing the right runner depends on the requirements of your job, such as the operating system needed for your tools, dependencies, and scripts.

steps:

In a GitHub Actions workflow, steps are the individual tasks that run sequentially within a job. Each step in a job executes in the same runner, allowing them to share data with each other.

runs:

The run keyword tells the job to execute a command on the runner. In this case, I am using run: echo "Hello world" which is bash command that print the hello world on the terminal

Here you can see in Graphical representation of Workflow how it works

Next steps

GitHub Actions can help you automate nearly every aspect of your application development processes. I hope you understand what GitHub Action is Here are some helpful resources for taking your next steps with GitHub Actions:

Conclusion

GitHub Actions automates tasks like code deployment and testing, saving time for developers. Using YAML files, it facilitates Continuous Integration and Continuous Deployment (CI/CD) triggered by events such as code pushes. Prerequisites include knowledge of YAML syntax, workflow concepts, and optional Docker basics, with key components like 'name,' 'on,' 'jobs,' and 'runs-on' defining automation workflows.

ย