-
Notifications
You must be signed in to change notification settings - Fork 3
80 lines (69 loc) · 2.82 KB
/
lint.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Lint
on:
push:
branches:
- main
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
name: Run pre-commit & flake8
runs-on: ubuntu-latest
env:
# Configure pip to cache dependencies and do a user install
PIP_NO_CACHE_DIR: false
PIP_USER: 1
# Make sure package manager does not use virtualenv
POETRY_VIRTUALENVS_CREATE: false
# Specify explicit paths for python dependencies and the pre-commit
# environment so we know which directories to cache
POETRY_CACHE_DIR: ${{ github.workspace }}/.cache/py-user-base
PYTHONUSERBASE: ${{ github.workspace }}/.cache/py-user-base
PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit-cache
steps:
- name: Add custom PYTHONUSERBASE to PATH
run: echo '${{ env.PYTHONUSERBASE }}/bin/' >> $GITHUB_PATH
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup python
id: python
uses: actions/setup-python@v2
with:
python-version: '3.9.5'
# This step caches our Python dependencies. To make sure we
# only restore a cache when the dependencies, the python version,
# the runner operating system, and the dependency location haven't
# changed, we create a cache key that is a composite of those states.
#
# Only when the context is exactly the same, we will restore the cache.
- name: Python Dependency Caching
uses: actions/cache@v2
id: python_cache
with:
path: ${{ env.PYTHONUSERBASE }}
key: "python-0-${{ runner.os }}-${{ env.PYTHONUSERBASE }}-\
${{ steps.python.outputs.python-version }}-\
${{ hashFiles('./pyproject.toml', './poetry.lock') }}"
# Install our dependencies if we did not restore a dependency cache
- name: Install dependencies using Poetry
if: steps.python_cache.outputs.cache-hit != 'true'
run: |
pip install poetry
poetry install
# This step caches our pre-commit environment. To make sure we
# do create a new environment when our pre-commit setup changes,
# we create a cache key based on relevant factors.
- name: Pre-commit Environment Caching
uses: actions/cache@v2
with:
path: ${{ env.PRE_COMMIT_HOME }}
key: "precommit-0-${{ runner.os }}-${{ env.PRE_COMMIT_HOME }}-\
${{ steps.python.outputs.python-version }}-\
${{ hashFiles('./.pre-commit-config.yaml') }}"
# We will not run `flake8` here, as we will use a separate flake8
# action. As pre-commit does not support user installs, we set
# PIP_USER=0 to not do a user install.
- name: Run pre-commit hooks
run: export PIP_USER=0; pre-commit run --all-files