Skip to content

Commit

Permalink
add bash linting worklow (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
siosw authored Nov 29, 2023
1 parent 448d6da commit 13f6684
Show file tree
Hide file tree
Showing 14 changed files with 455 additions and 385 deletions.
26 changes: 22 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- main

jobs:
pre_job:
check_for_changes:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
Expand All @@ -16,13 +16,14 @@ jobs:
uses: fkirc/skip-duplicate-actions@v5
with:
concurrent_skipping: same_content_newer
lint:
needs: pre_job

lint_solidity:
needs: check_for_changes
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest
defaults:
run:
working-directory: contracts
working-directory: ./contracts

steps:
- uses: actions/checkout@v3
Expand All @@ -45,3 +46,20 @@ jobs:

- name: Check if forge fmt was run
run: forge fmt --check

lint_bash:
needs: check_for_changes
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./sbin

steps:
- uses: actions/checkout@v3

- name: Install shfmt
run: sudo apt-get install -y shfmt

- name: Run shfmt
run: shfmt -d .
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
shfmt -d sbin
make
2 changes: 1 addition & 1 deletion sbin/clean.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
SBIN=`dirname $0`
SBIN=$(dirname $0)
$SBIN/clean_sp_geth.sh
$SBIN/clean_deployment.sh

Expand Down
18 changes: 9 additions & 9 deletions sbin/clean_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ ROOT_DIR=$SBIN/..

PATHS_ENV=".paths.env"
if ! test -f "$PATHS_ENV"; then
echo "Expected dotenv at $PATHS_ENV (does not exist)."
exit
echo "Expected dotenv at $PATHS_ENV (does not exist)."
exit
fi
echo "Using dotenv: $PATHS_ENV"
. $PATHS_ENV

GENESIS_ENV=".genesis.env"
if test -f "$GENESIS_ENV"; then
. $GENESIS_ENV
. $GENESIS_ENV
fi

if test -f "$GENESIS_PATH"; then
echo "Removing $GENESIS_PATH"
rm $GENESIS_PATH
echo "Removing $GENESIS_PATH"
rm $GENESIS_PATH
fi
if test -f "$GENESIS_EXPORTED_HASH_PATH"; then
echo "Removing $GENESIS_EXPORTED_HASH_PATH"
rm $GENESIS_EXPORTED_HASH_PATH
echo "Removing $GENESIS_EXPORTED_HASH_PATH"
rm $GENESIS_EXPORTED_HASH_PATH
fi
if test -f "$ROLLUP_CFG_PATH"; then
echo "Removing $ROLLUP_CFG_PATH"
rm $ROLLUP_CFG_PATH
echo "Removing $ROLLUP_CFG_PATH"
rm $ROLLUP_CFG_PATH
fi

echo "Removing deployment files in $CONTRACTS_DIR"
Expand Down
4 changes: 2 additions & 2 deletions sbin/clean_sp_geth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Check that a dotenv exists.
GETH_ENV=".sp_geth.env"
if ! test -f "$GETH_ENV"; then
echo "expected dotenv at ./$GETH_ENV (does not exist); could not clean cwd."
exit
echo "expected dotenv at ./$GETH_ENV (does not exist); could not clean cwd."
exit
fi
. $GETH_ENV
echo "Removing sp-geth data dir $DATA_DIR"
Expand Down
47 changes: 25 additions & 22 deletions sbin/create_genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,53 @@
# TODO: can we get rid of this somehow?
# currently the local sbin paths are relative to the project root
SBIN=$(dirname "$(readlink -f "$0")")
SBIN="`cd "$SBIN"; pwd`"
SBIN="$(
cd "$SBIN"
pwd
)"
ROOT_DIR=$SBIN/..

# Check that the all required dotenv files exists.
PATHS_ENV=".paths.env"
if ! test -f "$PATHS_ENV"; then
echo "Expected dotenv at $PATHS_ENV (does not exist)."
exit
echo "Expected dotenv at $PATHS_ENV (does not exist)."
exit
fi
echo "Using paths dotenv: $PATHS_ENV"
. $PATHS_ENV

GENESIS_ENV=".genesis.env"
if ! test -f "$GENESIS_ENV"; then
echo "Expected dotenv at $GENESIS_ENV (does not exist)."
exit
echo "Expected dotenv at $GENESIS_ENV (does not exist)."
exit
fi
echo "Using dotenv: $GENESIS_ENV"
. $GENESIS_ENV

