GitHub Actions CI/CD Pipeline Tutorial for Beginners

Written by

in

GitHub Actions CI/CD Pipeline Tutorial for Beginners

TL;DR: Create a YAML file in the .github/workflows directory to define your build and test steps. Commit this file to your repository to automatically trigger continuous integration and deployment upon every code push.

Why Use GitHub Actions?

GitHub Actions simplifies the software development lifecycle by integrating directly with your code repository. It allows you to automate repetitive tasks such as running unit tests, building artifacts, and deploying to staging or production environments. For beginners, the biggest advantage is that it requires no external infrastructure setup; everything runs on GitHub’s hosted runners, making it an ideal starting point for learning CI/CD concepts.

If you want to dig deeper, check out our guide on **Digital Twins: Real-Time Supply Chain Resilience** (47 cha.

Step 1: Initialize Your Project

Before creating a pipeline, ensure your project has a basic structure. You need a source code folder and a way to verify that your code works. For this tutorial, assume you have a simple Python application with a main.py file and a requirements.txt file listing your dependencies. If you are using a different language, the logic remains the same, but the specific commands will change.

Step 2: Create the Workflow Directory

Navigate to the root of your repository and create a new folder named .github. Inside this folder, create another subfolder named workflows. This specific directory structure is mandatory for GitHub to recognize your automation files. If you are working in a visual code editor, you can create these folders manually or via the terminal using mkdir -p .github/workflows.

Step 3: Define Your Workflow File

Create a new file inside the workflows directory. Name it something descriptive, like ci-pipeline.yml. The file must use YAML syntax, so pay close attention to indentation. Here is a basic template to start with:


name: My First CI/CD Pipeline
on: [push]
jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.9'
      - name: Install Dependencies
        run: pip install -r requirements.txt
      - name: Run Tests
        run: python -m unittest

Step 4: Understand the Components

The name field displays in the GitHub interface. The on key triggers the workflow; [push] means it runs every time code is pushed to any branch. The jobs section defines the tasks. Each job requires a runs-on property, specifying the virtual machine type, such as ubuntu-latest. The steps array lists the individual commands executed in sequence. The actions/checkout@v4 step downloads your code, while actions/setup-python@v5 installs the

Related Articles

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *