From 3d7d12a0fc80fe17c8f096559eb54a2fc0931cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Mi=C5=9Btal?= <37044072+szymmis@users.noreply.github.com> Date: Thu, 17 Aug 2023 11:50:53 +0200 Subject: [PATCH] Add support for installing nightlies in install script --- README.md | 2 +- install.sh | 49 ++++++++++++++++++++++++++++++++++++++------- website/download.md | 8 +++++++- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0e9a6b9ac..61beee2b3 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Scarb is under active development! Expect a lot of new features to appear soon! - [x] ASDF plugin - [x] GitHub action - [x] Workspaces -- [ ] Nightlies +- [x] Nightlies - [ ] Standardized `test` target - [ ] `scarb init` templates or `scarb create-starknet-contract` command - [ ] `Scarb.lock` diff --git a/install.sh b/install.sh index 764ea76cd..67c8aabb4 100755 --- a/install.sh +++ b/install.sh @@ -14,6 +14,7 @@ set -u SCARB_REPO="https://github.com/software-mansion/scarb" +SCARB_NIGHTLIES_REPO="https://github.com/software-mansion/scarb-nightlies" XDG_DATA_HOME="${XDG_DATA_HOME:-"${HOME}/.local/share"}" INSTALL_ROOT="${XDG_DATA_HOME}/scarb-install" LOCAL_BIN="${HOME}/.local/bin" @@ -56,7 +57,6 @@ main() { esac done - local _requested_ref="latest" local _requested_version="latest" local _do_modify_path=1 while getopts ":hpv:" opt; do @@ -69,7 +69,6 @@ main() { exit 0 ;; v) - _requested_ref="tag/v${OPTARG}" _requested_version="$OPTARG" ;; \?) @@ -81,7 +80,7 @@ main() { esac done - resolve_version "$_requested_version" "$_requested_ref" || return 1 + resolve_version "$_requested_version" || return 1 local _resolved_version=$RETVAL assert_nz "$_resolved_version" "resolved_version" @@ -400,12 +399,29 @@ get_architecture() { resolve_version() { local _requested_version=$1 - local _requested_ref=$2 + + local _ref + local _repo + + if echo "$_requested_version" | grep -q "nightly"; then + if [ "$_requested_version" = "nightly" ]; then + _requested_version="$(get_latest_nightly)" + fi + _repo="$SCARB_NIGHTLIES_REPO" + _ref="tag/${_requested_version}" + else + _repo="$SCARB_REPO" + if [ "$_requested_version" = "latest" ]; then + _ref="latest" + else + _ref="tag/v${_requested_version}" + fi + fi local _response - say "retrieving $_requested_version version from ${SCARB_REPO}..." - _response=$(ensure curl -Ls -H 'Accept: application/json' "${SCARB_REPO}/releases/${_requested_ref}") + say "retrieving $_requested_version version from ${_repo}..." + _response=$(ensure curl -Ls -H 'Accept: application/json' "${_repo}/releases/${_ref}") if [ "{\"error\":\"Not Found\"}" = "$_response" ]; then err "version $_requested_version not found" fi @@ -413,6 +429,17 @@ resolve_version() { RETVAL=$(echo "$_response" | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/') } +sort_versions() { + sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | + LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' +} + +get_latest_nightly() { + git ls-remote --tags --refs "$SCARB_NIGHTLIES_REPO" | + grep -o 'refs/tags/.*' | cut -d/ -f3- | + sort_versions | tail -n1 | xargs echo +} + create_install_dir() { local _requested_version=$1 @@ -434,8 +461,16 @@ download() { local _installdir=$3 local _tempdir=$4 + local _repo + + if echo "$_requested_version" | grep -q "nightly"; then + _repo="$SCARB_NIGHTLIES_REPO" + else + _repo="$SCARB_REPO" + fi + local _tarball="scarb-${_resolved_version}-${_arch}.tar.gz" - local _url="${SCARB_REPO}/releases/download/${_resolved_version}/${_tarball}" + local _url="${_repo}/releases/download/${_resolved_version}/${_tarball}" local _dl="$_tempdir/scarb.tar.gz" say "downloading ${_tarball}..." diff --git a/website/download.md b/website/download.md index ab8d84e84..8a593d973 100644 --- a/website/download.md +++ b/website/download.md @@ -33,7 +33,13 @@ This will install the latest **stable** release. curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh ``` -If you want to install a specific version of Scarb (such as a preview version), run the following with the desired +Run following command if you want to install the latest **nightly** release. + +```shell +curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v nightly +``` + +If you want to install a specific version of Scarb (such as a preview or nightly version), run the following with the desired version number. ```shell-vue