forked from DevExpress/DevExtreme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drone-cache.sh
executable file
·47 lines (37 loc) · 1.08 KB
/
drone-cache.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
#!/bin/bash
CACHE_BUCKET=devextreme-ci-cache
CACHE_DIRS="node_modules dotnet_packages"
if [ -z "$DRONE_REPO" ] || [ -z "$DRONE_BRANCH" ]; then
echo "Missing required env"
exit 1
fi
if [ "$1" == "rebuild" ]; then
if [ "$DRONE_BUILD_EVENT" != "push" ]; then
echo "Skip on $DRONE_BUILD_EVENT"
exit 0
fi
for i in $CACHE_DIRS; do
if [ -e $i ]; then
url="http://$CACHE_BUCKET.s3.amazonaws.com/$DRONE_REPO/$DRONE_BRANCH/$i.tgz"
if tar cfz - $i | curl -Lsf -X PUT -H "x-amz-acl: bucket-owner-full-control" --data-binary @- "$url"; then
echo "Uploaded: $url"
fi
else
echo "Does not exist: $i"
fi
done
exit 0
fi
if [ "$1" == "restore" ]; then
for i in $CACHE_DIRS; do
url="http://$CACHE_BUCKET.s3.amazonaws.com/$DRONE_REPO/$DRONE_BRANCH/$i.tgz"
if curl -Lsf "$url" | tar xzf - 2>/dev/null; then
echo "Restored: $url"
else
echo "Unable to restore: $url"
fi
done
exit 0
fi
echo "Not enough arguments"
exit 1