Skip to content

Commit

Permalink
ci: adds a script to install a local alias to load env variables on d…
Browse files Browse the repository at this point in the history
…emand
  • Loading branch information
kerber0x committed Feb 6, 2024
1 parent c803cc5 commit cc22650
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
24 changes: 24 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Prints the list of recipes.
default:
@just --list

# Builds the whole project with the a feature flag if provided.
build FEATURE='':
#!/usr/bin/env sh
echo "-- Building {{FEATURE}} -- \n"
Expand All @@ -7,9 +12,11 @@ build FEATURE='':
cargo build --features {{FEATURE}}
fi
# Build all schemas
schemas:
scripts/build_schemas.sh

# Tests the whole project with the a feature flag if provided.
test FEATURE='':
#!/usr/bin/env sh
if [ -z "{{FEATURE}}" ]; then
Expand All @@ -18,14 +25,17 @@ test FEATURE='':
cargo test --features {{FEATURE}}
fi
# Alias to the format recipe.
fmt:
@just format

# Formats the rust, toml and sh files in the project.
format:
cargo fmt --all
find . -type f -iname "*.toml" -print0 | xargs -0 taplo format
find . -type f -name '*.sh' -exec shfmt -w {} \;

# Runs clippy with the a feature flag if provided.
lint FEATURE='':
#!/usr/bin/env sh
if [ -z "{{FEATURE}}" ]; then
Expand All @@ -34,22 +44,28 @@ lint FEATURE='':
cargo clippy --features {{FEATURE}} --all -- -D warnings
fi
# Tries to fix clippy issues automatically.
lintfix:
cargo clippy --fix --allow-staged --allow-dirty --all-features
just format

# Checks the whole project with all the feature flags.
check-all:
cargo check --all-features

# Cargo check.
check:
cargo check

# Cargo clean and update.
refresh:
cargo clean && cargo update

# Cargo watch.
watch:
cargo watch -x lcheck

# Watches tests with the a feature flag if provided.
watch-test FEATURE='':
#!/usr/bin/env sh
if [ -z "{{FEATURE}}" ]; then
Expand All @@ -58,14 +74,22 @@ watch-test FEATURE='':
cargo watch -x "nextest run --features {{FEATURE}}"
fi
# Compiles and optimizes the contracts for the specified chain.
optimize CHAIN:
scripts/build_release.sh -c {{CHAIN}}

# Prints the artifacts versions on the current commit.
get-artifacts-versions:
scripts/get_artifacts_versions.sh

# Prints the artifacts size. Optimize should be called before.
get-artifacts-size:
scripts/check_artifacts_size.sh

# Extracts the pools from the given chain.
get-pools CHAIN:
scripts/deployment/extract_pools.sh -c {{CHAIN}}

# Installs the env loader locally.
install-env-loader:
scripts/deployment/deploy_env/add_load_chain_env_alias.sh
30 changes: 30 additions & 0 deletions scripts/deployment/deploy_env/add_load_chain_env_alias.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

project_root_path=$(realpath "$0" | sed 's|\(.*\)/.*|\1|' | cd ../ | pwd)

# Function definition to append, including the load alias
loadenv_function="
#cosmos chains env loader
alias load='load_chain_env'
load_chain_env() {
if [ -z \"\$1\" ]; then
echo \"Please specify the chain to load (e.g., migaloo, terra...)\"
else
source "${project_root_path}"/scripts/deployment/deploy_env/chain_env.sh
init_chain_env \"\$1\"
fi
}
"

# Potential shell configuration files
bashrc="$HOME/.bashrc"
zshrc="$HOME/.zshrc"
profile="$HOME/.profile"

# Append the function to Bash and Zsh configuration files if they exist
[[ -f "$bashrc" ]] && echo "$loadenv_function" >>"$bashrc" && echo "Added to $bashrc"
[[ -f "$zshrc" ]] && echo "$loadenv_function" >>"$zshrc" && echo "Added to $zshrc"
[[ -f "$profile" ]] && echo "$loadenv_function" >>"$profile" && echo "Added to $profile"

echo "Now you can load chains env variables by doing 'load <chain>' in your terminal."
echo "To see a list of compatible chains look into chain_env.sh"
4 changes: 2 additions & 2 deletions scripts/deployment/deploy_env/chain_env.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -e
#set -e

project_root_path=$(realpath "$0" | sed 's|\(.*\)/.*|\1|' | cd ../ | pwd)

Expand Down Expand Up @@ -93,7 +93,7 @@ function init_chain_env() {

*)
echo "Network $chain not defined"
exit 1
return 1
;;
esac

Expand Down
1 change: 0 additions & 1 deletion scripts/deployment/deploy_env/mainnets/terra.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export CHAIN_ID="phoenix-1"
export DENOM="uluna"
export BINARY="terrad"
export RPC="https://ww-terra-rpc.polkachu.com:443"
export TXFLAG="--node $RPC --chain-id $CHAIN_ID --gas-prices 0.15$DENOM --gas auto --gas-adjustment 1.3 -y -b block --output json"

0 comments on commit cc22650

Please sign in to comment.