echo "Using $OPS_DIR as ops directory."

# Define a function to convert a path to be relative to another directory.
relpath () {
echo `python3 -c "import os.path; print(os.path.relpath('$1', '$2'))"`
relpath() {
echo $(python3 -c "import os.path; print(os.path.relpath('$1', '$2'))")
}

# Define a function that requests a user to confirm
# that overwriting file ($1) is okay, if it exists.
guard_overwrite () {
if test -f $1; then
read -r -p "Overwrite $1 with a new file? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
rm $1
else
exit
fi
guard_overwrite() {
if test -f $1; then
read -r -p "Overwrite $1 with a new file? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
rm $1
else
exit
fi
fi
}

# Get relative paths for $OPS_DIR
GENESIS_CFG_PATH=`relpath $GENESIS_CFG_PATH $OPS_DIR`
GENESIS_PATH=`relpath $GENESIS_PATH $OPS_DIR`
GENESIS_EXPORTED_HASH_PATH=`relpath $GENESIS_EXPORTED_HASH_PATH $OPS_DIR`
GENESIS_CFG_PATH=$(relpath $GENESIS_CFG_PATH $OPS_DIR)
GENESIS_PATH=$(relpath $GENESIS_PATH $OPS_DIR)
GENESIS_EXPORTED_HASH_PATH=$(relpath $GENESIS_EXPORTED_HASH_PATH $OPS_DIR)
echo "Generating new genesis file at $GENESIS_PATH and exporting hash to $GENESIS_EXPORTED_HASH_PATH"
cd $OPS_DIR
guard_overwrite $GENESIS_PATH
Expand All @@ -67,7 +70,7 @@ CONTRACTS_ENV=$CONTRACTS_DIR/$ENV
guard_overwrite $CONTRACTS_ENV
# Write file, using relative paths.
echo "Initializing $CONTRACTS_ENV"
GENESIS_PATH=`relpath $GENESIS_PATH $CONTRACTS_DIR`
GENESIS_EXPORTED_HASH_PATH=`relpath $GENESIS_EXPORTED_HASH_PATH $CONTRACTS_DIR`
echo GENESIS_PATH=$GENESIS_PATH >> $CONTRACTS_ENV
echo GENESIS_EXPORTED_HASH_PATH=$GENESIS_EXPORTED_HASH_PATH >> $CONTRACTS_ENV
GENESIS_PATH=$(relpath $GENESIS_PATH $CONTRACTS_DIR)
GENESIS_EXPORTED_HASH_PATH=$(relpath $GENESIS_EXPORTED_HASH_PATH $CONTRACTS_DIR)
echo GENESIS_PATH=$GENESIS_PATH >>$CONTRACTS_ENV
echo GENESIS_EXPORTED_HASH_PATH=$GENESIS_EXPORTED_HASH_PATH >>$CONTRACTS_ENV
67 changes: 35 additions & 32 deletions sbin/deploy_l1_contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,69 @@

# the local sbin paths are relative to the project root
SBIN=$(dirname "$(readlink -f "$0")")
SBIN="`cd "$SBIN"; pwd`"
SBIN="$(
cd "$SBIN"
pwd
)"
ROOT_DIR=$SBIN/..

# Check that the all required dotenv files exists.
PATHS_ENV=".paths.env"
if ! test -f "$PATHS_ENV"; then
echo "Expected paths dotenv at $PATHS_ENV (does not exist)."
exit
echo "Expected paths dotenv at $PATHS_ENV (does not exist)."
exit
fi
echo "Using paths dotenv: $PATHS_ENV"
. $PATHS_ENV

GENESIS_ENV=".genesis.env"
if ! test -f "$GENESIS_ENV"; then
echo "Expected dotenv at $GENESIS_ENV (does not exist)."
exit
echo "Expected dotenv at $GENESIS_ENV (does not exist)."
exit
fi
echo "Using genesis dotenv: $GENESIS_ENV"
. $GENESIS_ENV

CONTRACTS_ENV=".contracts.env"
if ! test -f "$CONTRACTS_ENV"; then
echo "Expected dotenv at $CONTRACTS_ENV (does not exist)."
exit
if ! test -f "$CONTRACTS_ENV"; then
echo "Expected dotenv at $CONTRACTS_ENV (does not exist)."
exit
fi
echo "Using contracts dotenv: $CONTRACTS_ENV"
. $CONTRACTS_ENV

# Parse args.
optspec="ch"
while getopts "$optspec" optchar; do
case "${optchar}" in
c)
echo "Cleaning..."
$SBIN/clean_deployment.sh
;;
h)
echo "usage: $0 [-c][-h]"
echo "-c : clean before running"
exit
;;
*)
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
echo "Unknown option: '-${OPTARG}'"
exit 1
fi
;;
esac
case "${optchar}" in
c)
echo "Cleaning..."
$SBIN/clean_deployment.sh
;;
h)
echo "usage: $0 [-c][-h]"
echo "-c : clean before running"
exit
;;
*)
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
echo "Unknown option: '-${OPTARG}'"
exit 1
fi
;;
esac
done

echo "Using $CONTRACTS_DIR as HH proj"

# Define a function to convert a path to be relative to another directory.
relpath () {
echo `python3 -c "import os.path; print(os.path.relpath('$1', '$2'))"`
relpath() {
echo $(python3 -c "import os.path; print(os.path.relpath('$1', '$2'))")
}

# Define a function that requests a user to confirm
# that overwriting file ($1) is okay, if it exists.
guard_overwrite () {
guard_overwrite() {
if test -f $1; then
read -r -p "Overwrite $1 with a new file? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
Expand All @@ -78,10 +81,10 @@ cp $CONTRACTS_ENV $CONTRACTS_DIR/.env

# Get relative paths, since we have to run `create_genesis.ts`
# and `create_config.ts` from the HH proj.
BASE_ROLLUP_CFG_PATH=`relpath $BASE_ROLLUP_CFG_PATH $CONTRACTS_DIR`
ROLLUP_CFG_PATH=`relpath $ROLLUP_CFG_PATH $CONTRACTS_DIR`
GENESIS_PATH=`relpath $GENESIS_PATH $CONTRACTS_DIR`
GENESIS_EXPORTED_HASH_PATH=`relpath $GENESIS_EXPORTED_HASH_PATH $CONTRACTS_DIR`
BASE_ROLLUP_CFG_PATH=$(relpath $BASE_ROLLUP_CFG_PATH $CONTRACTS_DIR)
ROLLUP_CFG_PATH=$(relpath $ROLLUP_CFG_PATH $CONTRACTS_DIR)
GENESIS_PATH=$(relpath $GENESIS_PATH $CONTRACTS_DIR)
GENESIS_EXPORTED_HASH_PATH=$(relpath $GENESIS_EXPORTED_HASH_PATH $CONTRACTS_DIR)

# Generate genesis file
$SBIN/create_genesis.sh
Expand Down
38 changes: 38 additions & 0 deletions sbin/export_genesis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
SBIN=$(dirname "$(readlink -f "$0")")
ROOT_DIR=$SBIN/..

cd $ROOT_DIR/workspace

# Check that the all required dotenv files exists.
PATHS_ENV=".paths.env"
if ! test -f "$PATHS_ENV"; then
echo "Expected dotenv at $PATHS_ENV (does not exist)."
exit
fi
. $PATHS_ENV

# Check that the dotenv exists, or GENESIS_PATH is set.
ENV=".genesis.env"
if ! test -f $ENV && [ -z ${GENESIS_PATH+x} ]; then
echo "Expected GENESIS_PATH (not set) OR dotenv at $ENV (does not exist)."
exit 1
fi
. $ENV

# Export l2 genesis hash for $GENESIS_PATH
DATA_DIR=tmp_data/
HTTP_ADDRESS="0.0.0.0"
HTTP_PORT=1234
# Initialize sp-geth
$SP_GETH_BIN init --datadir $DATA_DIR $GENESIS_PATH
# Start sp-geth
$SP_GETH_BIN --datadir $DATA_DIR --http --http.addr $HTTP_ADDRESS --http.port 1234 &
SP_GETH_PID=$!
sleep 1
# Export l2 genesis hash for $GENESIS_PATH
RESULT=$($SP_GETH_BIN attach --exec "eth.getBlock(0).hash" "http://$HTTP_ADDRESS:$HTTP_PORT")
kill $SP_GETH_PID
rm -r $DATA_DIR

echo "{\"hash\": $RESULT}"
Loading

0 comments on commit 13f6684

Please sign in to comment.