Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script #1

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4480dca
wip
DelevoXDG Dec 11, 2024
5b513bc
Include uninstall docs for 'scarb' and 'starknet-foundry'
DelevoXDG Dec 11, 2024
ba89422
Improve plugin installation; Misc
DelevoXDG Dec 11, 2024
e4771ed
Add bold info messages on supported platforms
DelevoXDG Dec 11, 2024
abb7286
Replace bulk installation with individual version installation
DelevoXDG Dec 11, 2024
bd3bedd
Refactor global version setting
DelevoXDG Dec 11, 2024
eb3222a
Reinstall foundry to ensure latest version of USC is installed
DelevoXDG Dec 11, 2024
e2acb49
refactor
DelevoXDG Dec 11, 2024
8492df3
refactor
DelevoXDG Dec 11, 2024
7b97b9a
wip
DelevoXDG Dec 13, 2024
b8e5bbe
wip
DelevoXDG Dec 13, 2024
b97cd29
Add version and help args
DelevoXDG Dec 13, 2024
a095e67
wip
DelevoXDG Dec 13, 2024
92ce4a1
wip
DelevoXDG Dec 13, 2024
5c0d947
Fix `uninstall_latest_version`
DelevoXDG Dec 13, 2024
4cd9a6b
Add interactive installation for asdf-vm
DelevoXDG Dec 13, 2024
6434249
update description
DelevoXDG Dec 13, 2024
7932825
update shell-based installation instructions
DelevoXDG Dec 13, 2024
503ee7e
Drop support for all shels except bash, zshrc, ash
DelevoXDG Dec 13, 2024
12b03c5
Update asdf-vm installation instructions to use new documentation link
DelevoXDG Dec 13, 2024
bedaacf
wip
DelevoXDG Dec 16, 2024
6d12210
misc
DelevoXDG Dec 16, 2024
940a5cb
Add basic CI
DelevoXDG Dec 16, 2024
9230a1f
Update CI
DelevoXDG Dec 16, 2024
d35a563
Fix format checks
DelevoXDG Dec 16, 2024
491aded
improve ci
DelevoXDG Dec 16, 2024
426cf35
fix prints
DelevoXDG Dec 16, 2024
7e25f6b
misc
DelevoXDG Dec 16, 2024
1ed9000
misc
DelevoXDG Dec 16, 2024
4fb7c8c
Fetch and install latest version of asdf
DelevoXDG Dec 18, 2024
e395d8b
fix
DelevoXDG Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: CI

on:
push:
branches:
- main
pull_request:

jobs:
test:
name: test ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Setup asdf
uses: asdf-vm/actions/setup@v3

- name: Fetch latest Scarb version from GitHub releases
id: scarb_version
shell: pwsh
run: |
$location = (Invoke-WebRequest -Uri "https://github.com/software-mansion/scarb/releases/latest" -Method Head -MaximumRedirection 0 -SkipHttpErrorCheck -ErrorAction Ignore).Headers.Location
$latest_version = ($location -replace '^.*/v','')
echo "Latest Scarb version found is $latest_version"
echo "LATEST=$latest_version" >> $env:GITHUB_OUTPUT

- name: Fetch latest Starknet Foundry version from GitHub releases
id: snfoundry_version
shell: pwsh
run: |
$location = (Invoke-WebRequest -Uri "https://github.com/foundry-rs/starknet-foundry/releases/latest" -Method Head -MaximumRedirection 0 -SkipHttpErrorCheck -ErrorAction Ignore).Headers.Location
$latest_version = ($location -replace '^.*/v','')
echo "Latest Starknet Foundry version found is $latest_version"
echo "LATEST=$latest_version" >> $env:GITHUB_OUTPUT

- name: Fetch latest Universal Sierra Compiler version from GitHub releases
id: usc_version
shell: pwsh
run: |
$location = (Invoke-WebRequest -Uri "https://github.com/software-mansion/universal-sierra-compiler/releases/latest" -Method Head -MaximumRedirection 0 -SkipHttpErrorCheck -ErrorAction Ignore).Headers.Location
$latest_version = ($location -replace '^.*/v','')
echo "Latest Universal Sierra Compiler version found is $latest_version"
echo "LATEST=$latest_version" >> $env:GITHUB_OUTPUT

- name: Run starknetup
run: ./starknetup.sh

- name: Check Scarb latest
run: scarb --version | grep "scarb ${{ steps.scarb_version.outputs.LATEST }}"

- name: Check Starknet Foundry latest
run: |
snforge --version | grep "snforge ${{ steps.snfoundry_version.outputs.LATEST }}"
sncast --version | grep "sncast ${{ steps.snfoundry_version.outputs.LATEST }}"

- name: Check Universal Sierra Compiler latest
run: universal-sierra-compiler --version | grep "universal-sierra-compiler ${LATEST}"

shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: shellcheck starknetup.sh

