Skip to content

Instantly share code, notes, and snippets.

@alukach
Last active July 24, 2024 13:54
Show Gist options
  • Save alukach/6f3a371e9af600e417aca1b36806ad72 to your computer and use it in GitHub Desktop.
Save alukach/6f3a371e9af600e417aca1b36806ad72 to your computer and use it in GitHub Desktop.
An example Github Actions for Python + Pipenv + Postgres + Pyright
# .github/workflows/app.yaml
name: My Python Project
on: push
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
services:
db_service:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
- name: Check out repository code
uses: actions/checkout@v2
# Setup Python (faster than using Python container)
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.7"
- name: Install pipenv
run: |
python -m pip install --upgrade pipenv wheel
- id: cache-pipenv
uses: actions/cache@v1
with:
path: ~/.local/share/virtualenvs
key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
- name: Install dependencies
if: steps.cache-pipenv.outputs.cache-hit != 'true'
run: |
pipenv install --deploy --dev
- name: Run test suite
run: |
pipenv run test -svvv
env:
TEST_DB_HOST: localhost
TEST_DB_NAME: postgres
TEST_DB_PASS: postgres
TEST_DB_PORT: 5432
TEST_DB_USER: postgres
- name: Run linter
run: |
pipenv run lint
- name: Run formatting check
run: |
pipenv run format --check
- name: Setup node.js (for pyright)
uses: actions/setup-node@v1
with:
node-version: "12"
- name: Run type checking
run: |
npm install -g pyright
pipenv run typecheck
@blackandred
Copy link

Thanks

@Qubhis
Copy link

Qubhis commented Feb 14, 2022

This helped me, thank you!

@carkod
Copy link

carkod commented Dec 27, 2022

Any idea how to set it up with coverage?

@csorgod
Copy link

csorgod commented Apr 21, 2023

Nice! Thanks for sharing with us!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment