Setting Up a CI/CD Pipeline with GitHub Actions: A Practical Tutorial
GitHub Actions provides a powerful, integrated way to automate your software delivery pipeline directly from your repository. In this tutorial, you’ll learn how to create a simple CI/CD workflow that builds, tests, and deploys your code automatically on every push.
Before you start, ensure you have a GitHub repository with your source code and a basic understanding of YAML syntax. You’ll also need a deployment target (e.g., a cloud server) and its credentials stored as repository secrets.

1. Create the Workflow Directory and File
Inside your repository root, create a folder named .github/workflows. Then add a new YAML file, for example main.yml. This file defines the entire pipeline.
Example Workflow Structure
- Filename:
.github/workflows/deploy.yml - Naming the workflow:
name: Deploy to Production
2. Define Trigger Events
Specify when the workflow should run. Common triggers are push to a specific branch (e.g., main) or pull_request.
on:
push:
branches: [ main ]
3. Add Jobs: Build and Test
Each workflow contains one or more jobs. The first job typically runs on ubuntu-latest and includes checking out code, setting up the environment (e.g., Node.js), installing dependencies, and running tests.
- Checkout:
actions/checkout@v3 - Setup:
actions/setup-node@v3with version - Run:
npm install, thennpm test
4. Add a Deploy Job
Create a second job that depends on the test passing (needs: build). Use SSH, FTP, or cloud CLI to deploy the build artifact. Store sensitive data (host, username, password) as GitHub Secrets.
- name: Deploy via rsync
run: rsync -avz ./dist/ user@server:/path/
Conclusion
With just a few lines of YAML, you’ve automated your entire CI/CD pipeline using GitHub Actions. Start simple, then expand with caching, matrix builds, and multi-environment deployments as your project grows.