CI/CD with GitHub Actions

DevOpsCI/CDFree Lesson

Advertisement

Introduction

Automate workflows with GitHub Actions for continuous integration and deployment.

Basic Workflow

# .github/workflows/ci.yml
name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@v3
      
      - 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

Multi-Job Workflow

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Run tests
        run: pytest --junitxml=report.xml
      - uses: actions/upload-artifact@v3
        with:
          name: test-results
          path: report.xml
  
  deploy:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Deploy
        run: ./deploy.sh

Practice Problems

  1. Create basic CI workflow
  2. Add test and lint steps
  3. Set up matrix builds
  4. Deploy to cloud service
  5. Use secrets in workflows

Advertisement

Need Expert Python Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement