Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/blockscout/blockscout int…
Browse files Browse the repository at this point in the history
…o sync-01-13-25
  • Loading branch information
pustovalov committed Jan 15, 2025
2 parents 5b74991 + 1af4563 commit 8a9f231
Show file tree
Hide file tree
Showing 363 changed files with 14,556 additions and 6,799 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ To configure access to the PostgreSQL database using the VS Code extension:
- Password: `postgres`
- Port: `5432`
- Use an ssl connection: "Standard connection"
- Database: `blockscout`
- Database: `app`
- The display name: "<some name>"

These credentials are derived from the `DATABASE_URL` in the `bs` script.
Expand Down
149 changes: 116 additions & 33 deletions .devcontainer/bin/bs
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
#!/bin/bash

# This script helps to orchestrate typical tasks when developing Blockscout
# Blockscout Development Helper Script
#
# This script provides a unified interface for common development tasks when working
# with the Blockscout backend server. It handles environment configuration, project
# initialization, and various development workflows.
#
# Main usage scenarios:
# 1. Project Setup
# - Initialize project directory: bs --init
# - Setup/reset database: bs --db-init
#
# 2. Development Tasks
# - Run backend server: bs
# - Run server (API only): bs --no-sync
# - Compile/recompile changes: bs --compile
# - Recompile dependencies: bs --recompile
#
# 3. Code Quality
# - Run formatter: bs --format
# - Run static analysis: bs --dialyzer
# - Run code style checks: bs --credo
# - Run spell checker: bs --spellcheck
#
# 4. Documentation
# - Generate project docs: bs --docs
# - Show usage help: bs --help
#
# Environment:
# - Loads configuration from .devcontainer/.blockscout_config if present
# - Uses default DATABASE_URL if not specified
# - Supports chain-specific configurations via CHAIN_TYPE

source $(dirname $0)/utils

# cd $(dirname $0)/../../

# Source and exaport environment variables related to the backend configuration
# Source and export environment variables related to the backend configuration
BLOCKSCOUT_CONFIG_FILE=".devcontainer/.blockscout_config"
if [ -f "./${BLOCKSCOUT_CONFIG_FILE}" ]; then
set -a # Automatically export all variables
Expand All @@ -17,13 +45,14 @@ else
fi

if [ "${DATABASE_URL}" == "" ]; then
export DATABASE_URL="postgresql://postgres:postgres@db:5432/blockscout"
export DATABASE_URL="postgresql://postgres:postgres@db:5432/app"
fi

# Initialize variables
INIT=false
NO_SYNC=false
DB_INIT=false
COMPILE=false
RECOMPILE=false
SPELLCHECK=false
DIALYZER=false
Expand All @@ -32,6 +61,53 @@ FORMAT=false
DOCS=false
HELP=false

# Define the help function
show_help() {
echo "Usage: bs [OPTION]"
echo "Orchestrate typical tasks when developing Blockscout backend server"
echo
echo "Options:"
echo " --help Show this help message and exit"
echo " --init Initialize the project directory"
echo " --format Run code formatter"
echo " --spellcheck Run spellcheck"
echo " --dialyzer Run dialyzer"
echo " --credo Run credo"
echo " --docs Generate documentation"
echo " --compile Compile/recompile changes"
echo " --recompile Re-fetch dependencies and recompile"
echo " --db-init (Re)initialize the database"
echo " --no-sync Run the server with disabled indexer, so only the API is available"
echo
echo "If no option is provided, the script will run the backend server."
}

# Define valid arguments
VALID_ARGS=(
"--help"
"--init"
"--no-sync"
"--db-init"
"--compile"
"--recompile"
"--spellcheck"
"--dialyzer"
"--credo"
"--format"
"--docs"
)

# Validate arguments
for arg in "$@"
do
if [[ ! " ${VALID_ARGS[@]} " =~ " ${arg} " ]]; then
echo "Error: Unknown argument '${arg}'"
echo
show_help
exit 1
fi
done

# Parse command line arguments
for arg in "$@"
do
Expand All @@ -52,6 +128,10 @@ do
DB_INIT=true
shift # Remove --db-init from processing
;;
--compile)
COMPILE=true
shift # Remove --compile from processing
;;
--recompile)
RECOMPILE=true
shift # Remove --recompile from processing
Expand All @@ -69,7 +149,7 @@ do
shift # Remove --credo from processing
;;
--format)
FORMAT=true
FORMAT=true
shift # Remove --format from processing
;;
--docs)
Expand All @@ -79,26 +159,6 @@ do
esac
done

# Define the help function
show_help() {
echo "Usage: bs [OPTION]"
echo "Orchestrate typical tasks when developing Blockscout backend server"
echo
echo "Options:"
echo " --help Show this help message and exit"
echo " --init Initialize the project directory"
echo " --format Run code formatter"
echo " --spellcheck Run spellcheck"
echo " --dialyzer Run dialyzer"
echo " --credo Run credo"
echo " --docs Generate documentation"
echo " --recompile Re-fetch dependencies and recompile"
echo " --db-init (Re)initialize the database"
echo " --no-sync Run the server with disabled indexer, so only the API is available"
echo
echo "If no option is provided, the script will run the backend server."
}

