Skip to content

Commit

Permalink
fix(installation): Provide a backup git reference when tag can't be curl
Browse files Browse the repository at this point in the history
closes rust-lang#423

If the parsed JSON data curled during a bash installation is not valid, use the repository's tag files
as a backup. If those files don't exist somehow, then checkout the master branch and install it.
  • Loading branch information
AbdouSeck committed Jun 5, 2020
1 parent 8ad5f9b commit 9e4fb10
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,30 @@ Path=${1:-rustlings/}
echo "Cloning Rustlings at $Path..."
git clone -q https://github.com/rust-lang/rustlings $Path

cd $Path

Version=$(curl -s https://api.github.com/repos/rust-lang/rustlings/releases/latest | ${PY} -c "import json,sys;obj=json.load(sys.stdin);print(obj['tag_name']);")
CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin"

if [[ -z ${Version} ]]
then
echo "The latest tag version could not be fetched remotely."
echo "Using the local git repository..."
Version=$(ls -tr .git/refs/tags/ | tail -1)
if [[ -z ${Version} ]]
then
echo "No valid tag version found"
echo "Rustlings will be installed using the master branch"
Version="master"
else
Version="tags/${Version}"
fi
else
Version="tags/${Version}"
fi

echo "Checking out version $Version..."
cd $Path
git checkout -q tags/$Version
git checkout -q ${Version}

echo "Installing the 'rustlings' executable..."
cargo install --force --path .
Expand Down

1 comment on commit 9e4fb10

@alexxroche
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ls -tr .git/refs/tags/ (with my clone of rustlings version 3.0.0 on linux) is empty (or should I say None() ?)
git tag|tail -n1 (with git version 2.20.1) is 3.0.0 ( Some(3.0.0) )

If the issue is a problem with the local install of python, (the migration from python2 to python3 is still causing some problems) and curl and the network are functioning then we could use the native shell script to process the JSON, before falling back to digging through the git repo itself as a last resort.

I have sketched out my native shell example here

Please sign in to comment.