From 5f3d0353dac19c7ee0041ee8799710a9a91ab348 Mon Sep 17 00:00:00 2001 From: Matvey Kukuy Date: Sun, 1 Sep 2024 13:47:33 +0300 Subject: [PATCH] User-friendly test errors --- .github/workflows/test-pr-e2e.yml | 4 ++++ docs/mint.json | 3 +-- ...=> docs_generate_api_docs_from_openapi.sh} | 10 +++++++++- scripts/docs_validate_navigation.sh | 5 +++-- scripts/docs_validate_openapi_is_actual.sh | 20 +++++++++++++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) rename scripts/{docs_generate_readme_from_openapijson.sh => docs_generate_api_docs_from_openapi.sh} (58%) create mode 100755 scripts/docs_validate_openapi_is_actual.sh diff --git a/.github/workflows/test-pr-e2e.yml b/.github/workflows/test-pr-e2e.yml index 491745d45..702bbeb83 100644 --- a/.github/workflows/test-pr-e2e.yml +++ b/.github/workflows/test-pr-e2e.yml @@ -123,6 +123,10 @@ jobs: # create the state directory # mkdir -p ./state && chown -R root:root ./state && chmod -R 777 ./state + + # Testing if API docs are actual. + # Keeping this test here to avoid spinning Keep's backend it in the docs-test job + ./scripts/docs_validate_openapi_is_actual.sh - name: Run e2e tests and report coverage run: | poetry run coverage run --branch -m pytest -s tests/e2e_tests/ diff --git a/docs/mint.json b/docs/mint.json index afc16151e..ff372c327 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -249,8 +249,7 @@ "pages": [ "api-ref/dashboard/create-dashboard", "api-ref/dashboard/read-dashboards", - "api-ref/dashboard/update-dashboard", - "api-ref/dashboard/delete-dashboard" + "api-ref/dashboard/update-dashboard" ] }, { diff --git a/scripts/docs_generate_readme_from_openapijson.sh b/scripts/docs_generate_api_docs_from_openapi.sh similarity index 58% rename from scripts/docs_generate_readme_from_openapijson.sh rename to scripts/docs_generate_api_docs_from_openapi.sh index 28e115392..5469f01bc 100755 --- a/scripts/docs_generate_readme_from_openapijson.sh +++ b/scripts/docs_generate_api_docs_from_openapi.sh @@ -4,8 +4,16 @@ cd ../docs; # Before running this script, make sure you have update the openapi.json from the backend & backend is in the latest state. -printf "Fetching the latest openapi.json from the backend, make sure recent backend is launched...\n" +printf "Fetching the latest openapi.json." curl http://localhost:8080/openapi.json > ./openapi.json +# Check if curl was successful +if [ $? -ne 0 ]; then + echo "🔴🔴🔴 Error: Failed to download openapi.json, please run Keep backend. 🔴🔴🔴" + exit 1 +fi + +echo "Successfully downloaded openapi.json" + python3 ../scripts/docs_openapi_converter.py --source ./openapi.json --dest ./openapi.json npx @mintlify/scraping@latest openapi-file ./openapi.json -o ./api-ref \ No newline at end of file diff --git a/scripts/docs_validate_navigation.sh b/scripts/docs_validate_navigation.sh index 247768cbf..46508524f 100755 --- a/scripts/docs_validate_navigation.sh +++ b/scripts/docs_validate_navigation.sh @@ -58,8 +58,9 @@ find . -mindepth 2 -type f -name "*.mdx" | sort | while read -r file; do # echo "File $relative_path is listed in mint.json" : else - echo "\"$relative_path\"," - echo "Is missing in docs/mint.json, should be added there or to the EXCLUDE_FILE_LIST." + echo "🔴🔴🔴 \"$relative_path\" is missing in docs/mint.json. That's a file responsible for rendering docs navigation." + echo "Please add the new docs page there or to the EXCLUDE_FILE_LIST of the current script." + echo "Otherwise the page will be really hard to navigate to :)" exit 1 # Exit with an error code to fail the CI/CD process fi done diff --git a/scripts/docs_validate_openapi_is_actual.sh b/scripts/docs_validate_openapi_is_actual.sh new file mode 100755 index 000000000..ab8b03f38 --- /dev/null +++ b/scripts/docs_validate_openapi_is_actual.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +cd ../docs + +OPENAPI_JSON="../docs/openapi.json" +OPENAPI_JSON_BACKUP="../docs/openapi_backup.json" + +# Download the latest openapi.json +curl http://localhost:8080/openapi.json > $OPENAPI_JSON_BACKUP + +# Compare the 'paths' key of both JSON files directly +if cmp -s <(jq '.paths' "$OPENAPI_JSON") <(jq '.paths' "$OPENAPI_JSON_BACKUP"); then + echo "API docs are up-to-date." +else + echo "🔴🔴🔴 API docs are not up-to-date. 🔴🔴🔴" + echo "The 'paths' sections in openapi.json is not up-to-date with http://localhost:8080/openapi.json." + echo "Most probably it means that the API was updated, and the API docs should be regenerated." + echo "Please run the following command to regenerate the API docs: ./scripts/docs_generate_api_docs_from_openapi.sh" + exit 1 +fi