DEV Community

Cover image for Build CI/CD Pipeline in 10 Mins with GitHub Actions
Sudhir Bahadure
Sudhir Bahadure

Posted on

Build CI/CD Pipeline in 10 Mins with GitHub Actions

Introduction

Did you know that 70% of companies struggle to implement CI/CD pipelines, but you can build one in just 10 minutes with GitHub Actions? In this fast-paced development environment, having a smooth and automated workflow is crucial for efficiency and productivity. By the end of this article, you will have built a fully functional CI/CD pipeline using GitHub Actions, which you can use today to streamline your development process. This matters in 2026 because companies are increasingly looking for ways to optimize their workflows and reduce costs. To get started, you'll need:

  • A GitHub account
  • A basic understanding of YAML
  • A Python project to demonstrate the pipeline
  • GitHub Actions installed on your repository

Table of Contents

  1. Introduction
  2. Step 1 — Create a GitHub Actions Workflow
  3. Step 2 — Configure the Workflow to Run on Push Events
  4. Step 3 — Add a Step to Install Dependencies
  5. Step 4 — Add a Step to Run Tests
  6. Step 5 — Add a Step to Deploy to Production
  7. Real-World Usage
  8. Real-World Application
  9. Conclusion
  10. Your Turn

Step 1 — Create a GitHub Actions Workflow

Creating a new workflow is the first step in building your CI/CD pipeline. This step matters because it sets the foundation for your entire automation process.

name: Python package

on:
  push:
    branches: [ main ]
Enter fullscreen mode Exit fullscreen mode

The expected output will be a new workflow file created in your repository's .github/workflows directory.

Step 2 — Configure the Workflow to Run on Push Events

Configuring your workflow to run on push events ensures that your pipeline is triggered whenever you make changes to your code. This step matters because it automates the testing and deployment process.

on:
  push:
    branches: [ main ]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    ```
{% endraw %}

The expected output will be your workflow configured to run on push events to the main branch.

## Step 3 — Add a Step to Install Dependencies
Adding a step to install dependencies is crucial for ensuring that your pipeline has all the necessary packages to run your code. This step matters because it sets up the environment for your tests to run.
{% raw %}

```yml
steps:
  - name: Checkout code
    uses: actions/checkout@v2
  - name: Set up Python 3.9
    uses: actions/setup-python@v2
    with:
      python-version: '3.9'
  - name: Install dependencies
    run: |
      python -m pip install --upgrade pip
      pip install flake8
Enter fullscreen mode Exit fullscreen mode

The expected output will be your dependencies installed and ready for use.

Step 4 — Add a Step to Run Tests

Adding a step to run tests is vital for ensuring that your code works as expected. This step matters because it catches any bugs or errors in your code.

import unittest

class TestStringMethods(unittest.TestCase):

    def test_upper(self):
        self.assertEqual('foo'.upper(), 'FOO')

    def test_isupper(self):
        self.assertTrue('FOO'.isupper())
        self.assertFalse('Foo'.isupper())

    def test_split(self):
        s = 'hello world'
        self.assertEqual(s.split(), ['hello', 'world'])
        # check that s.split() doesn't return a list of individual characters
        with self.assertRaises(ValueError):
            s.split(5)

if __name__ == '__main__':
    unittest.main()
Enter fullscreen mode Exit fullscreen mode

The expected output will be your tests running successfully.

Step 5 — Add a Step to Deploy to Production

Adding a step to deploy to production is the final step in your CI/CD pipeline. This step matters because it gets your code live and ready for users.

  - name: Deploy to Production
    uses: appleboy/scp-action@master
    with:
      host: ${{ secrets.HOST }}
      username: ${{ secrets.USERNAME }}
      key: ${{ secrets.KEY }}
      source: "./"
      target: "/var/www/html"
Enter fullscreen mode Exit fullscreen mode

The expected output will be your code deployed to production.

Real-World Usage

Now that you've built your CI/CD pipeline, you can use it to automate your development process. For example, you can use it to deploy a Python web application to a cloud server. Here's an example of how you can use the pipeline to deploy a Flask app:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello, World!"

if __name__ == "__main__":
    app.run()
Enter fullscreen mode Exit fullscreen mode

The expected output will be your Flask app live and accessible to users.

Real-World Application

This CI/CD pipeline can be used to solve real-world problems such as automating the deployment of a web application. For instance, you can use Vultr Cloud (Get $100 free credit to host your apps) or DigitalOcean (Get $200 free credit to deploy your code) to host your application. By automating the deployment process, you can save time and reduce errors.

Conclusion

Here are three specific takeaways from this article:

  1. You can build a CI/CD pipeline using GitHub Actions in just 10 minutes.
  2. Automating your development process can save you time and reduce errors.
  3. You can use your pipeline to deploy a web application to a cloud server. What to build next? Try building a pipeline to automate your testing process, and share your experience in the comments below.

💬 Your Turn

Have you automated your deployment process before? What was your approach? Drop it in the comments — I read every one.

💡 Found this helpful?

If this tutorial saved you time or solved a problem, consider:

  • Support me on Ko-fi
  • Support via PayPal

Every coffee or donation keeps me writing free tutorials like this one!


This article was written with AI assistance and reviewed for technical accuracy.
Part of the **Zero-Cost Cloud & DevOps* series — Follow for more free tutorials*

#aBotWroteThis

Top comments (0)