Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Add sh fmt pre commit hook (#1128)
Michael2dafb6c47777
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex 2f3288f2d..6141039f7 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -126,6 +126,11 @@ repos:hooks:- id: shellcheck+ - repo: https://github.com/scop/pre-commit-shfmt+ rev: v3.6.0-2+ hooks:+ - id: shfmt-docker+- repo: https://github.com/rhysd/actionlintrev: v1.6.24hooks:diff --git a/api/run.sh b/api/run.shindex 04a525f37..6dfdd45c3 100755--- a/api/run.sh+++ b/api/run.sh@@ -4,7 +4,7 @@ set -ees_url="http://${ELASTICSEARCH_URL:-es}:${ELASTICSEARCH_PORT:-9200}/_cluster/health"while [ "$(curl -s -o /dev/null -w '%{http_code}' "$es_url")" != "200" ]; do- echo "Waiting for Elasticsearch connection..." && sleep 5;+ echo "Waiting for Elasticsearch connection..." && sleep 5doneecho "Elasticsearch connection established!"diff --git a/catalog/entrypoint.sh b/catalog/entrypoint.shindex 128ba3afc..1ff101d75 100755--- a/catalog/entrypoint.sh+++ b/catalog/entrypoint.sh@@ -3,7 +3,7 @@set -efunction help_text() {- cat << 'END'+ cat <<'END',-. ;-. ,--. . . . , ,--. ,-. ,-. ,--./ \ | ) | |\ | | / | | ) ( ` |@@ -25,17 +25,16 @@ Usage:END}-function header() {size=${COLUMNS:-80}# Print centered text between two dividers of length $sizeprintf '#%.0s' $(seq 1 "$size") && echo- printf "%*s\n" $(( (${#1} + size) / 2)) "$1"+ printf "%*s\n" $(((${#1} + size) / 2)) "$1"printf '#%.0s' $(seq 1 "$size") && echo}if [ "$1" == help ] || [ "$1" == --help ]; then help_text && exit 0; fi-sleep 0.1; # The $COLUMNS variable takes a moment to populate+sleep 0.1 # The $COLUMNS variable takes a moment to populate# Reformat Airflow connections that use httpsheader "MODIFYING ENVIRONMENT"@@ -45,20 +44,20 @@ header "MODIFYING ENVIRONMENT"# to propagate to the outer shell.# See: https://unix.stackexchange.com/a/402752while read -r var_string; do- # get the variable name- var_name=$(expr "$var_string" : '^\([A-Z_]*\)')- echo "Variable Name: $var_name"- # get the old value- old_value=$(expr "$var_string" : '^[A-Z_]*=\(http.*\)$')- echo " Old Value: $old_value"- # call python to url encode the http clause- url_encoded=$(python -c "from urllib.parse import quote_plus; import sys; print(quote_plus(sys.argv[1]))" "$old_value")- # prepend https://- new_value='https://'$url_encoded- echo " New Value: $new_value"- # set the environment variable- export "$var_name"="$new_value"-# only include airflow connections with http somewhere in the string+ # get the variable name+ var_name=$(expr "$var_string" : '^\([A-Z_]*\)')+ echo "Variable Name: $var_name"+ # get the old value+ old_value=$(expr "$var_string" : '^[A-Z_]*=\(http.*\)$')+ echo " Old Value: $old_value"+ # call python to url encode the http clause+ url_encoded=$(python -c "from urllib.parse import quote_plus; import sys; print(quote_plus(sys.argv[1]))" "$old_value")+ # prepend https://+ new_value='https://'$url_encoded+ echo " New Value: $new_value"+ # set the environment variable+ export "$var_name"="$new_value"+ # only include airflow connections with http somewhere in the stringdone < <(env | grep "^AIRFLOW_CONN[A-Z_]\+=http.*$")exec /entrypoint "$@"diff --git a/catalog/tests/dags/providers/provider_api_scripts/resources/wikimedia/prettify.sh b/catalog/tests/dags/providers/provider_api_scripts/resources/wikimedia/prettify.shindex a96d755a9..d2874c864 100755--- a/catalog/tests/dags/providers/provider_api_scripts/resources/wikimedia/prettify.sh+++ b/catalog/tests/dags/providers/provider_api_scripts/resources/wikimedia/prettify.sh@@ -1,5 +1,5 @@#!/bin/bashT=$(mktemp)-jq '.' "$1" > "$T"+jq '.' "$1" >"$T"mv "$T" "$1"diff --git a/dag-sync.sh b/dag-sync.shindex c014ac210..165c7cb29 100755--- a/dag-sync.sh+++ b/dag-sync.sh@@ -11,7 +11,7 @@ set -eSLACK_URL=$1# https://stackoverflow.com/a/246128 via Dave Dopson CC BY-SA 4.0-SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )+SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)cd "$SCRIPT_DIR"# Update origin@@ -24,15 +24,14 @@ new=$(git rev-list --reverse --topo-order HEAD..origin/main | head -1)# Move ahead to this new commitgit reset --hard "$new"# Verify if have /dags/ in the last commit-have_dag=$(git log -p -1 "$new" --pretty=format: --name-only | grep "catalog/dags/")+have_dag=$(git log -p -1 "$new" --pretty=format: --name-only | grep "catalog/dags/")# If there is no files under /dags/ folder, no need to notify, quit early[ -z "$have_dag" ] && exit# Pull out the subject from the new commitsubject=$(git log -1 --format='%s')-if [ -z "$SLACK_URL" ]- then+if [ -z "$SLACK_URL" ]; thenecho "Slack hook was not supplied! Updates will not be posted"elsecurl "$SLACK_URL" \diff --git a/frontend/bin/create-component.sh b/frontend/bin/create-component.shindex 6edeeca68..1232db437 100755--- a/frontend/bin/create-component.sh+++ b/frontend/bin/create-component.sh@@ -1,21 +1,20 @@#!/bin/bash# $1 = the first argument in the command line-if [ -z "$1" ]- then- echo "Please enter a component name"- exit 1;- else- # transforms component name from PascalCase to kebab-case- componentNameInKebabCase=$(echo "$1" | sed 's/\(.\)\([A-Z]\)/\1-\2/g' | tr '[:upper:]' '[:lower:]')+if [ -z "$1" ]; then+ echo "Please enter a component name"+ exit 1+else+ # transforms component name from PascalCase to kebab-case+ componentNameInKebabCase=$(echo "$1" | sed 's/\(.\)\([A-Z]\)/\1-\2/g' | tr '[:upper:]' '[:lower:]')- pnpm run create:component-scaffolding "$1" "$componentNameInKebabCase"+ pnpm run create:component-scaffolding "$1" "$componentNameInKebabCase"- # comment-json package changes the code style of tsconfig.json.- # if you try to commit your newly created component,- # it will fail the first time because it won`t pass prettier checks.- # to avoid this, we are runing prettier at the end of the component creation proccess.- echo "runing Prettier on tsconfig.json..."- pnpm prettier --write tsconfig.json- echo "Completed"+ # comment-json package changes the code style of tsconfig.json.+ # if you try to commit your newly created component,+ # it will fail the first time because it won`t pass prettier checks.+ # to avoid this, we are runing prettier at the end of the component creation proccess.+ echo "runing Prettier on tsconfig.json..."+ pnpm prettier --write tsconfig.json+ echo "Completed"fidiff --git a/frontend/bin/playwright.sh b/frontend/bin/playwright.shindex cb2d8cd91..57b21fd12 100755--- a/frontend/bin/playwright.sh+++ b/frontend/bin/playwright.sh@@ -6,7 +6,7 @@ package_manager() {}version() {- pnpm ls --depth=0 | grep -e playwright | awk '{print $2}';+ pnpm ls --depth=0 | grep -e playwright | awk '{print $2}'}PACKAGE_MANAGER=$(package_manager)diff --git a/ingestion_server/test/update_mocks.sh b/ingestion_server/test/update_mocks.shindex 8efef24e6..86b771a34 100755--- a/ingestion_server/test/update_mocks.sh+++ b/ingestion_server/test/update_mocks.sh@@ -5,9 +5,9 @@# Fetch the schema for image and audio tables from the running DB hostdocker run \- --rm -i --network='host' --volume="$(pwd)/mock_schemas:/mock_schemas" \- postgres \- /bin/bash <<-EOF+ --rm -i --network='host' --volume="$(pwd)/mock_schemas:/mock_schemas" \+ postgres \+ /bin/bash <<-EOFexport PGPASSWORD=deploypg_dump -s -t image -U deploy -d openledger -h localhost > /mock_schemas/image.sqlpg_dump -s -t api_deletedimage -U deploy -d openledger -h localhost > /mock_schemas/api_deletedimage.sql@@ -31,9 +31,9 @@ sed -i "" '/search_path/d' mock_schemas/audioset_view.sql# Select some media samples and export them to CSVdocker run \- --rm --network='host' --volume="$(pwd)/mock_data:/mock_data" \- postgres \- /bin/bash -c "PGPASSWORD=deploy psql -U deploy -d openledger -h localhost -p 5433 <<-EOF+ --rm --network='host' --volume="$(pwd)/mock_data:/mock_data" \+ postgres \+ /bin/bash -c "PGPASSWORD=deploy psql -U deploy -d openledger -h localhost -p 5433 <<-EOF\copy (SELECT * FROM image_view) to '/mock_data/mocked_image_view.csv' with (FORMAT csv, HEADER true);\copy (SELECT * FROM audio_view) to '/mock_data/mocked_audio_view.csv' with (FORMAT csv, HEADER true);EOF"diff --git a/load_sample_data.sh b/load_sample_data.shindex 1a70fef89..07a157382 100755--- a/load_sample_data.sh+++ b/load_sample_data.sh@@ -82,12 +82,11 @@ just docker/es/wait-for-index "audio-filtered" "audio-init-filtered"# Image ingestion is flaky; but usually works on the next attemptset +ewhile true; do- just ingestion_server/ingest-upstream "image" "init"- if just docker/es/wait-for-index "image-init"- then- break- fi- ((c++)) && ((c==3)) && break+ just ingestion_server/ingest-upstream "image" "init"+ if just docker/es/wait-for-index "image-init"; then+ break+ fi+ ((c++)) && ((c == 3)) && breakdoneset -e@@ -103,5 +102,5 @@ just docker/es/wait-for-index "image-filtered" "image-init-filtered"########## Clear source cache since it's out of date after data has been loaded-docker-compose exec -T "$CACHE_SERVICE_NAME" bash -c "echo \"del :1:sources-image\" | redis-cli"-docker-compose exec -T "$CACHE_SERVICE_NAME" bash -c "echo \"del :1:sources-audio\" | redis-cli"+docker-compose exec -T "$CACHE_SERVICE_NAME" bash -c 'echo "del :1:sources-image" | redis-cli'+docker-compose exec -T "$CACHE_SERVICE_NAME" bash -c 'echo "del :1:sources-audio" | redis-cli'diff --git a/setup_plausible.sh b/setup_plausible.shindex 55f92cc2a..bf439d879 100755--- a/setup_plausible.sh+++ b/setup_plausible.sh@@ -6,7 +6,7 @@ PLAUSIBLE_DB_SERVICE_NAME="${PLAUSIBLE_DB_SERVICE_NAME:-plausible_db}"# Create Plausible userdocker-compose exec -T "$PLAUSIBLE_SERVICE_NAME" \/app/bin/plausible rpc \- "Plausible.Auth.User.new(%{name: \"Deploy\", email: \"[email protected]\", password: \"deploy\", password_confirmation: \"deploy\"}) |> Plausible.Repo.insert"+ 'Plausible.Auth.User.new(%{name: "Deploy", email: "[email protected]", password: "deploy", password_confirmation: "deploy"}) |> Plausible.Repo.insert'# Create an API key with '{sites:provision:*}' scope# API key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa (that's 64 times 'a')@@ -30,9 +30,9 @@ RES=$(curl \-F 'timezone="UTC"' \"$local_plausible/api/v1/sites")-if [[ "$RES" == *"\"error\":\"domain This domain has already been taken"* ]]; then+if [[ $RES == *"\"error\":\"domain This domain has already been taken"* ]]; thenecho "Domain already exists."-elif [[ "$RES" == *"\"domain\":\"localhost\""* ]]; then+elif [[ $RES == *"\"domain\":\"localhost\""* ]]; thenecho "Domain created."elseecho "Error: $RES"@@ -44,8 +44,7 @@ custom_events=$(node ./frontend/bin/get-custom-event-names.js)echo "Verifying custom events:"-for eventName in $custom_events;-do+for eventName in $custom_events; doecho "$eventName"curl \-X PUT \diff --git a/utilities/load_testing/api.sh b/utilities/load_testing/api.shindex 066874ad7..e0640307c 100755--- a/utilities/load_testing/api.sh+++ b/utilities/load_testing/api.sh@@ -3,7 +3,7 @@set -e# shellcheck source=/dev/null-source ./.env.sh || (echo "Please create a $(.env.sh) file based on the $(.env.sh.template) file." > /dev/stderr && false)+source ./.env.sh || (echo "Please create a $(.env.sh) file based on the $(.env.sh.template) file." >/dev/stderr && false)host=$1@@ -18,13 +18,13 @@ q=$(./get_word.sh)set -xab \- -w \- -v 3 \- -c $concurrency \- -n $requests \- -T "application/json" \- -H "$auth_header" \- "$host/v1/images/?$q&page_size=500" > output.html+ -w \+ -v 3 \+ -c $concurrency \+ -n $requests \+ -T "application/json" \+ -H "$auth_header" \+ "$host/v1/images/?$q&page_size=500" >output.htmlset +x