diff options
author | 2022-01-10 19:36:51 +0000 | |
---|---|---|
committer | 2022-01-10 19:41:05 +0000 | |
commit | 2dba7b68e02f621b1126931fda8048440c47e573 (patch) | |
tree | 1ae207b3915114835b20ca41823ff680cea296fc | |
parent | Add config for pre-commit (diff) |
Update lint flow to cache and use pre-commit config
-rw-r--r-- | .github/workflows/lint.yml | 56 |
1 files changed, 50 insertions, 6 deletions
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 49b05fc..6112699 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,17 +14,61 @@ on: jobs: lint: runs-on: ubuntu-latest + env: + PIP_NO_CACHE_DIR: false + PIP_USER: 1 + 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 + - uses: actions/checkout@v2 - - name: Lint Ansible playbooks - uses: ansible/ansible-lint-action@master + - name: Setup python + id: python + uses: actions/setup-python@v2 + with: + python-version: '3.10' + + # 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: - targets: | - playbook.yml - override-deps: | - ansible-lint==5.3.2 + path: ${{ env.PYTHONUSERBASE }} + key: "python-0-${{ runner.os }}-${{ env.PYTHONUSERBASE }}-\ + ${{ steps.python.outputs.python-version }}-\ + ${{ hashFiles('./requirements.txt') }}" + + # 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 -U pip wheel setuptools + pip install -r requirements.txt + + # 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') }}" + + # 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 # Prepare the Pull Request Payload artifact. If this fails, we # we fail silently using the `continue-on-error` option. It's |