Skip to content

ci: Renaming EE group #490

ci: Renaming EE group

ci: Renaming EE group #490

Workflow file for this run

---
name: 'pre-commit'
on: # yamllint disable-line rule:truthy
pull_request:
branches:
- 'main'
push:
branches:
- 'main'
workflow_dispatch:
inputs:
repoCache:
description: 'Reset or disable the cache?'
type: 'choice'
default: 'enabled'
options:
- 'enabled'
- 'disabled'
- 'reset'
permissions:
contents: 'read'
# Adding these as env variables makes it easy to re-use them in different steps and in bash.
env:
cache_archive: 'pre-commit_cache.tar.gz'
# This is the dir renovate provides
# If we set our own directory via cacheDir, we can run into permissions issues.
# It is also possible to cache a higher level of the directory, but it has minimal benefit. While renovate execution
# time gets faster, it also takes longer to upload the cache as it grows bigger.
cache_dir: '/tmp/.cache/pre-commit'
# This can be manually changed to bust the cache if neccessary.
cache_key: 'pre-commit-cache'
# File that contains the pre-commit hooks to skip
hook_skip_file: './.github/.pre-commit-skip-hooks'
jobs:
pre-commit:
permissions:
contents: 'write'
runs-on: 'ubuntu-latest'
steps:
- name: 'Harden Runner'
uses: 'step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6' # v2.8.1
with:
egress-policy: 'audit'
- name: 'Checkout repository'
uses: 'actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332' # v4.1.7
- name: 'Download cache of the previous workflow run'
uses: 'dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11' # v6
if: "github.event.inputs.repoCache != 'disabled'"
continue-on-error: true
with:
name: '${{ env.cache_key }}'
path: 'cache-download'
- name: 'Extract pre-commit cache to improve performance'
run: |
set -x
# Skip if no cache is set, such as the first time it runs.
if [ ! -d cache-download ] ; then
echo "No cache found."
exit 0
fi
# Make sure the directory exists, and extract it there. Note that it's nested in the download directory.
mkdir -p "${cache_dir}"
tar -xzf "cache-download/${cache_archive}" -C "${cache_dir}"
- name: 'Install Python'
uses: 'actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f' # v5.1.1
with:
python-version: '3.11'
- name: 'Install pre-commit'
run: |
# renovate: datasource=pypi
pip3 install pre-commit==3.7.1
mkdir -pv "${cache_dir}"
- name: 'Run pre-commit'
run: |
export PRE_COMMIT_HOME="${cache_dir}"
if [[ -f "${hook_skip_file}" ]]; then
export SKIP="$(tr '\n' ',' < "${hook_skip_file}")"
fi
pre-commit run --verbose --all-files --show-diff-on-failure
- name: 'Compress pre-commit cache to improve performance'
if: "github.event.inputs.repoCache != 'disabled'"
run: |
# The -C is important, as otherwise we end up extracting the files with
# their full path, ultimately leading to a nested directory situation.
tar -czf "${cache_archive}" -C "${cache_dir}" .
- name: 'Upload compressed cache'
uses: 'actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b' # v4.3.4
if: "github.event.inputs.repoCache != 'disabled'"
with:
name: '${{ env.cache_key }}'
path: '${{ env.cache_archive }}'
# Since this is updated and restored on every run, we don't need to keep it
# for long. Just make sure this value is large enough that multiple renovate
# runs can happen before older cache archives are deleted.
retention-days: 1
...