Skip to content

Commit

Permalink
Support latest:nightly version alias (#10)
Browse files Browse the repository at this point in the history
Resolves #9
  • Loading branch information
szymmis authored Aug 17, 2023
1 parent d27552b commit 9d5937b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ jobs:
echo "Latest Scarb version found is $latest_version"
echo "LATEST_VERSION=$latest_version" >> $env:GITHUB_OUTPUT
$location = (Invoke-WebRequest -Uri "https://github.com/software-mansion/scarb-nightlies/releases/latest" -Method Head -MaximumRedirection 0 -SkipHttpErrorCheck -ErrorAction Ignore).Headers.Location
$latest_version = ($location -replace '^.*/nightly-','nightly-')
echo "Latest Scarb nightly version found is $latest_version"
echo "LATEST_NIGHTLY_VERSION=$latest_version" >> $env:GITHUB_OUTPUT
- name: "Check Scarb latest"
uses: asdf-vm/actions/plugin-test@v2
with:
Expand All @@ -38,6 +43,13 @@ jobs:
version: 0.5.2
command: scarb --version | grep "scarb 0.5.2"

- name: "Check Scarb latest:nightly"
uses: asdf-vm/actions/plugin-test@v2
with:
skip_install: true
version: latest:nightly
command: scarb --version | grep "${{ steps.version.outputs.LATEST_NIGHTLY_VERSION }}"

- name: "Check Scarb nightly-2023-08-10"
uses: asdf-vm/actions/plugin-test@v2
with:
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ Install specific version:
asdf install scarb 0.5.0
```

Install latest nightly version:

```shell
asdf install scarb latest:nightly
```

Install specific nightly version:

```shell
Expand All @@ -58,5 +64,4 @@ scarb --version
Check [asdf](https://github.com/asdf-vm/asdf) readme for more instructions on how to install & manage versions.

[asdf]: https://asdf-vm.com

[scarb]: https://docs.swmansion.com/scarb
22 changes: 13 additions & 9 deletions bin/latest-stable
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ if [ -n "${GITHUB_API_TOKEN:-}" ]; then
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
fi

# curl of REPO/releases/latest is expected to be a 302 to another URL
# when no releases redirect_url="REPO/releases"
# when there are releases redirect_url="REPO/releases/tag/v<VERSION>"
redirect_url=$(curl "${curl_opts[@]}" "$GH_REPO/releases/latest" | sed -n -e "s|^location: *||p" | sed -n -e "s|\r||p")
version=
printf "redirect url: %s\n" "$redirect_url" >&2
if [[ "$redirect_url" == "$GH_REPO/releases" ]]; then
version="$(list_all_versions | sort_versions | tail -n1 | xargs echo)"
if grep -q "nightly" <<<"$1"; then
version="$(get_latest_nightly)"
else
version="$(printf "%s\n" "$redirect_url" | sed 's|.*/tag/v\{0,1\}||')"
# curl of REPO/releases/latest is expected to be a 302 to another URL
# when no releases redirect_url="REPO/releases"
# when there are releases redirect_url="REPO/releases/tag/v<VERSION>"
redirect_url=$(curl "${curl_opts[@]}" "$GH_REPO/releases/latest" | sed -n -e "s|^location: *||p" | sed -n -e "s|\r||p")
version=
printf "redirect url: %s\n" "$redirect_url" >&2
if [[ "$redirect_url" == "$GH_REPO/releases" ]]; then
version="$(list_all_versions | sort_versions | tail -n1 | xargs echo)"
else
version="$(printf "%s\n" "$redirect_url" | sed 's|.*/tag/v\{0,1\}||')"
fi
fi

printf "%s\n" "$version"
6 changes: 6 additions & 0 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ list_all_versions() {
list_github_tags
}

get_latest_nightly() {
git ls-remote --tags --refs "$GH_NIGHTLIES_REPO" |
grep -o 'refs/tags/.*' | cut -d/ -f3- |
sort_versions | tail -n1 | xargs echo
}

download_release() {
local version filename url
version="$1"
Expand Down

0 comments on commit 9d5937b

Please sign in to comment.