Add setup-pre-commit action

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2023-02-03 16:15:53 +00:00 committed by Pedro Algarvio
parent 131028f67d
commit e2b45b1a5e

View file

@ -0,0 +1,48 @@
---
name: setup-pre-commit
description: Setup 'pre-commit'
inputs:
version:
type: string
description: Pre-commit version to install
required: true
default: 3.0.3
cache-seed:
required: true
type: string
description: Seed used to invalidate caches
env:
PIP_INDEX_URL: https://pypi-proxy.saltstack.net/root/local/+simple/
PIP_EXTRA_INDEX_URL: https://pypi.org/simple
runs:
using: composite
steps:
- uses: ./.github/actions/cached-virtualenv
id: pre-commit-virtualenv
with:
name: pre-commit
cache-seed: ${{ inputs.cache-seed }}
- name: Install Pre-Commit
if: ${{ steps.pre-commit-virtualenv.outputs.cache-hit != 'true' }}
shell: bash
run: |
${{ steps.pre-commit-virtualenv.outputs.python-executable }} -m pip install pre-commit==${{ inputs.version }}
- name: Cache Pre-Commit Hooks
uses: actions/cache@v3
id: pre-commit-hooks-cache
with:
key: ${{ steps.pre-commit-virtualenv.outputs.cache-key }}|${{ inputs.version }}|${{ hashFiles('.pre-commit-config.yaml') }}
path: ~/.cache/pre-commit
- name: Install Pre-Commit Hooks
shell: bash
run: |
pre-commit install --install-hooks