diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 22578e795c..79f6e300a7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -55,6 +55,21 @@ jobs: - name: Run transaction Fuzzing check run: make check-tx-fuzzing + shellcheck: + name: Shellcheck - ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + steps: + - uses: actions/checkout@v4 + - name: Install shellcheck + run: | + sudo apt update || true + sudo apt install -y shellcheck || true + - name: Run shellcheck + run: make lint-bash + hadolint: name: Hadolint - ${{ matrix.os }} runs-on: ${{ matrix.os }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cdb05b754..59b731ebf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Documentation**: add instructions for developers using MacOS based systems, and test the installation commands in CI ([#1247](https://github.com/o1-labs/openmina/pull/1234)). +- **Development tools**: Add shellcheck to the CI + ([#1255](https://github.com/o1-labs/openmina/pull/1255)) ### Changed diff --git a/Makefile b/Makefile index 542fbe4e0d..685a7c92a2 100644 --- a/Makefile +++ b/Makefile @@ -162,6 +162,16 @@ format-md: ## Format all markdown and MDX files to wrap at 80 characters lint: ## Run linter (clippy) cargo clippy --all-targets -- -D warnings --allow clippy::mutable_key_type +.PHONY: lint-bash +lint-bash: ## Check all shell scripts using shellcheck + @echo "Running shellcheck on shell scripts..." + @find . -name "*.sh" \ + -not -path "*/target/*" \ + -not -path "*/node_modules/*" \ + -not -path "*/website/docs/developers/scripts/setup/*" \ + -print0 | xargs -0 shellcheck + @echo "Shellcheck completed successfully!" + .PHONY: lint-dockerfiles lint-dockerfiles: ## Check all Dockerfiles using hadolint @if [ "$$GITHUB_ACTIONS" = "true" ]; then \ diff --git a/frontend/docker/startup.sh b/frontend/docker/startup.sh index 3ce73c91a2..50beba4b6d 100644 --- a/frontend/docker/startup.sh +++ b/frontend/docker/startup.sh @@ -10,12 +10,13 @@ replace_signaling_url() { echo "Replacing signaling URL in $HTTPD_CONF..." sed -i "s|$SIGNALING_URL|$OPENMINA_SIGNALING_URL|g" "$HTTPD_CONF" - - if [[ $? -ne 0 ]]; then + sed_exit_code=$? + if [[ $sed_exit_code -ne 0 ]]; then echo "Failed to replace the signaling URL, exiting." exit 1 else - echo "Successfully replaced signaling URL with '$OPENMINA_SIGNALING_URL' in $HTTPD_CONF" + echo "Successfully replaced signaling URL with" \ + "'$OPENMINA_SIGNALING_URL' in $HTTPD_CONF" fi else echo "OPENMINA_SIGNALING_URL is not set. No replacement performed." @@ -63,8 +64,11 @@ download_circuit_files() { echo "$FILE already exists in $DOWNLOAD_DIR, skipping download." else echo "Downloading $FILE to $DOWNLOAD_DIR..." - curl -s -L --retry 3 --retry-delay 5 -o "$DOWNLOAD_DIR/$FILE" "$CIRCUITS_BASE_URL/$CIRCUITS_VERSION/$FILE" - if [[ $? -ne 0 ]]; then + curl -s -L --retry 3 --retry-delay 5 \ + -o "$DOWNLOAD_DIR/$FILE" \ + "$CIRCUITS_BASE_URL/$CIRCUITS_VERSION/$FILE" + curl_exit_code=$? + if [[ $curl_exit_code -ne 0 ]]; then echo "Failed to download $FILE after 3 attempts, exiting." exit 1 else @@ -80,24 +84,28 @@ download_wasm_files() { exit 1 fi - WASM_URL="$OPENMINA_BASE_URL/openmina/releases/download/$OPENMINA_WASM_VERSION/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz" + WASM_URL="$OPENMINA_BASE_URL/openmina/releases/download/\ +$OPENMINA_WASM_VERSION/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz" TARGET_DIR="/usr/local/apache2/htdocs/assets/webnode/pkg" mkdir -p "$TARGET_DIR" echo "Downloading WASM files from $WASM_URL..." - curl -s -L --retry 3 --retry-delay 5 -o "/tmp/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz" "$WASM_URL" - - if [[ $? -ne 0 ]]; then + curl -s -L --retry 3 --retry-delay 5 \ + -o "/tmp/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz" \ + "$WASM_URL" + curl_exit_code=$? + if [[ $curl_exit_code -ne 0 ]]; then echo "Failed to download the WASM file after 3 attempts, exiting." exit 1 else echo "WASM file downloaded successfully. Extracting to $TARGET_DIR..." - tar -xzf "/tmp/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz" -C "$TARGET_DIR" - # Check if the extraction was successful - if [[ $? -ne 0 ]]; then + tar -xzf "/tmp/openmina-$OPENMINA_WASM_VERSION-webnode-wasm.tar.gz" \ + -C "$TARGET_DIR" + tar_exit_code=$? + if [[ $tar_exit_code -ne 0 ]]; then echo "Failed to extract the WASM file, exiting." exit 1 else diff --git a/frontend/scripts/download-webnode.sh b/frontend/scripts/download-webnode.sh index 619cc97347..acd0e45e0b 100644 --- a/frontend/scripts/download-webnode.sh +++ b/frontend/scripts/download-webnode.sh @@ -45,8 +45,11 @@ download_circuit_files() { echo "$FILE already exists in $DOWNLOAD_DIR, skipping download." else echo "Downloading $FILE to $DOWNLOAD_DIR..." - curl -s -L --retry 3 --retry-delay 5 -o "$DOWNLOAD_DIR/$FILE" "$CIRCUITS_BASE_URL/$CIRCUITS_VERSION/$FILE" - if [[ $? -ne 0 ]]; then + curl -s -L --retry 3 --retry-delay 5 \ + -o "$DOWNLOAD_DIR/$FILE" \ + "$CIRCUITS_BASE_URL/$CIRCUITS_VERSION/$FILE" + curl_exit_code=$? + if [[ $curl_exit_code -ne 0 ]]; then echo "Failed to download $FILE after 3 attempts, exiting." exit 1 else diff --git a/producer-dashboard/docker/init-db/init-db.sh b/producer-dashboard/docker/init-db/init-db.sh index 3293dc4a9e..9a4f66a035 100755 --- a/producer-dashboard/docker/init-db/init-db.sh +++ b/producer-dashboard/docker/init-db/init-db.sh @@ -10,12 +10,12 @@ PASSWORD=${POSTGRES_PASSWORD} # Wait for PostgreSQL to become available echo "Waiting for postgres..." -while ! pg_isready -h $HOST -p $PORT -U $USER; do +while ! pg_isready -h "$HOST" -p "$PORT" -U "$USER"; do sleep 2; done # Check if the database exists, and create it if it doesn't -if ! PGPASSWORD=$PASSWORD psql -h $HOST -U $USER -lqt | cut -d \| -f 1 | grep -qw $DB; then +if ! PGPASSWORD=$PASSWORD psql -h "$HOST" -U "$USER" -lqt | cut -d \| -f 1 | grep -qw "$DB"; then echo "Database $DB does not exist. Creating..." PGPASSWORD="$PASSWORD" createdb -h "$HOST" -U "$USER" "$DB" # Load the schema into the database @@ -24,7 +24,7 @@ if ! PGPASSWORD=$PASSWORD psql -h $HOST -U $USER -lqt | cut -d \| -f 1 | grep -q # PGPASSWORD=$PASSWORD psql -h $HOST -U $USER -d $DB < create_schema.sql # TODO cd /dumps - PGPASSWORD=$PASSWORD psql -h $HOST -U $USER -d $DB < dump.sql + PGPASSWORD=$PASSWORD psql -h "$HOST" -U "$USER" -d "$DB" < dump.sql exit 1 else echo "Database $DB already exists."