Hello World in GitHub Actions: A Beginner's Guide to Your First Workflow
Tags: beginners, devops, github, docker
Published: 2024-02-01 15:36:01

##  What Is a CI/CD Pipeline?

A CI/CD (Continuous Integration/Continuous Deployment) pipeline is a robust automated process that **orchestrates** code changes from **development** to **production**. It streamlines software delivery, ensuring code **integration**, **testing**, and **deployment** in a seamless, efficient manner. These pipelines automate workflows, enhancing collaboration, and enabling rapid, reliable software releases.

We will use **github action** for **CI** and **argocd** for **CD** pipeline.


Lets understand github action **workflow first**.


## How to Set Up A Github Action CI Workflow

1. **Create a `.github/workflows` directory:**
   - In your GitHub repository, create a new directory named `.github/workflows`.

2. **Add a YAML file for your workflow:**
   - Inside the `workflows` directory, create a YAML file (e.g., `main.yml`) to define your CI workflow to trigger events.


## GitHub Actions Workflow Lifecycle

1. **Triggering Event:**
   - The workflow kicks off in response to predefined trigger events, such as pushes, pull requests, or scheduled intervals.

2. **Workflow File Interpretation:**
   - GitHub Actions locates and interprets the workflow file (typically named `.github/workflows/main.yml`) in the repository, extracting instructions for the CI/CD process.

3. **Job Execution:**
   - The workflow file defines one or more jobs, each representing a set of tasks. These jobs can run concurrently or sequentially on the designated runner environment.

4. **Step-by-Step Execution:**
   - Within each job, individual steps are executed sequentially. These steps encompass various actions, commands, or scripts, performing tasks like code checkout, dependency installation, testing, and deployment.

5. **Status Monitoring and Notifications:**
   - GitHub Actions updates the workflow status based on the success or failure of each step. Users can track the workflow's progress in the GitHub Actions dashboard and configure notifications to stay informed about status changes. This lifecycle ensures a streamlined and automated CI/CD pipeline.


I think the **best** way to learn github action through a **project**.

Certainly! Let's set up a basic GitHub Actions workflow for a simple project. Follow these steps:

1. **Create Repository:**
   - Go to GitHub and create a new repository named `github-action-demo`.

2. **Local Setup:**
   - Clone the repository to your local machine:

     ```bash
     git clone https://github.com/your-username/github-action-demo.git
     ```

   - Navigate to the project directory:

     ```bash
     cd github-action-demo
     ```

3. **Create `.github/workflows` Directory:**
   - In your project's root directory, create a new directory named `.github/workflows`:

     ```bash
     mkdir -p .github/workflows
     ```

4. **Add `main.yaml` Workflow File:**
   - Now, let's set up a file named `main.yaml` inside the new `.github/workflows` folder. Copy and paste the following code:

     ```yaml
     name: CI

     on:
       push:
         branches:
           - main

     jobs:
       build:
         runs-on: ubuntu-latest

         steps:
           - name: Get Your Code
             uses: actions/checkout@v2

           - name: Say Hello to the World
             run: echo "Hello, World!"
     ```

   This simple setup is like giving your project a set of instructions. Whenever you make changes and push them to the `main` branch, GitHub will follow these instructions. It will fetch your code, and just to prove it's working, it will print "Hello, World!" Think of it like your project saying hi to the world when changes happen! 🌍✨

5. **Commit and Push Changes:**
   - Commit the changes and push them to GitHub:

     ```bash
     git add .
     git commit -m "Add GitHub Actions workflow"
     git push origin main
     ```

6. **Check GitHub Actions Tab:**
   - Visit your GitHub repository, go to the "Actions" tab, and you should see the CI workflow being triggered.

## Conclusion
GitHub Actions simplifies the process of automating CI/CD pipelines for software development. With easy-to-follow steps, you can set up workflows to handle tasks like code integration, testing, and deployment seamlessly. By embracing GitHub Actions, developers can streamline their workflow and accelerate software delivery with minimal effort. Start leveraging GitHub Actions today to enhance your development process and deliver high-quality software efficiently.🚀🛠️