Skip to content

Commit

Permalink
ci: add pip and poetry caching to CI (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous authored May 30, 2021
1 parent 0e75094 commit 32bad18
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# https://github.com/psf/black/blob/master/docs/compatible_configs.md
max-line-length = 88

extend-exclude =
# ignore cache directory for CI
.cache

extend-ignore =
# ignore E203 because black might reformat it
E203,
Expand Down
89 changes: 68 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,106 @@
name: Continuous integration
name: "Continuous integration"

on: [push, pull_request]

env:
PIP_CACHE_DIR: ${{ github.workspace }}/.cache/pip
POETRY_CACHE_DIR: ${{ github.workspace }}/.cache/pypoetry
DEFAULT_PYTHON: "3.8"

jobs:
test:
name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
name: "Test Python ${{ matrix.python-version }} on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.7", "3.8", "3.9"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: "Check out repository"
uses: actions/checkout@v2

- name: "Set up Python"
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies

- name: "Set up dependency cache"
uses: actions/cache@v2
with:
key: deps-${{ secrets.GH_CACHE }}-${{ runner.os }}-python${{ matrix.python-version }}-${{ hashFiles('**/*.lock') }}
path: |
${{ env.PIP_CACHE_DIR }}
${{ env.POETRY_CACHE_DIR }}
- name: "Install dependencies"
run: pip install poetry && poetry install
- name: Run tests

- name: "Run tests"
run: poetry run pytest

check:
name: Lint and type checks
name: "Lint and type checks"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: "Check out repository"
uses: actions/checkout@v2

- name: "Set up Python"
uses: actions/setup-python@v2
with:
python-version: "3.8"
- name: Install dependencies
python-version: ${{ env.DEFAULT_PYTHON }}

- name: "Set up dependency cache"
uses: actions/cache@v2
with:
key: deps-${{ secrets.GH_CACHE }}-${{ runner.os }}-python${{ env.DEFAULT_PYTHON }}-${{ hashFiles('**/*.lock') }}
path: |
${{ env.PIP_CACHE_DIR }}
${{ env.POETRY_CACHE_DIR }}
- name: "Install dependencies"
run: pip install poetry && poetry install
- name: Format checks

- name: "Check formatting"
run: poetry run black --check .
- name: Lint checks

- name: "Check linter"
run: poetry run flake8
- name: Type checks

- name: "Checks types"
run: poetry run mypy

build:
name: Build assets and deploy on tags
runs-on: ubuntu-latest
needs: [test, check]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: "Check out repository"
uses: actions/checkout@v2

- name: "Set up Python"
uses: actions/setup-python@v2
with:
python-version: "3.8"
- name: Install dependencies
python-version: ${{ env.DEFAULT_PYTHON }}

- name: "Set up dependency cache"
uses: actions/cache@v2
with:
key: deps-${{ secrets.GH_CACHE }}-${{ runner.os }}-python${{ env.DEFAULT_PYTHON }}-${{ hashFiles('**/*.lock') }}
path: |
${{ env.PIP_CACHE_DIR }}
${{ env.POETRY_CACHE_DIR }}
- name: "Install dependencies"
run: pip install poetry && poetry install
- name: Build artifacts

- name: "Build artifacts"
run: |
poetry build
poetry run mkdocs build
- if: startsWith(github.ref, 'refs/tags/v')
name: Deploy to PyPI and GitHub Pages
- name: "Deploy to PyPI and GitHub Pages"
if: startsWith(github.ref, 'refs/tags/v')
env:
USER_NAME: ${{ github.actor }}
USER_ID: ${{ github.event.sender.id }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ site
*.egg-info
.python-version
__pycache__
.cache

0 comments on commit 32bad18

Please sign in to comment.