shfmt:
runs-on: ubuntu-latest
steps:
- uses: mfinelli/setup-shfmt@v3
- uses: actions/checkout@v4
- run: shfmt --diff starknetup.sh
186 changes: 186 additions & 0 deletions starknetup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#!/bin/sh
# shellcheck shell=dash

set -eu

ASDF_INSTALL_DOCS="https://asdf-vm.com/guide/getting-started.html"
SCARB_UNINSTALL_DOCS="https://docs.swmansion.com/scarb/download#uninstall"
STARKNET_FOUNDRY_UNINSTALL_DOCS="PENDING"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SCRIPT_VERSION="0.1.0"

usage() {
cat <<EOF
The installer for Starknet tools. Installs the latest versions of Scarb, Starknet Foundry and Universal Sierra Compiler using asdf.

Usage: $0 [OPTIONS]

Options:
-h, --help Print help
-V, --version Print script version

EOF
}

main() {
for arg in "$@"; do
case "$arg" in
-h | --help)
usage
exit 0
;;
-V | --version)
printf "starknetup %s\n" "$SCRIPT_VERSION"
exit 0
;;
*)
err "invalid option '$arg'. For more information, try '--help'."
;;
esac
done

assert_dependencies
assert_not_installed "scarb" $SCARB_UNINSTALL_DOCS
install_latest_asdf_plugin "scarb"
install_latest_version "scarb"
set_global_latest_version "scarb"

assert_not_installed "starknet-foundry" $STARKNET_FOUNDRY_UNINSTALL_DOCS
install_latest_asdf_plugin "starknet-foundry"

# Reinstall to ensure the latest version of USC is installed
uninstall_latest_version "starknet-foundry"
install_latest_version "starknet-foundry"
set_global_latest_version "starknet-foundry"

say "Installation complete"
}

assert_dependencies() {
need_cmd curl
need_cmd git
if ! check_cmd asdf; then
install_asdf_interactively
fi
}

assert_not_installed() {
local tool="$1"
local uninstall_docs_url="$2"

if ! asdf which "$tool" >/dev/null 2>&1; then
if check_cmd "$tool"; then
err "$tool is already installed outside of asdf. Please uninstall it and re-run this script. For uninstallation instructions, refer to $uninstall_docs_url."
fi
fi
}

install_latest_asdf_plugin() {
local plugin="$1"
if asdf plugin list | grep -q "$plugin"; then
ensure asdf plugin update "$plugin"
else
ensure asdf plugin add "$plugin"
fi
}

install_latest_version() {
local tool="$1"
ensure asdf install "$tool" latest
}

uninstall_latest_version() {
local tool="$1"
local latest_version
latest_version=$(asdf latest "$tool")

if asdf list "$tool" "^${latest_version}$" >/dev/null 2>&1; then
ensure asdf uninstall "$tool" "$latest_version"
fi
}

set_global_latest_version() {
local tool="$1"
ensure asdf global "$tool" latest
}

say() {
printf "starknetup: %s\n" "$1"
}

err() {
say "$1" >&2
exit 1
}

need_cmd() {
if ! check_cmd "$1"; then
err "need '$1' (command not found)"
fi
}

check_cmd() {
command -v "$1" >/dev/null 2>&1
}

ensure() {
if ! "$@"; then err "command failed: $*"; fi
}

install_asdf_interactively() {
local _profile
local _pref_shell
local _asdf_path="$HOME/.asdf"

case ${SHELL:-""} in
*/zsh)
_profile=$HOME/.zshrc
_pref_shell=zsh
;;
*/ash)
_profile=$HOME/.profile
_pref_shell=ash
;;
*/bash)
if [ "$(uname)" = "Darwin" ]; then
_profile=$HOME/.bash_profile
else
_profile=$HOME/.bashrc
fi
_pref_shell=bash
;;
*)
err "asdf-vm is required. Please install it manually and re-run this script. For installation instructions, refer to ${ASDF_INSTALL_DOCS}."
;;
esac

if [ -n "$_profile" ]; then
if [ ! -f "$_profile" ]; then
touch "$_profile"
fi

say "asdf-vm is required. Do you want to install it now? (y/N): "
read -r answer
case $answer in
[Yy]*)
say "Installing asdf-vm...\n"
git clone https://github.com/asdf-vm/asdf.git "$_asdf_path" --branch v0.14.1
mkaput marked this conversation as resolved.
Show resolved Hide resolved

case $_pref_shell in
zsh | bash | ash)
echo >>"$_profile" && echo ". ${_asdf_path}/asdf.sh" >>"$_profile"
;;
esac

say "asdf-vm has been installed. Run 'source ${_profile}' or start a new terminal session and re-run this script."
exit 0
;;
*)
err "asdf-vm is required. Please install it manually and re-run this script. For installation instructions, refer to ${ASDF_INSTALL_DOCS}."
;;
esac
else
err "asdf-vm is required. Please install it manually and re-run this script. For installation instructions, refer to ${ASDF_INSTALL_DOCS}."
fi
}

main "$@" || exit 1
Loading