Automating Tests with GitHub Actions
flowchart TD
A["git push / pull request"] --> B["GitHub Actions starts a fresh runner"]
B --> C["checkout at that commit"]
C --> D["set up Python"]
D --> E["install from requirements.txt"]
E --> F{"install succeeded?"}
F -->|no| G["fail -- a dependency was never pinned"]
F -->|yes| H["lint / type check"]
H --> I["pytest"]
I --> J{"all green?"}
J -->|no| K["the PR is marked failing"]
J -->|yes| L["merge is allowed"]
C -.->|"clean machine"| M["catches 'works on my laptop'"]
What GitHub Actions is
Section titled “What GitHub Actions is”GitHub Actions runs workflows on:
- push
- pull_request
- schedules
Minimal Python test workflow
Section titled “Minimal Python test workflow”Create .github/workflows/tests.yml:
name: tests
on:
pull_request:
push:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: |
pytest -q- cache pip if workflows are slow
- upload coverage/html reports as artifacts
- run lint/type checks as separate jobs
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading