Skip to content

Commit 32bad18

Browse files
authored
ci: add pip and poetry caching to CI (#22)
1 parent 0e75094 commit 32bad18

File tree

3 files changed

+73
-21
lines changed

3 files changed

+73
-21
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# https://github.com/psf/black/blob/master/docs/compatible_configs.md
55
max-line-length = 88
66

7+
extend-exclude =
8+
# ignore cache directory for CI
9+
.cache
10+
711
extend-ignore =
812
# ignore E203 because black might reformat it
913
E203,

.github/workflows/ci.yml

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,106 @@
1-
name: Continuous integration
1+
name: "Continuous integration"
22

33
on: [push, pull_request]
44

5+
env:
6+
PIP_CACHE_DIR: ${{ github.workspace }}/.cache/pip
7+
POETRY_CACHE_DIR: ${{ github.workspace }}/.cache/pypoetry
8+
DEFAULT_PYTHON: "3.8"
9+
510
jobs:
611
test:
7-
name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
12+
name: "Test Python ${{ matrix.python-version }} on ${{ matrix.os }}"
813
runs-on: ${{ matrix.os }}
914
strategy:
1015
matrix:
1116
os: [ubuntu-latest, windows-latest, macos-latest]
1217
python-version: ["3.7", "3.8", "3.9"]
1318
steps:
14-
- uses: actions/checkout@v2
15-
- uses: actions/setup-python@v2
19+
- name: "Check out repository"
20+
uses: actions/checkout@v2
21+
22+
- name: "Set up Python"
23+
uses: actions/setup-python@v2
1624
with:
1725
python-version: ${{ matrix.python-version }}
18-
- name: Install dependencies
26+
27+
- name: "Set up dependency cache"
28+
uses: actions/cache@v2
29+
with:
30+
key: deps-${{ secrets.GH_CACHE }}-${{ runner.os }}-python${{ matrix.python-version }}-${{ hashFiles('**/*.lock') }}
31+
path: |
32+
${{ env.PIP_CACHE_DIR }}
33+
${{ env.POETRY_CACHE_DIR }}
34+
35+
- name: "Install dependencies"
1936
run: pip install poetry && poetry install
20-
- name: Run tests
37+
38+
- name: "Run tests"
2139
run: poetry run pytest
2240

2341
check:
24-
name: Lint and type checks
42+
name: "Lint and type checks"
2543
runs-on: ubuntu-latest
2644
steps:
27-
- uses: actions/checkout@v2
28-
- uses: actions/setup-python@v2
45+
- name: "Check out repository"
46+
uses: actions/checkout@v2
47+
48+
- name: "Set up Python"
49+
uses: actions/setup-python@v2
2950
with:
30-
python-version: "3.8"
31-
- name: Install dependencies
51+
python-version: ${{ env.DEFAULT_PYTHON }}
52+
53+
- name: "Set up dependency cache"
54+
uses: actions/cache@v2
55+
with:
56+
key: deps-${{ secrets.GH_CACHE }}-${{ runner.os }}-python${{ env.DEFAULT_PYTHON }}-${{ hashFiles('**/*.lock') }}
57+
path: |
58+
${{ env.PIP_CACHE_DIR }}
59+
${{ env.POETRY_CACHE_DIR }}
60+
61+
- name: "Install dependencies"
3262
run: pip install poetry && poetry install
33-
- name: Format checks
63+
64+
- name: "Check formatting"
3465
run: poetry run black --check .
35-
- name: Lint checks
66+
67+
- name: "Check linter"
3668
run: poetry run flake8
37-
- name: Type checks
69+
70+
- name: "Checks types"
3871
run: poetry run mypy
3972

4073
build:
4174
name: Build assets and deploy on tags
4275
runs-on: ubuntu-latest
4376
needs: [test, check]
4477
steps:
45-
- uses: actions/checkout@v2
46-
- uses: actions/setup-python@v2
78+
- name: "Check out repository"
79+
uses: actions/checkout@v2
80+
81+
- name: "Set up Python"
82+
uses: actions/setup-python@v2
4783
with:
48-
python-version: "3.8"
49-
- name: Install dependencies
84+
python-version: ${{ env.DEFAULT_PYTHON }}
85+
86+
- name: "Set up dependency cache"
87+
uses: actions/cache@v2
88+
with:
89+
key: deps-${{ secrets.GH_CACHE }}-${{ runner.os }}-python${{ env.DEFAULT_PYTHON }}-${{ hashFiles('**/*.lock') }}
90+
path: |
91+
${{ env.PIP_CACHE_DIR }}
92+
${{ env.POETRY_CACHE_DIR }}
93+
94+
- name: "Install dependencies"
5095
run: pip install poetry && poetry install
51-
- name: Build artifacts
96+
97+
- name: "Build artifacts"
5298
run: |
5399
poetry build
54100
poetry run mkdocs build
55-
- if: startsWith(github.ref, 'refs/tags/v')
56-
name: Deploy to PyPI and GitHub Pages
101+
102+
- name: "Deploy to PyPI and GitHub Pages"
103+
if: startsWith(github.ref, 'refs/tags/v')
57104
env:
58105
USER_NAME: ${{ github.actor }}
59106
USER_ID: ${{ github.event.sender.id }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ site
33
*.egg-info
44
.python-version
55
__pycache__
6+
.cache

0 commit comments

Comments
 (0)