Skip to content

Instantly share code, notes, and snippets.

@alukach
Last active Apr 8, 2022
Embed
What would you like to do?
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
@Hongbo-Miao
Copy link

Hongbo-Miao commented Apr 4, 2021

Thanks for sharing!

@mikemhenry
Copy link

mikemhenry commented Apr 14, 2021

This was really helpful, thanks!

@Sim4n6
Copy link

Sim4n6 commented Jun 7, 2021

Just to mention, you cannot pipenv shell since Github actions does not handle interactive mode.

@blackandred
Copy link

blackandred commented Jan 25, 2022

Thanks

@Qubhis
Copy link

Qubhis commented Feb 14, 2022

This helped me, thank you!

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