This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
forked from Drillster/drone-volume-cache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcacher.sh
56 lines (51 loc) · 1.67 KB
/
cacher.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
set -e
PACKAGE_FILE="package-lock.json"
if [[ -n "$PLUGIN_PACKAGE_FILE" ]]; then
PACKAGE_FILE="${PLUGIN_PACKAGE_FILE}"
fi
if [[ -e "${PACKAGE_FILE}" ]]; then
echo "Using ${PACKAGE_FILE} as cache key"
CACHE_PATH=$(md5sum "${PACKAGE_FILE}" | cut -d' ' -f1)
echo "Using ${CACHE_PATH} as cache path"
else
echo "package file: ${PACKAGE_FILE} not found"
exit 0
fi
cd $(dirname ${PACKAGE_FILE})
PACKAGE_FILE=$(basename ${PACKAGE_FILE})
npm set cache .npm
SOURCES=(./node_modules ./.npm)
if [[ -n "$PLUGIN_REBUILD" && "$PLUGIN_REBUILD" == "true" ]]; then
# Create cache
for source in "${SOURCES[@]}"; do
if [ -d "$source" ]; then
echo "Rebuilding tar archive for folder $source..."
tar cf "/cache/${CACHE_PATH}/${source}.tar" "${source}/"
else
echo "$source does not exist, removing from cached folder..."
rm -rf "/cache/$CACHE_PATH/$source"
fi
done
elif [[ -n "$PLUGIN_RESTORE" && "$PLUGIN_RESTORE" == "true" ]]; then
# Restore from cache
for source in "${SOURCES[@]}"; do
if [ -d "/cache/${CACHE_PATH}/${source}.tar" ]; then
echo "Restoring tar archive for folder $source..."
mkdir -p "$source" && \
tar xf "/cache/${CACHE_PATH}/${source}.tar"
else
echo "No cache for $source"
fi
done
if [ -d ./node_modules ]
then
echo "Running npm install..."
npm install --no-audit --no-progress --silent
else
echo "Running npm clean install..."
npm ci --no-audit --no-progress --silent
fi
else
echo "No restore or rebuild flag specified, plugin won't do anything!"
fi