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
- Create basic CI workflow
- Add test and lint steps
- Set up matrix builds
- Deploy to cloud service
- Use secrets in workflows