Hands-on Lab

#Lab: CI/CD Pipeline

Build a complete CI/CD pipeline with GitHub Actions.

#🎯 Objectives

  • Create workflow file
  • Configure build and test
  • Set up deployment

#Task 1: Create Workflow

Create .github/workflows/ci.yml:

yaml
1name: CI/CD
2
3on:
4  push:
5    branches: [main]
6  pull_request:
7    branches: [main]
8
9jobs:
10  build:
11    runs-on: ubuntu-latest
12    steps:
13      - uses: actions/checkout@v4
14
15      - name: Setup Node
16        uses: actions/setup-node@v4
17        with:
18          node-version: '20'
19
20      - run: npm ci
21      - run: npm test
22      - run: npm run build
23
24      - name: Upload artifact
25        uses: actions/upload-artifact@v4
26        with:
27          name: dist
28          path: dist/

#Task 2: Add Deployment

yaml
1  deploy:
2    needs: build
3    runs-on: ubuntu-latest
4    if: github.ref == 'refs/heads/main'
5    steps:
6      - name: Download artifact
7        uses: actions/download-artifact@v4
8        with:
9          name: dist
10
11      - name: Deploy
12        run: echo "Deploying..."

#✅ Success Criteria

  • Workflow runs on push
  • Tests pass
  • Deployment triggers on main