Complete Beginner's Guide to CI/CD Pipelines in GitHub Actions
Hello Friends, Welcome at way2testing.com, in this tutorial we will learn about pipe lines, how to create them , execute them from very basics
In modern software engineering and QA automation, manual code building and testing are things of the past. Continuous Integration and Continuous Deployment (CI/CD) ensures that every line of code committed to a repository is automatically built, tested, and prepped for release.
In this guide, we will break down what a GitHub CI/CD pipeline is, how to set one up, how to trigger runs, and how to schedule automated tests automatically using GitHub Actions.
1. What is a CI/CD Pipeline in GitHub?
GitHub provides built-in CI/CD capabilities directly inside your repository through GitHub Actions. Instead of needing external tools like Jenkins or Travis CI, you can write automation scripts right alongside your code using YAML syntax.
- Workflow: An automated process configured using a
.ymlfile placed in.github/workflows/. - Event / Trigger: Specific activities (like a
push,pull_request, orschedule) that kick off the workflow. - Job: A series of steps that run on a fresh virtual machine (Runner).
- Step: An individual task executed inside a job (e.g., checking out code, running
npm test). - Runner: The cloud server (Ubuntu, Windows, or macOS) provided by GitHub to execute your workflow.
2. How to Set Up Your First CI/CD Pipeline
Setting up a pipeline takes less than two minutes:
- In your GitHub repository, create the following directory path:
.github/workflows/ - Create a new file named
ci-pipeline.ymlinside that folder. - Paste the following simple workflow configuration into the file:
name: Way2Testing Smoke Tests
# Trigger the workflow on pushes to the main branch
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
# Step 1: Fetch repo code
- name: Checkout Repository
uses: actions/checkout@v4
# Step 2: Set up Node.js environment
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
# Step 3: Install Dependencies
- name: Install Dependencies
run: npm ci
# Step 4: Run Automated Tests
- name: Run Test Suite
run: npm test
3. How to Run the Pipeline
GitHub Actions offers three primary ways to run your pipelines:
A. Automatic Trigger (Code Commit or PR)
Whenever a developer or QA engineer pushes code or opens a Pull Request against the main branch, GitHub automatically detects the event and runs the workflow.
B. Manual Trigger (On-Demand Run)
To run a pipeline manually from the GitHub UI whenever you choose, add workflow_dispatch: under the on: trigger block in your YAML file:
on:
workflow_dispatch: # Enables the 'Run workflow' button in GitHub UI
push:
branches: [ "main" ]
Steps to run manually:
- Go to your GitHub repository in your web browser.
- Click on the Actions tab at the top.
- Select your workflow name on the left sidebar.
- Click the Run workflow dropdown button on the right side and hit Run workflow.
4. How to Schedule a CI/CD Pipeline (Cron Jobs)
For automated nightly builds, regression suites, or health checks, you can schedule your pipeline to run automatically at specific times using standard POSIX Cron syntax.
on:
schedule:
# Runs at 02:00 AM UTC every single day
- cron: '0 2 * * *'
| Cron Expression | Description |
|---|---|
0 0 * * * |
Every day at midnight (UTC) |
0 9 * * 1-5 |
Monday through Friday at 9:00 AM (UTC) |
*/30 * * * * |
Every 30 minutes |
5. Best Practices for QA Engineers & Developers
- Fail Fast: Put faster linting and unit tests early in the job, and heavy Selenium/Playwright integration tests later.
- Use Matrix Strategy: Run your tests across multiple browsers or OS versions concurrently using
strategy: matrix. - Store Artifacts: Save test reports, screenshots, or logs using
actions/upload-artifact@v4when tests fail. - Protect Secrets: Never hardcode API keys or passwords in the YAML file. Store them in Settings > Secrets and variables > Actions and reference them via
${{ secrets.API_KEY }}.
No comments:
Post a Comment