-
Notifications
You must be signed in to change notification settings - Fork 3
Add script #1
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
Merged
Merged
Add script #1
Changes from all commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
4480dca
wip
DelevoXDG 5b513bc
Include uninstall docs for 'scarb' and 'starknet-foundry'
DelevoXDG ba89422
Improve plugin installation; Misc
DelevoXDG e4771ed
Add bold info messages on supported platforms
DelevoXDG abb7286
Replace bulk installation with individual version installation
DelevoXDG bd3bedd
Refactor global version setting
DelevoXDG eb3222a
Reinstall foundry to ensure latest version of USC is installed
DelevoXDG e2acb49
refactor
DelevoXDG 8492df3
refactor
DelevoXDG 7b97b9a
wip
DelevoXDG b8e5bbe
wip
DelevoXDG b97cd29
Add version and help args
DelevoXDG a095e67
wip
DelevoXDG 92ce4a1
wip
DelevoXDG 5c0d947
Fix `uninstall_latest_version`
DelevoXDG 4cd9a6b
Add interactive installation for asdf-vm
DelevoXDG 6434249
update description
DelevoXDG 7932825
update shell-based installation instructions
DelevoXDG 503ee7e
Drop support for all shels except bash, zshrc, ash
DelevoXDG 12b03c5
Update asdf-vm installation instructions to use new documentation link
DelevoXDG bedaacf
wip
DelevoXDG 6d12210
misc
DelevoXDG 940a5cb
Add basic CI
DelevoXDG 9230a1f
Update CI
DelevoXDG d35a563
Fix format checks
DelevoXDG 491aded
improve ci
DelevoXDG 426cf35
fix prints
DelevoXDG 7e25f6b
misc
DelevoXDG 1ed9000
misc
DelevoXDG 4fb7c8c
Fetch and install latest version of asdf
DelevoXDG e395d8b
fix
DelevoXDG 79123fe
Use 2 spaces instead of tabs
DelevoXDG f298591
Add shell source instruction on completion
DelevoXDG ddf7b65
Format
DelevoXDG fc13f93
Add .editorconfig with correct indent
DelevoXDG e65b87a
Improve handling of asdf version fetching
DelevoXDG 41f16f7
update ci per review (remove pwsh use)
DelevoXDG af5daa8
fmt
DelevoXDG 96a71a3
add sh support; drop ash
DelevoXDG 238f412
Remove if around touch
DelevoXDG 4cf66d3
update error msg
DelevoXDG 2714c80
remove `set +e` around curl
DelevoXDG dacf543
add `--fail` to curl
DelevoXDG 20ac8da
Revert "remove `set +e` around curl"
DelevoXDG 50fb38a
update snfoundry uninstall instructions
DelevoXDG 25e7407
misc: improve foundry uninst instructions
DelevoXDG 5a550dd
misc: update error message for negative asdf install prompt answer
DelevoXDG 57ddcf4
remove shellcheck
DelevoXDG 7b411b3
drop `local` to make shellcheck happy (posix shell compat)
DelevoXDG 09a73cd
simplify `install_asdf_interactively`
DelevoXDG 71a1685
fmt
DelevoXDG aff9ee8
simplify fetching asdf version
DelevoXDG a0fa3e7
install_asdf_interactively: fix completion msg
DelevoXDG 8412992
misc reorder cases
DelevoXDG d2434f4
install asdf silently
DelevoXDG 5411f72
install USC manually
DelevoXDG 9191854
fix `say` to support newlines
DelevoXDG eae4d48
fix plugin check
DelevoXDG 96da134
centralize non-asdf install check; fix installation check
DelevoXDG 55adea0
add `check_asdf_plugin_installed`
DelevoXDG 4ad983f
update usc only if non-latest ver is installed
DelevoXDG a446699
enforce asdf prompt in non-interactive shells
DelevoXDG 7976d20
always use asdf 0.15.0
DelevoXDG 72b44d0
Use correct shell for usc install
DelevoXDG 3a94220
fix `install_universal_sierra_compiler`
DelevoXDG 662b9bc
add final usc check
DelevoXDG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
root = true | ||
|
||
[*.sh] | ||
indent_style = space | ||
indent_size = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
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 | ||
run: | | ||
latest_version=$(curl -s --fail https://api.github.com/repos/software-mansion/scarb/releases/latest | grep \"tag_name\": | awk '{print $2}' | tr -d 'v",') | ||
echo "Latest Scarb version found is $latest_version" | ||
echo "LATEST=$latest_version" >> $GITHUB_OUTPUT | ||
|
||
- name: Fetch latest Starknet Foundry version from GitHub releases | ||
id: snfoundry_version | ||
run: | | ||
latest_version=$(curl -s --fail https://api.github.com/repos/foundry-rs/starknet-foundry/releases/latest | grep \"tag_name\": | awk '{print $2}' | tr -d 'v",') | ||
echo "Latest Starknet Foundry version found is $latest_version" | ||
echo "LATEST=$latest_version" >> $GITHUB_OUTPUT | ||
|
||
- name: Fetch latest Universal Sierra Compiler version from GitHub releases | ||
id: usc_version | ||
run: | | ||
latest_version=$(curl -s --fail https://api.github.com/repos/software-mansion/universal-sierra-compiler/releases/latest | grep \"tag_name\": | awk '{print $2}' | tr -d 'v",') | ||
echo "Latest Universal Sierra Compiler version found is $latest_version" | ||
echo "LATEST=$latest_version" >> $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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,262 @@ | ||
#!/bin/sh | ||
DelevoXDG marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
set -eu | ||
|
||
ASDF_INSTALL_DOCS="https://asdf-vm.com/guide/getting-started.html" | ||
SCARB_UNINSTALL_INSTRUCTIONS="For uninstallation instructions, refer to https://docs.swmansion.com/scarb/download#uninstall" | ||
# TODO(#2): Link snfoundry uninstall docs once they are available | ||
STARKNET_FOUNDRY_UNINSTALL_INSTRUCTIONS="Try removing snforge and sncast binaries from $HOME/.local/bin" | ||
SCRIPT_VERSION="0.1.0" | ||
DEFAULT_ASDF_VERSION="v0.15.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 | ||
maciektr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
EOF | ||
} | ||
|
||
main() { | ||
for arg in "$@"; do | ||
case "$arg" in | ||
-h | --help) | ||
usage | ||
exit 0 | ||
;; | ||
-V | --version) | ||
maciektr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
say "starknetup $SCRIPT_VERSION" | ||
exit 0 | ||
;; | ||
*) | ||
err "invalid option '$arg'. For more information, try '--help'." | ||
;; | ||
esac | ||
done | ||
|
||
assert_dependencies | ||
assert_not_installed_outside_asdf | ||
|
||
install_latest_asdf_plugin "scarb" | ||
install_latest_version "scarb" | ||
set_global_latest_version "scarb" | ||
THenry14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
install_universal_sierra_compiler | ||
|
||
install_latest_asdf_plugin "starknet-foundry" | ||
install_latest_version "starknet-foundry" | ||
set_global_latest_version "starknet-foundry" | ||
|
||
_shell_config="" | ||
_completion_message="" | ||
|
||
case ${SHELL:-""} in | ||
*/zsh) | ||
_shell_config="$HOME/.zshrc" | ||
_completion_message="Run 'source ${_shell_config}'" | ||
;; | ||
*/bash) | ||
if [ "$(uname)" = "Darwin" ]; then | ||
_shell_config="$HOME/.bash_profile" | ||
else | ||
_shell_config="$HOME/.bashrc" | ||
fi | ||
_completion_message="Run 'source ${_shell_config}'" | ||
;; | ||
*/sh) | ||
_shell_config="$HOME/.profile" | ||
_completion_message="Run '. ${_shell_config}'" | ||
;; | ||
*) | ||
_completion_message="Source your shell configuration file" | ||
;; | ||
esac | ||
|
||
if ! check_cmd universal-sierra-compiler; then | ||
_local_bin="${HOME}/.local/bin" | ||
say "Couldn't finish universal-sierra-compiler installation, try manually adding ${_local_bin} to your PATH." | ||
fi | ||
|
||
say "Installation complete. ${_completion_message} or start a new terminal session to use the installed tools." | ||
} | ||
|
||
assert_dependencies() { | ||
need_cmd curl | ||
need_cmd git | ||
if ! check_cmd asdf; then | ||
install_asdf_interactively | ||
fi | ||
} | ||
|
||
assert_not_installed_outside_asdf() { | ||
THenry14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_installed_tools="" | ||
|
||
for _tool in "scarb" "starknet-foundry"; do | ||
_uninst_instructions="" | ||
_tool_cmds="" | ||
|
||
case "$_tool" in | ||
"scarb") | ||
_uninst_instructions="$SCARB_UNINSTALL_INSTRUCTIONS" | ||
_tool_cmds="scarb" | ||
;; | ||
"starknet-foundry") | ||
_uninst_instructions="$STARKNET_FOUNDRY_UNINSTALL_INSTRUCTIONS" | ||
_tool_cmds="snforge sncast" | ||
;; | ||
esac | ||
|
||
if ! check_asdf_plugin_installed "$_tool"; then | ||
for _cmd in $_tool_cmds; do | ||
if check_cmd "$_cmd"; then | ||
_installed_tools="${_installed_tools}${_installed_tools:+\n} - $_cmd (from $_tool). $_uninst_instructions" | ||
fi | ||
done | ||
fi | ||
done | ||
|
||
if [ -n "$_installed_tools" ]; then | ||
err "The following tool(s) are already installed outside of asdf:\n$_installed_tools" | ||
fi | ||
} | ||
|
||
install_latest_asdf_plugin() { | ||
_plugin="$1" | ||
if check_asdf_plugin_installed "$_plugin"; then | ||
ensure asdf plugin update "$_plugin" | ||
else | ||
ensure asdf plugin add "$_plugin" | ||
fi | ||
} | ||
|
||
check_asdf_plugin_installed() { | ||
_plugin="$1" | ||
asdf plugin list | grep -xq "$_plugin" | ||
} | ||
|
||
install_latest_version() { | ||
_tool="$1" | ||
ensure asdf install "$_tool" latest | ||
} | ||
|
||
uninstall_latest_version() { | ||
_tool="$1" | ||
_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() { | ||
_tool="$1" | ||
ensure asdf global "$_tool" latest | ||
} | ||
|
||
get_latest_gh_version() { | ||
_repo="$1" | ||
curl -sS --fail "https://api.github.com/repos/${_repo}/releases/latest" | awk -F'"' '/"tag_name"/ {print $4}' | ||
} | ||
|
||
install_universal_sierra_compiler() { | ||
THenry14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_version="" | ||
_latest_version="" | ||
if check_cmd universal-sierra-compiler; then | ||
_version=$(universal-sierra-compiler --version 2>/dev/null | awk '{print $2}') | ||
_latest_version=$(get_latest_gh_version "software-mansion/universal-sierra-compiler") | ||
fi | ||
|
||
if [ -z "$_version" ] || [ "$_version" != "$_latest_version" ]; then | ||
curl -sSL --fail https://raw.githubusercontent.com/software-mansion/universal-sierra-compiler/master/scripts/install.sh | ${SHELL:-sh} | ||
fi | ||
} | ||
|
||
say() { | ||
printf 'starknetup: %b\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() { | ||
_profile="" | ||
_pref_shell="" | ||
_completion_message="" | ||
_asdf_path="$HOME/.asdf" | ||
|
||
case ${SHELL:-""} in | ||
*/zsh) | ||
_profile=$HOME/.zshrc | ||
_pref_shell=zsh | ||
_completion_message="Run 'source ${_profile}'" | ||
;; | ||
*/bash) | ||
if [ "$(uname)" = "Darwin" ]; then | ||
_profile=$HOME/.bash_profile | ||
else | ||
_profile=$HOME/.bashrc | ||
fi | ||
_pref_shell=bash | ||
_completion_message="Run 'source ${_profile}'" | ||
;; | ||
*/sh) | ||
_profile=$HOME/.profile | ||
_pref_shell="sh" | ||
_completion_message="Run '. ${_profile}'" | ||
;; | ||
esac | ||
|
||
if [ -z "$_profile" ] || [ -z "$_pref_shell" ]; then | ||
err "asdf-vm is required. Please install it manually and re-run this script. For installation instructions, refer to ${ASDF_INSTALL_DOCS}." | ||
fi | ||
|
||
touch "$_profile" | ||
|
||
say "asdf-vm is required. Do you want to install it now? (y/N): " | ||
# Starknetup is going to want to ask for confirmation by | ||
# reading stdin. This script may be piped into `sh` though | ||
# and wouldn't have stdin to pass to its children. Instead we're | ||
# going to explicitly connect /dev/tty to the installer's stdin. | ||
if [ ! -t 0 ] && [ -r /dev/tty ]; then | ||
read -r answer </dev/tty | ||
else | ||
read -r answer | ||
fi | ||
if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then | ||
# TODO: https://github.com/software-mansion/scarb/issues/1938 | ||
# Support newer versions of asdf-vm | ||
_version="$DEFAULT_ASDF_VERSION" | ||
say "Installing asdf-vm ${_version}..." | ||
git clone --quiet -c advice.detachedHead=false https://github.com/asdf-vm/asdf.git "$_asdf_path" --branch "$_version" | ||
|
||
echo >>"$_profile" && echo ". ${_asdf_path}/asdf.sh" >>"$_profile" | ||
|
||
say "asdf-vm has been installed. ${_completion_message} or start a new terminal session and re-run this script." | ||
exit 0 | ||
else | ||
err "cancelled asdf-vm installation. Please install it manually and re-run this script. For installation instructions, refer to ${ASDF_INSTALL_DOCS}." | ||
fi | ||
} | ||
|
||
main "$@" || exit 1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.