Lesson 36 of 40
DevOps
Expert
โฑ 35 min
CI/CD โ GitHub Actions & Azure Pipelines
Automate testing, linting, and deployment of Python apps with GitHub Actions, matrix builds, secrets, and Azure Container Apps deployment.
Part 1: What You Will Learn
- Understand continuous integration (CI) and continuous delivery/deployment (CD).
- Run linting and pytest automatically on every push or pull request.
- Create a Python matrix build in GitHub Actions.
- Recognise the equivalent stages in an Azure Pipelines YAML file.
Part 2: GitHub Actions Workflow
name: Python CI
on:
push:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest ruff
- name: Lint
run: ruff check .
- name: Test
run: pytest -qPart 3: Azure Pipelines Equivalent
trigger:
- main
pool:
vmImage: ubuntu-latest
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: "3.13"
- script: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest ruff
displayName: Install dependencies
- script: ruff check .
displayName: Lint
- script: pytest -q
displayName: Run testsPart 4: CI/CD Best Practices
- Keep secrets in the CI platform's secret store, never directly in YAML.
- Make the test stage pass before deployment begins.
- Pin important dependencies and review automated dependency updates.
- Produce deployable artifacts or container images once, then promote the same artifact between environments.
- Protect the production environment with approvals when appropriate.
Part 5: Hands-On Practice
Mini project โ Automated Python Quality Gate. Create a small Python package with two pytest tests. Push it to GitHub, add the workflow above under .github/workflows/python-ci.yml, deliberately introduce a failing test, and observe how the workflow blocks a clean CI result until the bug is fixed.
Part 6: Next Steps
Once the CI workflow is green, continue to Lesson 37 to build real-time applications with streaming and WebSockets.
๐ Want the complete guide with projects?
Get the book โ