?? Day 3: GitHub Actions – Automating Workflows Like a Pro

?? Day 3: GitHub Actions – Automating Workflows Like a Pro

Welcome to Day 3 of the #100DaysOfDevOps & Cloud Challenge!

Today, we’re diving deep into GitHub Actions, a powerful tool that automates your software development workflows.

By the end of this post, you’ll have a clear understanding of GitHub Actions, its real-world applications, and how to set up an automated CI/CD pipeline from scratch!


?? What is GitHub Actions?

GitHub Actions is GitHub’s built-in automation tool that allows you to create, manage, and execute workflows directly within your repositories.

It enables Continuous Integration (CI) and Continuous Deployment (CD) by automating tasks such as building, testing, and deploying code.

?? Why Use GitHub Actions?

? Native to GitHub – No need for external CI/CD tools.

? Event-driven – Triggers workflows based on GitHub events (push, pull requests, etc.).

? Scalability & Customisation – Supports self-hosted and cloud runners for various environments.

? Built-in Marketplace – Thousands of pre-built actions available.


?? Layman’s Example: How GitHub Actions Work?

Imagine you run a pizza delivery shop ??. When a customer places an order:

1?? The chef prepares the pizza (Build Stage).

2?? The quality check ensures it’s well-baked (Test Stage).

3?? The delivery guy takes it to the customer (Deploy Stage).

This is how GitHub Actions works in software development:

? Developers push code → Triggers CI/CD pipeline.

? Code is tested & built → Ensures quality before deployment.

? Deployed to production → Automatically reaches end users.


?? Real-World Use Case: Automating a Deployment Process

Let’s say you work at a fintech startup that frequently updates a loan approval application ??.

Every time developers push new code, it must:

? Run tests to ensure functionality.

? Build and package the application.

? Deploy to a cloud service (AWS/Azure) automatically.

This process ensures that no manual intervention is needed, speeding up releases and minimising errors.


?? Key Components of GitHub Actions

1?? Workflows – The full automation process (.github/workflows/).

2?? Events – Triggers that start the workflow (e.g., push, pull_request).

3?? Jobs – A collection of steps executed in an environment.

4?? Steps – Individual tasks within a job (e.g., running scripts, deploying code).

5?? Actions – Reusable commands/functions (pre-built in GitHub Marketplace).


?? Step-by-Step: Setting Up a GitHub Actions Workflow

Step 1: Create a Simple Node.js Application

Create a new directory, navigate into it, and initialize a Node.js app:

mkdir github-actions-demo && cd github-actions-demo  
npm init -y  
        

Create a file called app.js:

const http = require('http');

const server = http.createServer((req, res) => {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Hello, GitHub Actions!');
});

server.listen(3000, () => {
    console.log('Server running at https://localhost:3000/');
});
        

Create a package.json script to start the app:

"scripts": {
  "start": "node app.js"
}
        

Install dependencies:

npm install
        

Now, push the code to GitHub.


Step 2: Create a GitHub Actions Workflow File

Inside your repo, create a new folder and file:

mkdir -p .github/workflows  
nano .github/workflows/ci-cd-pipeline.yml  
        

Copy and paste the following GitHub Actions workflow:

name: CI/CD Pipeline

on:
  push:
    branches:
      - main  

jobs:
  build:
    runs-on: ubuntu-latest  

    steps:
      - name: Checkout Code
        uses: actions/checkout@v3  

      - name: Set Up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 16  

      - name: Install Dependencies
        run: npm install  

      - name: Run Tests
        run: echo "No tests implemented yet!"  

      - name: Deploy to Server
        run: echo "Deploying the app..."  
        


Step 3: Commit & Push the Code

git add .  
git commit -m "Added GitHub Actions workflow"  
git push origin main  
        

?? Now, every time you push code, the workflow will:

?? Checkout the latest code

?? Install dependencies

?? Run basic tests

?? Deploy the application


?? Advanced GitHub Actions Use Cases

?? Deploy to AWS/Azure – Use GitHub Actions to deploy to EC2, S3, or Azure App Services.

?? Build & Push Docker Images – Automate Docker image deployment to Docker Hub or Azure Container Registry.

?? Kubernetes Deployment – Automate rolling updates for Kubernetes clusters.


?? Summary

GitHub Actions makes CI/CD automation simple and efficient.

Whether you’re working on a personal project or an enterprise application, mastering GitHub Actions will save time, reduce errors, and enhance productivity. ??

?? Coming Next: Day 4 – Jenkins: What is CI/CD? Why Automate Builds? Stay tuned!


?? Follow Shruthi Chikkela for More!

If you're enjoying this 100 Days of DevOps & Cloud Challenge, don’t forget to:

? Like, share & comment if you found this useful!

? Subscribe to my newsletter

?? What’s your experience with GitHub Actions? Share your thoughts in the comments!

#GitHubActions #DevOps #CI/CD #Automation #Azure #Cloud #100DaysOfDevOps #LearnwithShruthi #CareerByteCode #Linkedin??

Naveen Kumar

Technology Lead

1 个月

Very informative

GitHub Actions indeed revolutionizes automation in DevOps workflows. However, ensuring proper security measures within these automated pipelines is crucial. Have you explored incorporating secrets management tools like Vault for enhanced security?

Shruthi Chikkela! Love your deep dive into GitHub Actions. Remember, secure pipelines are key to successful automation! #connections

要查看或添加评论,请登录

Shruthi Chikkela的更多文章

社区洞察