# If --help argument is passed, show help and exit
if [ "$HELP" = true ]; then
show_help
Expand Down Expand Up @@ -130,16 +190,28 @@ initialize_project() {
# Define the initialization subroutine
initialize_db() {
echo "Initializing database. Step 1 of 2: Dropping database"
mix ecto.drop > /dev/null 2>&1
echo "Initializing database. Step 2 of 2: Creating database"
mix do ecto.create, ecto.migrate | grep Runn
if OUTPUT=$(mix ecto.drop 2>&1); then
echo "Initializing database. Step 2 of 2: Creating database"
mix do ecto.create, ecto.migrate | grep Runn
else
echo "Failed to drop database. Initialization aborted."
echo "Error output:"
echo "$OUTPUT"
return 1
fi
}

# Define the compile subroutine
compile() {
mix compile
}

# Define the recompile subroutine
recompile() {
mix deps.clean block_scout_web
mix deps.clean explorer
mix deps.clean indexer
FALLBACK_APPS="block_scout_web ethereum_jsonrpc explorer indexer utils nft_media_handler"
APPS=$($(dirname $0)/extract_apps.exs) || APPS="$FALLBACK_APPS"
[ -z "$APPS" ] && APPS="$FALLBACK_APPS"
mix deps.clean $APPS
mix deps.get
mix deps.compile --force
}
Expand All @@ -151,7 +223,12 @@ spellcheck() {

# Define the dialyzer subroutine
dialyzer() {
mix dialyzer
if ! mix dialyzer; then
echo -e "\nDepending on the error you see, try either:"
echo " rm -rf 'priv/plts'"
echo " MIX_ENV=test bs --recompile"
return 1
fi
}

# Define the credo subroutine
Expand Down Expand Up @@ -181,6 +258,12 @@ if [ "$DB_INIT" = true ]; then
exit 0
fi

# If --compile argument is passed, run the compile subroutine and exit
if [ "$COMPILE" = true ]; then
compile
exit 0
fi

# If --recompile argument is passed, run the recompile subroutine and exit
if [ "$RECOMPILE" = true ]; then
recompile
Expand Down
45 changes: 45 additions & 0 deletions .devcontainer/bin/extract_apps.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env elixir

defmodule LocalHelper do
# Helper function to safely get configuration values
def get_config_value(config, key, name) do
case Keyword.get(config, key) do
nil -> {:error, name}
value -> {:ok, value}
end
end
end

# Start Mix application
Mix.start()

# Set the Mix environment to dev (or whatever environment you need)
Mix.env(:dev)

# Read and evaluate the mix.exs file
Code.require_file("mix.exs")

# Get the applications from the project configuration
apps =
try do
project = BlockScout.Mixfile.project()

with {:ok, releases} <- LocalHelper.get_config_value(project, :releases, "releases"),
{:ok, blockscout} <- LocalHelper.get_config_value(releases, :blockscout, "blockscout release"),
{:ok, applications} <- LocalHelper.get_config_value(blockscout, :applications, "applications") do
applications
|> Keyword.keys()
|> Enum.join("\n")
else
{:error, message} ->
IO.puts(:stderr, "Error: #{message} not found in mix.exs configuration")
System.halt(1)
end
rescue
error ->
IO.puts(:stderr, "Error: Failed to read mix.exs configuration - #{Exception.message(error)}")
System.halt(1)
end

# Print the applications to stdout
IO.puts(apps)
2 changes: 1 addition & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
command: sleep infinity

db:
image: postgres:latest
image: postgres:17
command: postgres -c 'max_connections=250'
restart: unless-stopped
volumes:
Expand Down
3 changes: 3 additions & 0 deletions .dialyzer-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ lib/explorer/smart_contract/solidity/publisher_worker.ex:8
lib/explorer/smart_contract/vyper/publisher_worker.ex:8
lib/explorer/smart_contract/stylus/publisher_worker.ex:8
lib/phoenix/router.ex:402
lib/explorer/chain/search.ex:80
lib/explorer/chain/search.ex:183
lib/explorer/chain/search.ex:271
22 changes: 22 additions & 0 deletions .github/workflows/antiscam.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: antiscam

on:
issue_comment:
types:
- created
- edited

permissions:
pull-requests: write
issues: write

jobs:
build:
if: ${{ !github.event.issue.pull_request }}
name: Antiscam
runs-on: ubuntu-latest

steps:
- uses: vbaranov/antiscam-action@main
with:
token: ${{ github.token }}
22 changes: 22 additions & 0 deletions .github/workflows/antispam.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: antispam

on:
issues:
types:
- opened
- edited
- reopened

permissions:
pull-requests: write
issues: write

jobs:
build:
name: Antispam
runs-on: ubuntu-latest

steps:
- uses: vbaranov/antispam-action@main
with:
token: ${{ github.token }}
8 changes: 4 additions & 4 deletions .github/workflows/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ jobs:
- matrix-builder
services:
postgres:
image: postgres:15
image: postgres:17
env:
# Match apps/explorer/config/test.exs config :explorer, Explorer.Repo, database
POSTGRES_DB: explorer_test
Expand Down Expand Up @@ -561,7 +561,7 @@ jobs:
- matrix-builder
services:
postgres:
image: postgres:15
image: postgres:17
env:
# Match apps/explorer/config/test.exs config :explorer, Explorer.Repo, database
POSTGRES_DB: explorer_test
Expand Down Expand Up @@ -636,7 +636,7 @@ jobs:
- matrix-builder
services:
postgres:
image: postgres:15
image: postgres:17
env:
# Match apps/explorer/config/test.exs config :explorer, Explorer.Repo, database
POSTGRES_DB: explorer_test
Expand Down Expand Up @@ -708,7 +708,7 @@ jobs:
- 6379:6379

postgres:
image: postgres:15
image: postgres:17
env:
# Match apps/explorer/config/test.exs config :explorer, Explorer.Repo, database
POSTGRES_DB: explorer_test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-release-arbitrum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
env:
RELEASE_VERSION: 6.9.2
RELEASE_VERSION: 6.10.1
steps:
- uses: actions/checkout@v4
- name: Setup repo
Expand Down
Loading

0 comments on commit 8a9f231

Please sign in to comment.