Skip to content

Commit e305fb8

Browse files
committed
Add support for installing nightlies in install script
1 parent ff9b157 commit e305fb8

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Scarb is under active development! Expect a lot of new features to appear soon!
2929
- [x] ASDF plugin
3030
- [x] GitHub action
3131
- [x] Workspaces
32-
- [ ] Nightlies
32+
- [x] Nightlies
3333
- [ ] Standardized `test` target
3434
- [ ] `scarb init` templates or `scarb create-starknet-contract` command
3535
- [ ] `Scarb.lock`

install.sh

+42-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
set -u
1515

1616
SCARB_REPO="https://github.com/software-mansion/scarb"
17+
SCARB_NIGHTLIES_REPO="https://github.com/software-mansion/scarb-nightlies"
1718
XDG_DATA_HOME="${XDG_DATA_HOME:-"${HOME}/.local/share"}"
1819
INSTALL_ROOT="${XDG_DATA_HOME}/scarb-install"
1920
LOCAL_BIN="${HOME}/.local/bin"
@@ -56,7 +57,6 @@ main() {
5657
esac
5758
done
5859

59-
local _requested_ref="latest"
6060
local _requested_version="latest"
6161
local _do_modify_path=1
6262
while getopts ":hpv:" opt; do
@@ -69,7 +69,6 @@ main() {
6969
exit 0
7070
;;
7171
v)
72-
_requested_ref="tag/v${OPTARG}"
7372
_requested_version="$OPTARG"
7473
;;
7574
\?)
@@ -81,7 +80,7 @@ main() {
8180
esac
8281
done
8382

84-
resolve_version "$_requested_version" "$_requested_ref" || return 1
83+
resolve_version "$_requested_version" || return 1
8584
local _resolved_version=$RETVAL
8685
assert_nz "$_resolved_version" "resolved_version"
8786

@@ -400,19 +399,47 @@ get_architecture() {
400399

401400
resolve_version() {
402401
local _requested_version=$1
403-
local _requested_ref=$2
402+
403+
local _ref
404+
local _repo
405+
406+
if echo "$_requested_version" | grep -q "nightly"; then
407+
if [ "$_requested_version" = "nightly" ]; then
408+
_requested_version="$(get_latest_nightly)"
409+
fi
410+
_repo="$SCARB_NIGHTLIES_REPO"
411+
_ref="tag/${_requested_version}"
412+
else
413+
_repo="$SCARB_REPO"
414+
if [ "$_requested_version" = "latest" ]; then
415+
_ref="latest"
416+
else
417+
_ref="tag/v${_requested_version}"
418+
fi
419+
fi
404420

405421
local _response
406422

407-
say "retrieving $_requested_version version from ${SCARB_REPO}..."
408-
_response=$(ensure curl -Ls -H 'Accept: application/json' "${SCARB_REPO}/releases/${_requested_ref}")
423+
say "retrieving $_requested_version version from ${_repo}..."
424+
_response=$(ensure curl -Ls -H 'Accept: application/json' "${_repo}/releases/${_ref}")
409425
if [ "{\"error\":\"Not Found\"}" = "$_response" ]; then
410426
err "version $_requested_version not found"
411427
fi
412428

413429
RETVAL=$(echo "$_response" | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
414430
}
415431

432+
sort_versions() {
433+
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
434+
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
435+
}
436+
437+
get_latest_nightly() {
438+
git ls-remote --tags --refs "$SCARB_NIGHTLIES_REPO" |
439+
grep -o 'refs/tags/.*' | cut -d/ -f3- |
440+
sort_versions | tail -n1 | xargs echo
441+
}
442+
416443
create_install_dir() {
417444
local _requested_version=$1
418445

@@ -434,8 +461,16 @@ download() {
434461
local _installdir=$3
435462
local _tempdir=$4
436463

464+
local _repo
465+
466+
if echo "$_requested_version" | grep -q "nightly"; then
467+
_repo="$SCARB_NIGHTLIES_REPO"
468+
else
469+
_repo="$SCARB_REPO"
470+
fi
471+
437472
local _tarball="scarb-${_resolved_version}-${_arch}.tar.gz"
438-
local _url="${SCARB_REPO}/releases/download/${_resolved_version}/${_tarball}"
473+
local _url="${_repo}/releases/download/${_resolved_version}/${_tarball}"
439474
local _dl="$_tempdir/scarb.tar.gz"
440475

441476
say "downloading ${_tarball}..."

website/download.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ This will install the latest **stable** release.
3333
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh
3434
```
3535

36-
If you want to install a specific version of Scarb (such as a preview version), run the following with the desired
36+
Run following command if you want to install the latest **nightly** release.
37+
38+
```shell
39+
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v nightly
40+
```
41+
42+
If you want to install a specific version of Scarb (such as a preview or nightly version), run the following with the desired
3743
version number.
3844

3945
```shell-vue

0 commit comments

Comments
 (0)