Last active
September 6, 2024 20:08
-
-
Save NodeJSmith/ba2cb8e931cb65aa84cc41b3a2fd6008 to your computer and use it in GitHub Desktop.
Cache pre-commit, both pre-commit and virtualenv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- job: precommit | |
pool: | |
vmImage: ubuntu-latest | |
variables: | |
PYTHON_VERSION: 3.11 | |
VENV_ENV_NAME: .venv | |
PRE_COMMIT_HOME: $(Pipeline.Workspace)/pre-commit-cache | |
steps: | |
- task: UsePythonVersion@0 | |
inputs: | |
versionSpec: "$(PYTHON_VERSION)" | |
- script: | | |
echo "##vso[task.setvariable variable=PY]$(python -VV)" | |
displayName: set version variables | |
- task: Cache@2 | |
inputs: | |
key: '"$(Agent.OS)" | "$(PythonVersion.pythonLocation)" | requirements.txt' | |
restoreKeys: | | |
venv | "$(Agent.OS)" | "$(PythonVersion.pythonLocation)" | |
path: $(VENV_ENV_NAME) | |
cacheHitVar: VENV_CACHE_RESTORED | |
displayName: Restore cached pip packages | |
- script: | | |
pip install virtualenv wheel | |
virtualenv $(VENV_ENV_NAME) | |
displayName: Setup environment | |
condition: eq(variables.VENV_CACHE_RESTORED, 'false') | |
- task: Cache@2 | |
inputs: | |
key: pre-commit | .pre-commit-config.yaml | "$(PY)" | |
path: $(PRE_COMMIT_HOME) | |
restoreKeys: pre-commit | .pre-commit-config.yaml | |
displayName: Cache pre-commit | |
- script: | | |
source $(VENV_ENV_NAME)/bin/activate | |
pip install --upgrade pre-commit | |
displayName: install pre-commit and requirements | |
- script: source $(VENV_ENV_NAME)/bin/activate; pre-commit run --all-files --show-diff-on-failure | |
displayName: run pre-commit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment