From 2991250adf2003cc0a191acfd48350e2fda70446 Mon Sep 17 00:00:00 2001 From: "Gan, Jimmy" Date: Mon, 6 Apr 2026 22:13:21 +0800 Subject: [PATCH] fix: improve dependency caching in test workflow - Fix cache key generation (cat files before hashing, not hash twice) - Use cp -a instead of cp -r to preserve symlinks and permissions - Add --no-cache-dir to pip to avoid double caching - Export CACHE_KEY to env for better logging - Cache should now work properly and speed up subsequent runs --- .gitea/workflows/test.yml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 70a2ec8..d8468bf 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -28,9 +28,10 @@ jobs: - name: Cache Python dependencies id: cache-python run: | - CACHE_KEY="python-$(md5sum dashboard/backend/requirements.txt dashboard/backend/requirements-dev.txt | md5sum | cut -d' ' -f1)" + CACHE_KEY="python-$(cat dashboard/backend/requirements.txt dashboard/backend/requirements-dev.txt | md5sum | cut -d' ' -f1)" CACHE_DIR="/tmp/pytest-cache/$CACHE_KEY" echo "CACHE_DIR=$CACHE_DIR" >> $GITHUB_ENV + echo "CACHE_KEY=$CACHE_KEY" >> $GITHUB_ENV if [ -d "$CACHE_DIR" ]; then echo "Cache hit for $CACHE_KEY" echo "cache-hit=true" >> $GITHUB_OUTPUT @@ -44,17 +45,18 @@ jobs: run: | cd dashboard/backend if [ "${{ steps.cache-python.outputs.cache-hit }}" = "true" ]; then - echo "Restoring from cache..." - cp -r $CACHE_DIR/venv . + echo "Restoring from cache $CACHE_KEY..." + cp -a $CACHE_DIR/venv . else echo "Installing fresh dependencies..." python3 -m venv venv . venv/bin/activate - pip install -r requirements.txt - pip install -r requirements-dev.txt - pip install pytest-timeout + pip install --no-cache-dir -r requirements.txt + pip install --no-cache-dir -r requirements-dev.txt + pip install --no-cache-dir pytest-timeout # Save to cache - cp -r venv $CACHE_DIR/ + echo "Saving to cache $CACHE_KEY..." + cp -a venv $CACHE_DIR/ fi - name: Run unit tests @@ -91,6 +93,7 @@ jobs: CACHE_KEY="node-$(md5sum dashboard/frontend/package-lock.json | cut -d' ' -f1)" CACHE_DIR="/tmp/npm-cache/$CACHE_KEY" echo "CACHE_DIR=$CACHE_DIR" >> $GITHUB_ENV + echo "CACHE_KEY=$CACHE_KEY" >> $GITHUB_ENV if [ -d "$CACHE_DIR" ]; then echo "Cache hit for $CACHE_KEY" echo "cache-hit=true" >> $GITHUB_OUTPUT @@ -106,13 +109,14 @@ jobs: run: | cd dashboard/frontend if [ "${{ steps.cache-node.outputs.cache-hit }}" = "true" ]; then - echo "Restoring from cache..." - cp -r $CACHE_DIR/node_modules . + echo "Restoring from cache $CACHE_KEY..." + cp -a $CACHE_DIR/node_modules . else echo "Installing fresh dependencies..." npm ci # Save to cache - cp -r node_modules $CACHE_DIR/ + echo "Saving to cache $CACHE_KEY..." + cp -a node_modules $CACHE_DIR/ fi - name: Run tests