From 430083867a122f53608dc2bca93dae14ccbcc532 Mon Sep 17 00:00:00 2001 From: Jean-Paul van Ravensberg <14926452+DevSecNinja@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:34:29 +0100 Subject: [PATCH] style(scripts): format shell scripts and fix shellcheck findings Reformat every shell script with shfmt 3.14.1 under the central .editorconfig (4-space indent for *.sh) and apply shellcheck 0.11.0's autofixes for SC2250/SC2248 under the central .shellcheckrc. The five SC2312 notes are resolved without changing failure behaviour: command substitutions whose failure was already masked are split out with `|| true`, and the two `docker exec ... | grep -q` probes, where `timeout` is expected to stop index-now, get a justified directive. Ships the central .editorconfig and .shellcheckrc (identical to the config-sync PR #450) so this PR's lint run enforces the result. Closes #451 --- .devcontainer/post-create.sh | 20 +++--- .devcontainer/post-start.sh | 6 +- .editorconfig | 15 ++++- .github/scripts/check-if-prerelease.sh | 8 +-- .github/scripts/cleanup-containers.sh | 8 +-- .github/scripts/create-github-release.sh | 16 ++--- .github/scripts/download-search-index.sh | 7 +- .github/scripts/extract-version.sh | 44 ++++++------- .github/scripts/publish-db-release.sh | 44 ++++++------- .github/scripts/start-backend-container.sh | 14 ++-- .github/scripts/start-container.sh | 18 ++--- .../scripts/start-integration-containers.sh | 14 ++-- .github/scripts/test-backend-api.sh | 44 ++++++------- .github/scripts/test-frontend.sh | 46 ++++++------- .github/scripts/test-index-now.sh | 14 ++-- .github/scripts/test-integration.sh | 26 ++++---- .github/scripts/validate-version.sh | 16 ++--- .github/scripts/wait-for-healthy.sh | 29 +++++---- .shellcheckrc | 8 +++ backend/entrypoint.sh | 8 +-- setup.sh | 65 ++++++++++--------- start.sh | 12 ++-- stop.sh | 44 ++++++------- 23 files changed, 275 insertions(+), 251 deletions(-) create mode 100644 .shellcheckrc diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index f5c18337..ecef999a 100755 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -34,17 +34,17 @@ cd ../frontend npm install # Create .env.local for devcontainer -if [ -n "$CODESPACE_NAME" ]; then - # GitHub Codespaces - CODESPACE_URL="https://${CODESPACE_NAME}-8080.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}" - echo "📝 Creating .env.local with Codespace URL..." - echo "NEXT_PUBLIC_API_URL=${CODESPACE_URL}/api/v1" >.env.local - echo "✅ .env.local created with Codespace URL: ${CODESPACE_URL}/api/v1" +if [ -n "${CODESPACE_NAME}" ]; then + # GitHub Codespaces + CODESPACE_URL="https://${CODESPACE_NAME}-8080.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}" + echo "📝 Creating .env.local with Codespace URL..." + echo "NEXT_PUBLIC_API_URL=${CODESPACE_URL}/api/v1" >.env.local + echo "✅ .env.local created with Codespace URL: ${CODESPACE_URL}/api/v1" else - # Local devcontainer or other environment - echo "📝 Creating .env.local for local development..." - echo "NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1" >.env.local - echo "✅ .env.local created with local URL" + # Local devcontainer or other environment + echo "📝 Creating .env.local for local development..." + echo "NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1" >.env.local + echo "✅ .env.local created with local URL" fi echo "✅ Frontend setup complete!" diff --git a/.devcontainer/post-start.sh b/.devcontainer/post-start.sh index 67d52cbb..ff6f701d 100755 --- a/.devcontainer/post-start.sh +++ b/.devcontainer/post-start.sh @@ -10,10 +10,10 @@ nohup npm run dev >/tmp/frontend-dev.log 2>&1 & sleep 3 if pgrep -f "next dev" >/dev/null; then - echo "✅ Frontend dev server started at http://localhost:8080" - echo "📋 View logs: tail -f /tmp/frontend-dev.log" + echo "✅ Frontend dev server started at http://localhost:8080" + echo "📋 View logs: tail -f /tmp/frontend-dev.log" else - echo "⚠️ Frontend dev server failed to start. Check logs: cat /tmp/frontend-dev.log" + echo "⚠️ Frontend dev server failed to start. Check logs: cat /tmp/frontend-dev.log" fi echo "" diff --git a/.editorconfig b/.editorconfig index eb8bbc74..2e450828 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,9 +1,18 @@ -# top-most EditorConfig file +; https://editorconfig.org/ + root = true -[*.ext] +[*] +indent_style = space +indent_size = 2 end_of_line = lf charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true -indent_style = space +[*.md] +indent_size = 4 +trim_trailing_whitespace = false + +[*.sh] indent_size = 4 diff --git a/.github/scripts/check-if-prerelease.sh b/.github/scripts/check-if-prerelease.sh index dd64be7b..bd46b12f 100755 --- a/.github/scripts/check-if-prerelease.sh +++ b/.github/scripts/check-if-prerelease.sh @@ -8,11 +8,11 @@ VERSION="$1" MANUAL_PRERELEASE="${2:-false}" # Extract version without v prefix -VERSION_NUM=$(echo "$VERSION" | grep -oP '\d+\.\d+\.\d+.*' || echo "$VERSION") +VERSION_NUM=$(echo "${VERSION}" | grep -oP '\d+\.\d+\.\d+.*' || echo "${VERSION}") # Check if version contains prerelease identifiers or if manually set -if [[ "$MANUAL_PRERELEASE" == "true" ]] || [[ "$VERSION_NUM" =~ -alpha|-beta|-rc|-pre ]]; then - echo "is_prerelease=true" +if [[ "${MANUAL_PRERELEASE}" == "true" ]] || [[ "${VERSION_NUM}" =~ -alpha|-beta|-rc|-pre ]]; then + echo "is_prerelease=true" else - echo "is_prerelease=false" + echo "is_prerelease=false" fi diff --git a/.github/scripts/cleanup-containers.sh b/.github/scripts/cleanup-containers.sh index ddf11390..43e2c841 100755 --- a/.github/scripts/cleanup-containers.sh +++ b/.github/scripts/cleanup-containers.sh @@ -5,13 +5,13 @@ set -e if [ $# -eq 0 ]; then - echo "Usage: $0 [container2] [container3...]" - exit 1 + echo "Usage: $0 [container2] [container3...]" + exit 1 fi for CONTAINER in "$@"; do - echo "Removing container ${CONTAINER}..." - docker rm -f "${CONTAINER}" 2>&1 || true + echo "Removing container ${CONTAINER}..." + docker rm -f "${CONTAINER}" 2>&1 || true done echo "✓ Cleanup complete" diff --git a/.github/scripts/create-github-release.sh b/.github/scripts/create-github-release.sh index 4ed4b28d..ba7597f6 100755 --- a/.github/scripts/create-github-release.sh +++ b/.github/scripts/create-github-release.sh @@ -13,10 +13,10 @@ set -euo pipefail # Fetch auto-generated release notes from GitHub API GENERATED_NOTES=$(gh api \ - --method POST \ - "/repos/${GITHUB_REPOSITORY}/releases/generate-notes" \ - -f "tag_name=${VERSION_TAG}" \ - --jq '.body') + --method POST \ + "/repos/${GITHUB_REPOSITORY}/releases/generate-notes" \ + -f "tag_name=${VERSION_TAG}" \ + --jq '.body') # Write the full release notes to a temp file RELEASE_NOTES_FILE=$(mktemp) @@ -34,13 +34,13 @@ EOF # Build gh CLI argument list GH_ARGS=( - "${VERSION_TAG}" - --title "${VERSION}" - --notes-file "${RELEASE_NOTES_FILE}" + "${VERSION_TAG}" + --title "${VERSION}" + --notes-file "${RELEASE_NOTES_FILE}" ) if [[ "${IS_PRERELEASE}" == "true" ]]; then - GH_ARGS+=(--prerelease) + GH_ARGS+=(--prerelease) fi gh release create "${GH_ARGS[@]}" diff --git a/.github/scripts/download-search-index.sh b/.github/scripts/download-search-index.sh index 9db21b0a..0432a08c 100755 --- a/.github/scripts/download-search-index.sh +++ b/.github/scripts/download-search-index.sh @@ -10,11 +10,12 @@ SEARCH_INDEX_URL="${SEARCH_INDEX_URL:-https://github.com/${GITHUB_REPOSITORY}/re mkdir -p "$(dirname "${SEARCH_INDEX_PATH}")" if curl -fsSL "${SEARCH_INDEX_URL}" -o "${SEARCH_INDEX_PATH}"; then - echo "Downloaded search index from ${SEARCH_INDEX_URL}" - exit 0 + echo "Downloaded search index from ${SEARCH_INDEX_URL}" + exit 0 fi echo "Warning: could not download ${SEARCH_INDEX_URL}; writing empty search index." +generated_at="$(date -u +%Y-%m-%dT%H:%M:%SZ || true)" cat >"${SEARCH_INDEX_PATH}" <. - if [ -z "$PR_NUMBER" ]; then - echo "Error: PR_NUMBER required for pull_request event" - exit 1 - fi - SHORT_SHA=$(git rev-parse --short HEAD) - VERSION="0.0.0-pr.${PR_NUMBER}.${SHORT_SHA}" - VERSION_TAG="pr-${PR_NUMBER}" -elif [ "$EVENT_NAME" = "workflow_dispatch" ]; then - if [ -z "$INPUT_VERSION" ]; then - echo "Error: version input required for workflow_dispatch event" - exit 1 - fi - VERSION="${PR_NUMBER}" # PR_NUMBER is actually INPUT_VERSION for workflow_dispatch - VERSION_TAG="v${VERSION}" -elif [ -n "$GIT_REF" ]; then - # Extract version from tag (e.g., v1.0.0 -> 1.0.0) - VERSION=${GIT_REF#refs/tags/v} - VERSION_TAG=${GIT_REF#refs/tags/} +if [ "${EVENT_NAME}" = "pull_request" ]; then + # For PRs, use format: 0.0.0-pr.. + if [ -z "${PR_NUMBER}" ]; then + echo "Error: PR_NUMBER required for pull_request event" + exit 1 + fi + SHORT_SHA=$(git rev-parse --short HEAD) + VERSION="0.0.0-pr.${PR_NUMBER}.${SHORT_SHA}" + VERSION_TAG="pr-${PR_NUMBER}" +elif [ "${EVENT_NAME}" = "workflow_dispatch" ]; then + if [ -z "${INPUT_VERSION}" ]; then + echo "Error: version input required for workflow_dispatch event" + exit 1 + fi + VERSION="${PR_NUMBER}" # PR_NUMBER is actually INPUT_VERSION for workflow_dispatch + VERSION_TAG="v${VERSION}" +elif [ -n "${GIT_REF}" ]; then + # Extract version from tag (e.g., v1.0.0 -> 1.0.0) + VERSION=${GIT_REF#refs/tags/v} + VERSION_TAG=${GIT_REF#refs/tags/} else - echo "Error: Invalid arguments for event $EVENT_NAME" - exit 1 + echo "Error: Invalid arguments for event ${EVENT_NAME}" + exit 1 fi echo "version=${VERSION}" diff --git a/.github/scripts/publish-db-release.sh b/.github/scripts/publish-db-release.sh index d64ab2cf..a832d050 100755 --- a/.github/scripts/publish-db-release.sh +++ b/.github/scripts/publish-db-release.sh @@ -21,13 +21,13 @@ LATEST_TAG="db-latest" DATED_TAG="db-$(date -u +%Y-%m-%d)" if [ ! -f "${DB_FILE}" ]; then - echo "Error: Database file '${DB_FILE}' not found." - exit 1 + echo "Error: Database file '${DB_FILE}' not found." + exit 1 fi if [ ! -f "${SEARCH_INDEX_FILE}" ]; then - echo "Error: Search index file '${SEARCH_INDEX_FILE}' not found." - exit 1 + echo "Error: Search index file '${SEARCH_INDEX_FILE}' not found." + exit 1 fi RELEASE_BODY="Static search data and archived SQLite database updated by GitHub Actions. @@ -46,30 +46,30 @@ https://github.com/${GITHUB_REPOSITORY}/releases/download/${LATEST_TAG}/hadiscov # --- Rolling latest release --- if gh release view "${LATEST_TAG}" &>/dev/null; then - echo "Updating existing '${LATEST_TAG}' release assets..." - gh release upload "${LATEST_TAG}" "${DB_FILE}" "${SEARCH_INDEX_FILE}" --clobber + echo "Updating existing '${LATEST_TAG}' release assets..." + gh release upload "${LATEST_TAG}" "${DB_FILE}" "${SEARCH_INDEX_FILE}" --clobber else - echo "Creating '${LATEST_TAG}' release..." - gh release create "${LATEST_TAG}" \ - --title "Latest Search Data" \ - --notes "${RELEASE_BODY}" \ - --prerelease \ - "${DB_FILE}" \ - "${SEARCH_INDEX_FILE}" + echo "Creating '${LATEST_TAG}' release..." + gh release create "${LATEST_TAG}" \ + --title "Latest Search Data" \ + --notes "${RELEASE_BODY}" \ + --prerelease \ + "${DB_FILE}" \ + "${SEARCH_INDEX_FILE}" fi echo "✓ Published to '${LATEST_TAG}'" # --- Dated snapshot release --- if gh release view "${DATED_TAG}" &>/dev/null; then - echo "Updating existing '${DATED_TAG}' release assets..." - gh release upload "${DATED_TAG}" "${DB_FILE}" "${SEARCH_INDEX_FILE}" --clobber + echo "Updating existing '${DATED_TAG}' release assets..." + gh release upload "${DATED_TAG}" "${DB_FILE}" "${SEARCH_INDEX_FILE}" --clobber else - echo "Creating '${DATED_TAG}' release..." - gh release create "${DATED_TAG}" \ - --title "Search Data ${DATED_TAG#db-}" \ - --notes "${RELEASE_BODY}" \ - --prerelease \ - "${DB_FILE}" \ - "${SEARCH_INDEX_FILE}" + echo "Creating '${DATED_TAG}' release..." + gh release create "${DATED_TAG}" \ + --title "Search Data ${DATED_TAG#db-}" \ + --notes "${RELEASE_BODY}" \ + --prerelease \ + "${DB_FILE}" \ + "${SEARCH_INDEX_FILE}" fi echo "✓ Published to '${DATED_TAG}'" diff --git a/.github/scripts/start-backend-container.sh b/.github/scripts/start-backend-container.sh index c9308c10..30e7c8d3 100755 --- a/.github/scripts/start-backend-container.sh +++ b/.github/scripts/start-backend-container.sh @@ -8,17 +8,17 @@ CONTAINER_NAME="${1}" IMAGE_TAG="${2}" PORT="${3:-8000}" -if [ -z "$CONTAINER_NAME" ] || [ -z "$IMAGE_TAG" ]; then - echo "Usage: $0 [port]" - exit 1 +if [ -z "${CONTAINER_NAME}" ] || [ -z "${IMAGE_TAG}" ]; then + echo "Usage: $0 [port]" + exit 1 fi echo "Starting backend container ${CONTAINER_NAME} from image ${IMAGE_TAG}..." docker run -d \ - --name "${CONTAINER_NAME}" \ - -p "${PORT}:8000" \ - -e ENVIRONMENT=development \ - "${IMAGE_TAG}" + --name "${CONTAINER_NAME}" \ + -p "${PORT}:8000" \ + -e ENVIRONMENT=development \ + "${IMAGE_TAG}" echo "✓ Backend container ${CONTAINER_NAME} started" diff --git a/.github/scripts/start-container.sh b/.github/scripts/start-container.sh index 9fd4c4c6..5fba2f84 100755 --- a/.github/scripts/start-container.sh +++ b/.github/scripts/start-container.sh @@ -10,17 +10,17 @@ PORT_MAPPING="${3}" shift 3 ADDITIONAL_ARGS="$*" -if [ -z "$CONTAINER_NAME" ] || [ -z "$IMAGE_TAG" ]; then - echo "Usage: $0 [additional-docker-run-args...]" - exit 1 +if [ -z "${CONTAINER_NAME}" ] || [ -z "${IMAGE_TAG}" ]; then + echo "Usage: $0 [additional-docker-run-args...]" + exit 1 fi -echo "Starting container $CONTAINER_NAME from image $IMAGE_TAG..." +echo "Starting container ${CONTAINER_NAME} from image ${IMAGE_TAG}..." # shellcheck disable=SC2086 -docker run -d --name "$CONTAINER_NAME" \ - -p "$PORT_MAPPING" \ - $ADDITIONAL_ARGS \ - "$IMAGE_TAG" +docker run -d --name "${CONTAINER_NAME}" \ + -p "${PORT_MAPPING}" \ + ${ADDITIONAL_ARGS} \ + "${IMAGE_TAG}" -echo "✓ Container $CONTAINER_NAME started" +echo "✓ Container ${CONTAINER_NAME} started" diff --git a/.github/scripts/start-integration-containers.sh b/.github/scripts/start-integration-containers.sh index c8fa5420..9a35abf5 100755 --- a/.github/scripts/start-integration-containers.sh +++ b/.github/scripts/start-integration-containers.sh @@ -7,17 +7,17 @@ set -e BACKEND_IMAGE="${1}" FRONTEND_IMAGE="${2}" -if [ -z "$BACKEND_IMAGE" ] || [ -z "$FRONTEND_IMAGE" ]; then - echo "Usage: $0 " - exit 1 +if [ -z "${BACKEND_IMAGE}" ] || [ -z "${FRONTEND_IMAGE}" ]; then + echo "Usage: $0 " + exit 1 fi echo "Starting backend container..." docker run -d \ - --name hadiscover-backend \ - -p 8000:8000 \ - -e ENVIRONMENT=development \ - "${BACKEND_IMAGE}" + --name hadiscover-backend \ + -p 8000:8000 \ + -e ENVIRONMENT=development \ + "${BACKEND_IMAGE}" echo "Starting frontend container..." .github/scripts/start-container.sh hadiscover-frontend "${FRONTEND_IMAGE}" 8080:80 diff --git a/.github/scripts/test-backend-api.sh b/.github/scripts/test-backend-api.sh index 8365eab1..a338e57e 100755 --- a/.github/scripts/test-backend-api.sh +++ b/.github/scripts/test-backend-api.sh @@ -12,57 +12,57 @@ echo "Testing API endpoints on ${BASE_URL}..." # Test root endpoint echo "Testing root endpoint..." root_response=$(curl -s "${BASE_URL}/") -echo "Root endpoint response: $root_response" -if ! echo "$root_response" | grep -q "hadiscover API"; then - echo "✗ Root endpoint test failed" - exit 1 +echo "Root endpoint response: ${root_response}" +if ! echo "${root_response}" | grep -q "hadiscover API"; then + echo "✗ Root endpoint test failed" + exit 1 fi echo "✓ Root endpoint works" # Test health endpoint echo "Testing health endpoint..." health_response=$(curl -s "${BASE_URL}/api/v1/health") -echo "Health endpoint response: $health_response" -if ! echo "$health_response" | grep -q "healthy"; then - echo "✗ Health endpoint test failed" - exit 1 +echo "Health endpoint response: ${health_response}" +if ! echo "${health_response}" | grep -q "healthy"; then + echo "✗ Health endpoint test failed" + exit 1 fi echo "✓ Health endpoint works" # Test version in root endpoint echo "Testing version field..." -if ! echo "$root_response" | grep -q "version"; then - echo "✗ Version field not found in root endpoint" - exit 1 +if ! echo "${root_response}" | grep -q "version"; then + echo "✗ Version field not found in root endpoint" + exit 1 fi echo "✓ Version field present" # Test statistics endpoint echo "Testing statistics endpoint..." response=$(curl -s "${BASE_URL}/api/v1/statistics") -echo "Statistics endpoint response: $response" -if ! echo "$response" | grep -q "total_repositories"; then - echo "✗ Statistics endpoint test failed" - exit 1 +echo "Statistics endpoint response: ${response}" +if ! echo "${response}" | grep -q "total_repositories"; then + echo "✗ Statistics endpoint test failed" + exit 1 fi echo "✓ Statistics endpoint works" # Test search endpoint echo "Testing search endpoint..." response=$(curl -s "${BASE_URL}/api/v1/search?q=test") -echo "Search endpoint response: $response" -if ! echo "$response" | grep -q "results"; then - echo "✗ Search endpoint test failed" - exit 1 +echo "Search endpoint response: ${response}" +if ! echo "${response}" | grep -q "results"; then + echo "✗ Search endpoint test failed" + exit 1 fi echo "✓ Search endpoint works" # Test OpenAPI docs endpoint echo "Testing OpenAPI docs endpoint..." status=$(curl -s -o /dev/null -w "%{http_code}" "${BASE_URL}/docs") -if [ "$status" != "200" ]; then - echo "✗ OpenAPI docs endpoint returned status $status" - exit 1 +if [ "${status}" != "200" ]; then + echo "✗ OpenAPI docs endpoint returned status ${status}" + exit 1 fi echo "✓ OpenAPI docs endpoint works" diff --git a/.github/scripts/test-frontend.sh b/.github/scripts/test-frontend.sh index 157825ad..13ff8c7b 100755 --- a/.github/scripts/test-frontend.sh +++ b/.github/scripts/test-frontend.sh @@ -12,18 +12,18 @@ echo "Testing frontend web server on ${BASE_URL}..." # Test root endpoint echo "Testing root endpoint..." status=$(curl -s -o /dev/null -w "%{http_code}" "${BASE_URL}/") -if [ "$status" != "200" ]; then - echo "✗ Frontend root endpoint returned status $status" - exit 1 +if [ "${status}" != "200" ]; then + echo "✗ Frontend root endpoint returned status ${status}" + exit 1 fi -echo "✓ Frontend root endpoint works (status: $status)" +echo "✓ Frontend root endpoint works (status: ${status})" # Test that HTML is served echo "Testing HTML content..." response=$(curl -s "${BASE_URL}/") -if ! echo "$response" | grep -q ""; then - echo "✗ Frontend does not serve HTML" - exit 1 +if ! echo "${response}" | grep -q ""; then + echo "✗ Frontend does not serve HTML" + exit 1 fi echo "✓ Frontend serves HTML correctly" @@ -31,39 +31,39 @@ echo "✓ Frontend serves HTML correctly" echo "Testing security headers..." headers=$(curl -s -I "${BASE_URL}/") -if ! echo "$headers" | grep -qi "X-Frame-Options"; then - echo "✗ X-Frame-Options header missing" - exit 1 +if ! echo "${headers}" | grep -qi "X-Frame-Options"; then + echo "✗ X-Frame-Options header missing" + exit 1 fi echo "✓ X-Frame-Options header present" -if ! echo "$headers" | grep -qi "X-Content-Type-Options"; then - echo "✗ X-Content-Type-Options header missing" - exit 1 +if ! echo "${headers}" | grep -qi "X-Content-Type-Options"; then + echo "✗ X-Content-Type-Options header missing" + exit 1 fi echo "✓ X-Content-Type-Options header present" -if ! echo "$headers" | grep -qi "Content-Security-Policy"; then - echo "✗ Content-Security-Policy header missing" - exit 1 +if ! echo "${headers}" | grep -qi "Content-Security-Policy"; then + echo "✗ Content-Security-Policy header missing" + exit 1 fi echo "✓ Content-Security-Policy header present" # Test health endpoint echo "Testing health endpoint..." health_status=$(curl -s -o /dev/null -w "%{http_code}" "${BASE_URL}/health.html") -if [ "$health_status" != "200" ]; then - echo "✗ Health endpoint returned status $health_status" - exit 1 +if [ "${health_status}" != "200" ]; then + echo "✗ Health endpoint returned status ${health_status}" + exit 1 fi -echo "✓ Health endpoint works (status: $health_status)" +echo "✓ Health endpoint works (status: ${health_status})" # Test 404 handling for invalid paths echo "Testing 404 handling..." not_found_status=$(curl -s -o /dev/null -w "%{http_code}" "${BASE_URL}/this-page-does-not-exist") -if [ "$not_found_status" != "404" ]; then - echo "✗ Invalid path returned status $not_found_status instead of 404" - exit 1 +if [ "${not_found_status}" != "404" ]; then + echo "✗ Invalid path returned status ${not_found_status} instead of 404" + exit 1 fi echo "✓ 404 handling works correctly" diff --git a/.github/scripts/test-index-now.sh b/.github/scripts/test-index-now.sh index 98d88372..ffdc405e 100755 --- a/.github/scripts/test-index-now.sh +++ b/.github/scripts/test-index-now.sh @@ -6,9 +6,9 @@ set -e CONTAINER_NAME="${1}" -if [ -z "$CONTAINER_NAME" ]; then - echo "Usage: $0 " - exit 1 +if [ -z "${CONTAINER_NAME}" ]; then + echo "Usage: $0 " + exit 1 fi echo "Testing index-now command in container..." @@ -21,9 +21,11 @@ docker exec "${CONTAINER_NAME}" which index-now docker exec "${CONTAINER_NAME}" timeout 10 index-now 2>&1 | head -20 || true # Verify the command started the indexing process +# timeout stops index-now with a non-zero exit; only grep's result matters here. +# shellcheck disable=SC2312 if docker exec "${CONTAINER_NAME}" timeout 10 index-now 2>&1 | grep -q "Starting indexing job"; then - echo "✓ index-now command executed successfully" + echo "✓ index-now command executed successfully" else - echo "✗ index-now command failed to start" - exit 1 + echo "✗ index-now command failed to start" + exit 1 fi diff --git a/.github/scripts/test-integration.sh b/.github/scripts/test-integration.sh index 9367fff7..ba048a75 100755 --- a/.github/scripts/test-integration.sh +++ b/.github/scripts/test-integration.sh @@ -8,35 +8,37 @@ echo "Testing that both services are running together..." # Test backend is accessible backend_status=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8000/api/v1/health) -if [ "$backend_status" != "200" ]; then - echo "✗ Backend not accessible (status: $backend_status)" - exit 1 +if [ "${backend_status}" != "200" ]; then + echo "✗ Backend not accessible (status: ${backend_status})" + exit 1 fi echo "✓ Backend accessible" # Test frontend is accessible frontend_status=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/) -if [ "$frontend_status" != "200" ]; then - echo "✗ Frontend not accessible (status: $frontend_status)" - exit 1 +if [ "${frontend_status}" != "200" ]; then + echo "✗ Frontend not accessible (status: ${frontend_status})" + exit 1 fi echo "✓ Frontend accessible" # Test index-now command in backend container echo "Testing index-now command..." if docker exec hadiscover-backend which index-now >/dev/null 2>&1; then - echo "✓ index-now command found in PATH" + echo "✓ index-now command found in PATH" else - echo "✗ index-now command not found in PATH" - exit 1 + echo "✗ index-now command not found in PATH" + exit 1 fi # Test that index-now can be executed +# timeout stops index-now with a non-zero exit; only grep's result matters here. +# shellcheck disable=SC2312 if docker exec hadiscover-backend timeout 5 index-now 2>&1 | grep -q "Starting indexing job"; then - echo "✓ index-now command executes correctly" + echo "✓ index-now command executes correctly" else - echo "✗ index-now command failed to execute" - exit 1 + echo "✗ index-now command failed to execute" + exit 1 fi echo "✓ Integration test passed - both services running successfully" diff --git a/.github/scripts/validate-version.sh b/.github/scripts/validate-version.sh index 955d3e10..267f5a53 100755 --- a/.github/scripts/validate-version.sh +++ b/.github/scripts/validate-version.sh @@ -6,16 +6,16 @@ set -e VERSION="${1}" -if [ -z "$VERSION" ]; then - echo "Usage: $0 " - exit 1 +if [ -z "${VERSION}" ]; then + echo "Usage: $0 " + exit 1 fi # Check if version matches semantic versioning format (X.Y.Z or X.Y.Z-suffix) -if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*)?$'; then - echo "✗ Invalid version format: $VERSION" - echo "Version must follow semantic versioning (e.g., 1.0.0, 1.2.3-beta.1)" - exit 1 +if ! echo "${VERSION}" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*)?$'; then + echo "✗ Invalid version format: ${VERSION}" + echo "Version must follow semantic versioning (e.g., 1.0.0, 1.2.3-beta.1)" + exit 1 fi -echo "✓ Version format is valid: $VERSION" +echo "✓ Version format is valid: ${VERSION}" diff --git a/.github/scripts/wait-for-healthy.sh b/.github/scripts/wait-for-healthy.sh index 8008ac01..92156f66 100755 --- a/.github/scripts/wait-for-healthy.sh +++ b/.github/scripts/wait-for-healthy.sh @@ -7,24 +7,25 @@ set -e CONTAINER_NAME="${1}" TIMEOUT="${2:-60}" -if [ -z "$CONTAINER_NAME" ]; then - echo "Usage: $0 [timeout-seconds]" - exit 1 +if [ -z "${CONTAINER_NAME}" ]; then + echo "Usage: $0 [timeout-seconds]" + exit 1 fi -echo "Waiting for $CONTAINER_NAME container to be healthy..." +echo "Waiting for ${CONTAINER_NAME} container to be healthy..." elapsed=0 -while [ $elapsed -lt "$TIMEOUT" ]; do - if [ "$(docker inspect --format='{{.State.Health.Status}}' "$CONTAINER_NAME" 2>/dev/null)" = "healthy" ]; then - echo "✓ $CONTAINER_NAME container is healthy" - exit 0 - fi - echo "Waiting... ($elapsed seconds)" - sleep 5 - elapsed=$((elapsed + 5)) +while [ "${elapsed}" -lt "${TIMEOUT}" ]; do + health_status="$(docker inspect --format='{{.State.Health.Status}}' "${CONTAINER_NAME}" 2>/dev/null || true)" + if [ "${health_status}" = "healthy" ]; then + echo "✓ ${CONTAINER_NAME} container is healthy" + exit 0 + fi + echo "Waiting... (${elapsed} seconds)" + sleep 5 + elapsed=$((elapsed + 5)) done -echo "✗ $CONTAINER_NAME container health check timeout" -docker logs "$CONTAINER_NAME" +echo "✗ ${CONTAINER_NAME} container health check timeout" +docker logs "${CONTAINER_NAME}" exit 1 diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 00000000..cf3fc320 --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,8 @@ +# Default shell dialect; individual scripts override this via their shebang +shell=bash + +# Error severity: error, warning, info, style (default: style — show everything) +severity=style + +# Enable optional checks not on by default +enable=add-default-case,avoid-nullary-conditions,check-extra-masked-returns,check-set-e-suppressed,deprecate-which,quote-safe-variables,require-variable-braces diff --git a/backend/entrypoint.sh b/backend/entrypoint.sh index c5bc51ca..4eef95e9 100755 --- a/backend/entrypoint.sh +++ b/backend/entrypoint.sh @@ -5,9 +5,9 @@ set -e # Supports running as a web server or as a one-time indexing job if [ "$1" = "index-now" ]; then - echo "Running indexing job..." - exec python -m app.cli index-now + echo "Running indexing job..." + exec python -m app.cli index-now else - echo "Starting web server..." - exec uvicorn app.main:app --host 0.0.0.0 --port 8000 + echo "Starting web server..." + exec uvicorn app.main:app --host 0.0.0.0 --port 8000 fi diff --git a/setup.sh b/setup.sh index 8ba45522..bcd5af10 100755 --- a/setup.sh +++ b/setup.sh @@ -19,23 +19,24 @@ NC='\033[0m' # No Color # Check if Python 3.12+ is available echo "Checking Python version..." if ! command -v python3 &>/dev/null; then - echo -e "${RED}✗ Python 3 is not installed${NC}" - exit 1 + echo -e "${RED}✗ Python 3 is not installed${NC}" + exit 1 fi -PYTHON_VERSION=$(python3 --version | cut -d' ' -f2) -echo -e "${GREEN}✓ Python $PYTHON_VERSION found${NC}" +python_version_output="$(python3 --version || true)" +PYTHON_VERSION=$(cut -d' ' -f2 <<<"${python_version_output}") +echo -e "${GREEN}✓ Python ${PYTHON_VERSION} found${NC}" echo "" # Check if Node.js is available echo "Checking Node.js version..." if ! command -v node &>/dev/null; then - echo -e "${RED}✗ Node.js is not installed${NC}" - exit 1 + echo -e "${RED}✗ Node.js is not installed${NC}" + exit 1 fi NODE_VERSION=$(node --version) -echo -e "${GREEN}✓ Node.js $NODE_VERSION found${NC}" +echo -e "${GREEN}✓ Node.js ${NODE_VERSION} found${NC}" echo "" # Setup Backend @@ -48,11 +49,11 @@ cd backend # Create virtual environment if it doesn't exist if [ ! -d "venv" ]; then - echo "Creating Python virtual environment..." - python3 -m venv venv - echo -e "${GREEN}✓ Virtual environment created${NC}" + echo "Creating Python virtual environment..." + python3 -m venv venv + echo -e "${GREEN}✓ Virtual environment created${NC}" else - echo -e "${YELLOW}Virtual environment already exists${NC}" + echo -e "${YELLOW}Virtual environment already exists${NC}" fi # Activate virtual environment @@ -67,17 +68,17 @@ pip install --upgrade pip --quiet # Install dependencies echo "Installing backend dependencies..." if [ -f "requirements.txt" ]; then - pip install -r requirements.txt --quiet - echo -e "${GREEN}✓ Backend dependencies installed${NC}" + pip install -r requirements.txt --quiet + echo -e "${GREEN}✓ Backend dependencies installed${NC}" else - echo -e "${RED}✗ requirements.txt not found${NC}" - exit 1 + echo -e "${RED}✗ requirements.txt not found${NC}" + exit 1 fi # Create data directory if it doesn't exist if [ ! -d "data" ]; then - mkdir data - echo -e "${GREEN}✓ Data directory created${NC}" + mkdir data + echo -e "${GREEN}✓ Data directory created${NC}" fi # Deactivate virtual environment @@ -96,32 +97,32 @@ cd frontend # Check if package.json exists if [ ! -f "package.json" ]; then - echo -e "${RED}✗ package.json not found${NC}" - exit 1 + echo -e "${RED}✗ package.json not found${NC}" + exit 1 fi # Install dependencies if [ ! -d "node_modules" ]; then - echo "Installing frontend dependencies..." - npm install - echo -e "${GREEN}✓ Frontend dependencies installed${NC}" + echo "Installing frontend dependencies..." + npm install + echo -e "${GREEN}✓ Frontend dependencies installed${NC}" else - echo -e "${YELLOW}node_modules already exists, checking for updates...${NC}" - npm install - echo -e "${GREEN}✓ Frontend dependencies up to date${NC}" + echo -e "${YELLOW}node_modules already exists, checking for updates...${NC}" + npm install + echo -e "${GREEN}✓ Frontend dependencies up to date${NC}" fi # Setup .env.local if it doesn't exist if [ ! -f ".env.local" ]; then - echo "Creating .env.local..." - echo "NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1" >.env.local - echo -e "${GREEN}✓ .env.local created${NC}" + echo "Creating .env.local..." + echo "NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1" >.env.local + echo -e "${GREEN}✓ .env.local created${NC}" elif ! grep -q "NEXT_PUBLIC_API_URL" .env.local; then - echo "Adding NEXT_PUBLIC_API_URL to .env.local..." - echo "NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1" >>.env.local - echo -e "${GREEN}✓ NEXT_PUBLIC_API_URL added to .env.local${NC}" + echo "Adding NEXT_PUBLIC_API_URL to .env.local..." + echo "NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1" >>.env.local + echo -e "${GREEN}✓ NEXT_PUBLIC_API_URL added to .env.local${NC}" else - echo -e "${YELLOW}.env.local already configured${NC}" + echo -e "${YELLOW}.env.local already configured${NC}" fi cd .. diff --git a/start.sh b/start.sh index 2c637929..45104cd3 100755 --- a/start.sh +++ b/start.sh @@ -25,10 +25,10 @@ sleep 3 # Check if backend is running if curl -s http://localhost:8000/api/v1/health >/dev/null 2>&1; then - echo -e "${GREEN}✓ Backend API running on http://localhost:8000${NC}" - echo " API docs: http://localhost:8000/docs" + echo -e "${GREEN}✓ Backend API running on http://localhost:8000${NC}" + echo " API docs: http://localhost:8000/docs" else - echo -e "${YELLOW}⚠ Backend might still be starting up...${NC}" + echo -e "${YELLOW}⚠ Backend might still be starting up...${NC}" fi echo "" @@ -49,11 +49,11 @@ echo "Backend API: http://localhost:8000" echo "API Docs: http://localhost:8000/docs" echo "Frontend UI: http://localhost:8080" echo "" -echo "Backend PID: $BACKEND_PID" -echo "Frontend PID: $FRONTEND_PID" +echo "Backend PID: ${BACKEND_PID}" +echo "Frontend PID: ${FRONTEND_PID}" echo "" echo "To stop the servers:" -echo " kill $BACKEND_PID $FRONTEND_PID" +echo " kill ${BACKEND_PID} ${FRONTEND_PID}" echo "" echo "Press Ctrl+C to view logs or stop the servers." echo "" diff --git a/stop.sh b/stop.sh index adf10836..7d023aba 100755 --- a/stop.sh +++ b/stop.sh @@ -14,18 +14,18 @@ NC='\033[0m' # No Color # Find and stop backend (uvicorn) echo "Stopping Backend API..." BACKEND_PIDS=$(pgrep -f "uvicorn app.main:app") -if [ -n "$BACKEND_PIDS" ]; then - echo "Found backend process(es): $BACKEND_PIDS" - kill "$BACKEND_PIDS" 2>/dev/null - sleep 1 - # Force kill if still running - if pgrep -f "uvicorn app.main:app" >/dev/null; then - echo "Force stopping backend..." - pkill -9 -f "uvicorn app.main:app" - fi - echo -e "${GREEN}✓ Backend stopped${NC}" +if [ -n "${BACKEND_PIDS}" ]; then + echo "Found backend process(es): ${BACKEND_PIDS}" + kill "${BACKEND_PIDS}" 2>/dev/null + sleep 1 + # Force kill if still running + if pgrep -f "uvicorn app.main:app" >/dev/null; then + echo "Force stopping backend..." + pkill -9 -f "uvicorn app.main:app" + fi + echo -e "${GREEN}✓ Backend stopped${NC}" else - echo -e "${YELLOW}No backend process found${NC}" + echo -e "${YELLOW}No backend process found${NC}" fi echo "" @@ -33,18 +33,18 @@ echo "" # Find and stop frontend (next dev / npm) echo "Stopping Frontend..." FRONTEND_PIDS=$(pgrep -f "next dev") -if [ -n "$FRONTEND_PIDS" ]; then - echo "Found frontend process(es): $FRONTEND_PIDS" - kill "$FRONTEND_PIDS" 2>/dev/null - sleep 1 - # Force kill if still running - if pgrep -f "next dev" >/dev/null; then - echo "Force stopping frontend..." - pkill -9 -f "next dev" - fi - echo -e "${GREEN}✓ Frontend stopped${NC}" +if [ -n "${FRONTEND_PIDS}" ]; then + echo "Found frontend process(es): ${FRONTEND_PIDS}" + kill "${FRONTEND_PIDS}" 2>/dev/null + sleep 1 + # Force kill if still running + if pgrep -f "next dev" >/dev/null; then + echo "Force stopping frontend..." + pkill -9 -f "next dev" + fi + echo -e "${GREEN}✓ Frontend stopped${NC}" else - echo -e "${YELLOW}No frontend process found${NC}" + echo -e "${YELLOW}No frontend process found${NC}" fi echo ""