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
This commit is contained in:
+14
-10
@@ -28,9 +28,10 @@ jobs:
|
|||||||
- name: Cache Python dependencies
|
- name: Cache Python dependencies
|
||||||
id: cache-python
|
id: cache-python
|
||||||
run: |
|
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"
|
CACHE_DIR="/tmp/pytest-cache/$CACHE_KEY"
|
||||||
echo "CACHE_DIR=$CACHE_DIR" >> $GITHUB_ENV
|
echo "CACHE_DIR=$CACHE_DIR" >> $GITHUB_ENV
|
||||||
|
echo "CACHE_KEY=$CACHE_KEY" >> $GITHUB_ENV
|
||||||
if [ -d "$CACHE_DIR" ]; then
|
if [ -d "$CACHE_DIR" ]; then
|
||||||
echo "Cache hit for $CACHE_KEY"
|
echo "Cache hit for $CACHE_KEY"
|
||||||
echo "cache-hit=true" >> $GITHUB_OUTPUT
|
echo "cache-hit=true" >> $GITHUB_OUTPUT
|
||||||
@@ -44,17 +45,18 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cd dashboard/backend
|
cd dashboard/backend
|
||||||
if [ "${{ steps.cache-python.outputs.cache-hit }}" = "true" ]; then
|
if [ "${{ steps.cache-python.outputs.cache-hit }}" = "true" ]; then
|
||||||
echo "Restoring from cache..."
|
echo "Restoring from cache $CACHE_KEY..."
|
||||||
cp -r $CACHE_DIR/venv .
|
cp -a $CACHE_DIR/venv .
|
||||||
else
|
else
|
||||||
echo "Installing fresh dependencies..."
|
echo "Installing fresh dependencies..."
|
||||||
python3 -m venv venv
|
python3 -m venv venv
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
pip install -r requirements.txt
|
pip install --no-cache-dir -r requirements.txt
|
||||||
pip install -r requirements-dev.txt
|
pip install --no-cache-dir -r requirements-dev.txt
|
||||||
pip install pytest-timeout
|
pip install --no-cache-dir pytest-timeout
|
||||||
# Save to cache
|
# Save to cache
|
||||||
cp -r venv $CACHE_DIR/
|
echo "Saving to cache $CACHE_KEY..."
|
||||||
|
cp -a venv $CACHE_DIR/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Run unit tests
|
- name: Run unit tests
|
||||||
@@ -91,6 +93,7 @@ jobs:
|
|||||||
CACHE_KEY="node-$(md5sum dashboard/frontend/package-lock.json | cut -d' ' -f1)"
|
CACHE_KEY="node-$(md5sum dashboard/frontend/package-lock.json | cut -d' ' -f1)"
|
||||||
CACHE_DIR="/tmp/npm-cache/$CACHE_KEY"
|
CACHE_DIR="/tmp/npm-cache/$CACHE_KEY"
|
||||||
echo "CACHE_DIR=$CACHE_DIR" >> $GITHUB_ENV
|
echo "CACHE_DIR=$CACHE_DIR" >> $GITHUB_ENV
|
||||||
|
echo "CACHE_KEY=$CACHE_KEY" >> $GITHUB_ENV
|
||||||
if [ -d "$CACHE_DIR" ]; then
|
if [ -d "$CACHE_DIR" ]; then
|
||||||
echo "Cache hit for $CACHE_KEY"
|
echo "Cache hit for $CACHE_KEY"
|
||||||
echo "cache-hit=true" >> $GITHUB_OUTPUT
|
echo "cache-hit=true" >> $GITHUB_OUTPUT
|
||||||
@@ -106,13 +109,14 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cd dashboard/frontend
|
cd dashboard/frontend
|
||||||
if [ "${{ steps.cache-node.outputs.cache-hit }}" = "true" ]; then
|
if [ "${{ steps.cache-node.outputs.cache-hit }}" = "true" ]; then
|
||||||
echo "Restoring from cache..."
|
echo "Restoring from cache $CACHE_KEY..."
|
||||||
cp -r $CACHE_DIR/node_modules .
|
cp -a $CACHE_DIR/node_modules .
|
||||||
else
|
else
|
||||||
echo "Installing fresh dependencies..."
|
echo "Installing fresh dependencies..."
|
||||||
npm ci
|
npm ci
|
||||||
# Save to cache
|
# Save to cache
|
||||||
cp -r node_modules $CACHE_DIR/
|
echo "Saving to cache $CACHE_KEY..."
|
||||||
|
cp -a node_modules $CACHE_DIR/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
|
|||||||
Reference in New Issue
Block a user