|
8 | 8 |
|
9 | 9 | variables:
|
10 | 10 | PIP_CACHE_DIR: .cache/pip
|
| 11 | + PRE_COMMIT_HOME: $(Pipeline.Workspace)/pre-commit-cache |
11 | 12 |
|
12 | 13 | steps:
|
13 | 14 | - task: UsePythonVersion@0
|
14 | 15 | displayName: 'Set Python Version'
|
| 16 | + name: PythonVersion |
15 | 17 | inputs:
|
16 | 18 | versionSpec: '3.7.x'
|
17 | 19 | addToPath: true
|
|
31 | 33 | pip install flake8-formatter-junit-xml
|
32 | 34 | displayName: 'Install Project Environment'
|
33 | 35 |
|
34 |
| - - script: flake8 --format junit-xml --output-file TEST-lint.xml |
35 |
| - displayName: 'Run Linter' |
| 36 | + # Create an executable shell script which replaces the original pipenv binary. |
| 37 | + # The shell script ignores the first argument and executes the rest of the args as a command. |
| 38 | + # It makes the `pipenv run flake8` command in the pre-commit hook work by circumventing |
| 39 | + # pipenv entirely, which is too dumb to know it should use the system interpreter rather than |
| 40 | + # creating a new venv. |
| 41 | + - script: | |
| 42 | + printf '%s\n%s' '#!/bin/bash' '"${@:2}"' > $(PythonVersion.pythonLocation)/bin/pipenv \ |
| 43 | + && chmod +x $(PythonVersion.pythonLocation)/bin/pipenv |
| 44 | + displayName: 'Mock pipenv binary' |
| 45 | +
|
| 46 | + - task: Cache@2 |
| 47 | + displayName: 'Restore pre-commit environment' |
| 48 | + inputs: |
| 49 | + key: pre-commit | "$(PythonVersion.pythonLocation)" | .pre-commit-config.yaml |
| 50 | + restoreKeys: | |
| 51 | + pre-commit | "$(PythonVersion.pythonLocation)" |
| 52 | + path: $(PRE_COMMIT_HOME) |
| 53 | + |
| 54 | + # flake8 runs so it can generate the XML output. pre-commit will run it again to show stdout. |
| 55 | + # flake8 standalone runs first to avoid any fixes pre-commit hooks may make. |
| 56 | + - script: flake8 --format junit-xml --output-file TEST-lint.xml; pre-commit run --all-files |
| 57 | + displayName: 'Run pre-commit hooks' |
36 | 58 |
|
37 | 59 | - script: |
|
38 | 60 | python3 manage.py makemigrations --check
|
|
0 commit comments