Archived
1
0
This repository has been archived on 2024-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
code-server/scripts/cacher.sh

67 lines
1.8 KiB
Bash
Raw Normal View History

2020-01-14 19:29:57 +01:00
#!/usr/bin/env sh
# cacher.sh -- Restore and rebuild cache.
# Cache paths are designed to work with multi-arch builds and are organized
# based on the branch or tag. The master branch cache is used as a fallback.
# This will download and package the cache but it will not upload it.
set -eu
# Try restoring from each argument in turn until we get something.
restore() {
2020-02-04 20:27:46 +01:00
for branch in "$@" ; do
if [ -n "$branch" ] ; then
cache_path="https://codesrv-ci.cdr.sh/cache/$branch/$tar.tar.gz"
if wget "$cache_path" ; then
tar xzvf "$tar.tar.gz"
break
fi
fi
done
2020-01-14 19:29:57 +01:00
}
# We need to cache the built-in extensions and Node modules. Everything inside
# the cache-upload directory will be uploaded as-is to the code-server bucket.
package() {
2020-02-04 20:27:46 +01:00
mkdir -p "cache-upload/cache/$1"
tar czfv "cache-upload/cache/$1/$tar.tar.gz" node_modules yarn-cache \
lib/vscode/.build \
lib/vscode/node_modules
2020-01-14 19:29:57 +01:00
}
main() {
2020-02-04 20:27:46 +01:00
cd "$(dirname "$0")/.."
# Get the branch for this build.
branch=${DRONE_BRANCH:-${DRONE_SOURCE_BRANCH:-${DRONE_TAG:-}}}
# The cache will be named based on the arch, platform, and libc.
arch=$DRONE_STAGE_ARCH
platform=${PLATFORM:-linux}
case $DRONE_STAGE_NAME in
*alpine*) libc=musl ;;
* ) libc=glibc ;;
esac
tar="$platform-$arch-$libc"
# The action is determined by the name of the step.
case $DRONE_STEP_NAME in
*restore*)
# Sub-modules must be pulled first since extracting the cache directories
# will prevent git from cloning into them.
git submodule update --init
restore "$branch" "$DRONE_REPO_BRANCH"
# Now make sure the pulled Node modules are up to date.
YARN_CACHE_FOLDER="$(pwd)/yarn-cache"
export YARN_CACHE_FOLDER
yarn
;;
2020-02-04 20:27:46 +01:00
*rebuild*|*package*) package "$branch" ;;
*) exit 1 ;;
esac
2020-01-14 19:29:57 +01:00
}
main "$@"