From 0feeb5884a0a6497b2f5711d1f67cbe14a1b88f8 Mon Sep 17 00:00:00 2001 From: Dunedan Date: Wed, 28 Aug 2024 07:42:08 +0200 Subject: [PATCH] Cache Python dependencies in pre-commit workflow This should speed up installation of pre-commit as part of the Gitea Action a bit, as it caches the Python packages required for it. The cache functionality of actions/setup-python is unsuitable for this use case, as we don't have a file with requirements we want to use as key. Instead, we just want to cache whatever is downloaded via pip from PyPI and keep it for further invocations. This commit achieves that by using the same cache key for every workflow run. The cache is being updated even if pre-commit fails so we always keep the the Python packages used for installing pre-commit cached. --- .gitea/workflows/pre-commit.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.gitea/workflows/pre-commit.yml b/.gitea/workflows/pre-commit.yml index 0237934358..a5f4008fd2 100644 --- a/.gitea/workflows/pre-commit.yml +++ b/.gitea/workflows/pre-commit.yml @@ -9,4 +9,14 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + - id: restore-pip-cache + uses: actions/cache/restore@v4 + with: + key: pip-cache-v1-${{ github.workflow }} + path: ~/.cache/pip - uses: pre-commit/action@v3.0.1 + - uses: actions/cache/save@v4 + if: steps.restore-pip-cache.outcome == 'success' + with: + key: pip-cache-v1-${{ github.workflow }} + path: ~/.cache/pip