⚙️ Week 6: CI/CD + DevOps Lifecycle

Day 3: GitHub Actions Deep Dive

⏱ Duration: 5 Hours

📚 Learning Objectives

  • Understand GitHub Actions workflow syntax
  • Create workflows with jobs and steps
  • Use secrets and environment variables
  • Work with artifacts and caching

📖 Core Concepts

Workflow File Structure

# .github/workflows/ci.yml name: CI Pipeline on: push: branches: [main] pull_request: branches: [main] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.11' - name: Install dependencies run: | pip install -r requirements.txt - name: Run tests run: | pytest tests/

Using Secrets

# Set secrets in: Settings → Secrets → Actions # Use in workflow: - name: Deploy env: AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }} run: ./deploy.sh

Matrix Builds

jobs: test: runs-on: ubuntu-latest strategy: matrix: python-version: ['3.9', '3.10', '3.11'] steps: - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }}

🔬 Hands-on Lab

Create CI Workflow

  • Create .github/workflows/ci.yml
  • Add build and test steps
  • Test with a pull request