From 469218f7e362443338789fcaf0b3134ad3477904 Mon Sep 17 00:00:00 2001 From: haraldreingruber Date: Sat, 11 Nov 2023 12:49:03 +0000 Subject: [PATCH 1/2] skip clone and checkout if on gitpod workspace --- install.sh | 46 ++++++++++++++++++++++++++-------------------- rustlings | 1 + 2 files changed, 27 insertions(+), 20 deletions(-) create mode 160000 rustlings diff --git a/install.sh b/install.sh index 5915a33d..7e9b0c9f 100755 --- a/install.sh +++ b/install.sh @@ -135,34 +135,40 @@ else echo "SUCCESS: Rust is up to date" fi -Path=${1:-rustlings/} -echo "Cloning Rustlings at $Path..." -git clone -q https://github.com/rust-lang/rustlings "$Path" +# Check if GITPOD_WORKSPACE_ID environment variable exists +if [ -z "$GITPOD_WORKSPACE_ID" ]; then + Path=${1:-rustlings/} -cd "$Path" + echo "Cloning Rustlings at $Path..." + git clone -q https://github.com/rust-lang/rustlings "$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']) if 'tag_name' in obj else sys.exit(f\"Error: {obj['message']}\");") -CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin" + cd "$Path" -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} ]] + 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']) if 'tag_name' in obj else sys.exit(f\"Error: {obj['message']}\");") + CargoBin="${CARGO_HOME:-$HOME/.cargo}/bin" + + if [[ -z ${Version} ]] then - echo "No valid tag version found" - echo "Rustlings will be installed using the main branch" - Version="main" + 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 main branch" + Version="main" + else + Version="tags/${Version}" + fi else Version="tags/${Version}" fi -else - Version="tags/${Version}" -fi -echo "Checking out version $Version..." -git checkout -q ${Version} + echo "Checking out version $Version..." + git checkout -q ${Version} +else + echo "GITPOD_WORKSPACE_ID found. Skipping git clone and git checkout." +fi echo "Installing the 'rustlings' executable..." cargo install --force --path . diff --git a/rustlings b/rustlings new file mode 160000 index 00000000..9a743f80 --- /dev/null +++ b/rustlings @@ -0,0 +1 @@ +Subproject commit 9a743f80c57cc6bf27819589a8ddb5a5579ab1a4 From 9cf9a6c532e84e1a80cda6f73c9c4626271c2246 Mon Sep 17 00:00:00 2001 From: haraldreingruber Date: Sat, 11 Nov 2023 18:57:05 +0000 Subject: [PATCH 2/2] Clean up --- install.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 7e9b0c9f..54f2a844 100755 --- a/install.sh +++ b/install.sh @@ -135,8 +135,9 @@ else echo "SUCCESS: Rust is up to date" fi -# Check if GITPOD_WORKSPACE_ID environment variable exists -if [ -z "$GITPOD_WORKSPACE_ID" ]; then +# We don't need to clone if installing in Gitpod.io environment +if [[ -z ${GITPOD_WORKSPACE_ID} ]] +then Path=${1:-rustlings/} echo "Cloning Rustlings at $Path..."