aboutsummaryrefslogtreecommitdiffstats
path: root/azure-pipelines.yml
diff options
context:
space:
mode:
Diffstat (limited to 'azure-pipelines.yml')
-rw-r--r--azure-pipelines.yml26
1 files changed, 24 insertions, 2 deletions
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 0331e67f..f273dad3 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -8,10 +8,12 @@ jobs:
variables:
PIP_CACHE_DIR: .cache/pip
+ PRE_COMMIT_HOME: $(Pipeline.Workspace)/pre-commit-cache
steps:
- task: UsePythonVersion@0
displayName: 'Set Python Version'
+ name: PythonVersion
inputs:
versionSpec: '3.7.x'
addToPath: true
@@ -31,8 +33,28 @@ jobs:
pip install flake8-formatter-junit-xml
displayName: 'Install Project Environment'
- - script: flake8 --format junit-xml --output-file TEST-lint.xml
- displayName: 'Run Linter'
+ # Create an executable shell script which replaces the original pipenv binary.
+ # The shell script ignores the first argument and executes the rest of the args as a command.
+ # It makes the `pipenv run flake8` command in the pre-commit hook work by circumventing
+ # pipenv entirely, which is too dumb to know it should use the system interpreter rather than
+ # creating a new venv.
+ - script: |
+ printf '%s\n%s' '#!/bin/bash' '"${@:2}"' > $(PythonVersion.pythonLocation)/bin/pipenv \
+ && chmod +x $(PythonVersion.pythonLocation)/bin/pipenv
+ displayName: 'Mock pipenv binary'
+
+ - task: Cache@2
+ displayName: 'Restore pre-commit environment'
+ inputs:
+ key: pre-commit | "$(PythonVersion.pythonLocation)" | .pre-commit-config.yaml
+ restoreKeys: |
+ pre-commit | "$(PythonVersion.pythonLocation)"
+ path: $(PRE_COMMIT_HOME)
+
+ # flake8 runs so it can generate the XML output. pre-commit will run it again to show stdout.
+ # flake8 standalone runs first to avoid any fixes pre-commit hooks may make.
+ - script: flake8 --format junit-xml --output-file TEST-lint.xml; pre-commit run --all-files
+ displayName: 'Run pre-commit hooks'
- script: |
python3 manage.py makemigrations --check