-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestore-py-cache.sh
35 lines (28 loc) · 1.27 KB
/
restore-py-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
#!/usr/bin/env bash
set -e
py_ver=${1:-'3.7.0'}
py_cache_archive="$SEMAPHORE_CACHE_DIR/py$py_ver-cache.tar.gz"
# Install pyenv
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
echo 'export PATH="/home/runner/.pyenv/bin:$PATH"' | tee -a ~/.bash_profile
echo 'eval "$(pyenv init -)"' | tee -a ~/.bash_profile
echo 'eval "$(pyenv virtualenv-init -)"' | tee -a ~/.bash_profile
source ~/.bash_profile
# Restore the Python version from cache, if exists
if [ -e $py_cache_archive ]; then
echo "Restoring Python $py_ver installation cache..."
tar -xf $py_cache_archive -C $SEMAPHORE_CACHE_DIR
rm -rf ~/.pyenv/versions/$py_ver
mkdir ~/.pyenv/versions/$py_ver
cp -r $SEMAPHORE_CACHE_DIR/py$py_ver/* ~/.pyenv/versions/$py_ver/
echo "Python $py_ver installation cache restored."
else
echo "Cacheed Python $py_ver installation not found, downloading..."
# install the prerequisites
sudo apt-get update
sudo apt-get install -y libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdm-dev libc6-dev libbz2-dev zlib1g-dev openssl libffi-dev python3-dev python3-setuptools wget
pyenv install $py_ver
rm -rf $SEMAPHORE_CACHE_DIR/py$py_ver
cp -r ~/.pyenv/versions/$py_ver $SEMAPHORE_CACHE_DIR/py$py_ver
fi
pyenv global $py_ver