Build: added steps to generate packages api documentation. (#27930)

* added steps to generate docs.

* re-generated the drone.yml file.

* removed metrics reporting from pr pipeline.

* fixed spelling issues.

* fixed so package generation should work.

* some small refactorings.

* fixed spelling error.

* adding echo to verify that we execute the correct script.

* removed echo statement.

* changed scripts a bit.

* added ci flag to script.

* adding exit 1

* increased the limit.

* added missing space.

* fixed shellcheck error.

* fixing lint errors.

* renamed build step.

* changed logic.

* increased limit.

* changed to echo instead of echo -e

* fixed shellcheck errors.

* trying to debug script,

* trying to simplify the find statement.

* fixed issue with text formatting on linux.

* imported build step.

* Update scripts/ci-reference-docs-lint.sh

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>

* removed cleanup of packages.

* increased limit.

* will build frontend docs on master but not lint it.

* will always run the linting step.

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Marcus Andersson
2020-10-14 14:35:55 +02:00
committed by GitHub
co-authored by Arve Knudsen
parent f22b768ce4
commit b5196f531c
9 changed files with 123 additions and 60 deletions
+10 -7
View File
@@ -3,9 +3,16 @@
# abort if we get any error
set -eo pipefail
# building grafana packages
echo "building grafana packages..."
yarn packages:build
BUILD_MODE="${1-local}"
if [ "local" == "$BUILD_MODE" ]
then
# building grafana packages
echo "building grafana packages..."
yarn packages:build
else
echo "skip building grafana packages since it already built in previous steps..."
fi
# extract packages api documentation json
echo "extracting packages documentation data..."
@@ -14,7 +21,3 @@ yarn packages:docsExtract
# generating api documentation markdown
echo "generating markdown from documentation data..."
yarn packages:docsToMarkdown
# cleaning packages
echo "cleaning up packages build files..."
lerna run clean
@@ -3,49 +3,42 @@
# abort if we get any error
set -eo pipefail
report_reference_docs_metrics() {
# $1 = branch that the script is running on.
# $2 = number of warnings in current version of the code.
if [ "${1}" == "master" ]; then
./scripts/ci-metrics-publisher.sh \
grafana.ci-code.reference-docs.warnings="$2"
fi
}
pretty_print_result_of_report() {
# $1 = result of current report
echo -e "\n\n"
echo -e "-----------------------------------------------------\n"
echo -e "$1\n"
echo -e "-----------------------------------------------------"
echo "-----------------------------------------------------"
}
BUILD_MODE="${1-local}"
REPORT_PATH="$(realpath "$(dirname "$0")/../reports/docs/")"
BUILD_SCRIPT_PATH="$(realpath "$(dirname "$0")/ci-reference-docs-build.sh")"
if [ ! -d "$REPORT_PATH" ]; then
# this script needs to be run after the packages have been built and the api-extractor has completed.
# shellcheck source=/scripts/ci-reference-docs-build.sh
. "$BUILD_SCRIPT_PATH"
if ! . "$BUILD_SCRIPT_PATH" "$BUILD_MODE";
then
echo "Failed to build packages and extract docs" >&2
exit 1
else
echo "Successfully built packages and extracted docs"
fi
fi
WARNINGS_COUNT="$(find "$REPORT_PATH" -type f -name \*.log -print0 | xargs -0 grep -o "\[33mWarning:" | wc -l | xargs)"
WARNINGS_COUNT_LIMIT=900
WARNINGS_COUNT="$(find "$REPORT_PATH" -type f -name \*.log -print0 | xargs -0 grep -o "Warning: " | wc -l | xargs)"
WARNINGS_COUNT_LIMIT=1077
if [ "$WARNINGS_COUNT" -gt $WARNINGS_COUNT_LIMIT ]; then
echo -e "API Extractor warnings/errors $WARNINGS_COUNT exceeded $WARNINGS_COUNT_LIMIT so failing build.\n"
echo -e "Please go to: https://github.com/grafana/grafana/blob/master/contribute/style-guides/code-comments.md for more information on how to add code comments."
report_reference_docs_metrics "$CIRCLE_BRANCH" "$WARNINGS_COUNT"
echo "Please go to: https://github.com/grafana/grafana/blob/master/contribute/style-guides/code-comments.md for more information on how to add code comments."
exit 1
fi
if [ "$WARNINGS_COUNT" -lt $WARNINGS_COUNT_LIMIT ]; then
pretty_print_result_of_report "Wohoo! Fewer warnings compared to last build 🎉🎈🍾✨\n\nYou can lower the threshold from $WARNINGS_COUNT_LIMIT to $WARNINGS_COUNT in the:\nscripts/ci-reference-docs-metrics.sh"
report_reference_docs_metrics "$CIRCLE_BRANCH" "$WARNINGS_COUNT"
exit 0
fi
pretty_print_result_of_report "API Extractor total warnings: $WARNINGS_COUNT"
report_reference_docs_metrics "$CIRCLE_BRANCH" "$WARNINGS_COUNT"
+16
View File
@@ -383,6 +383,21 @@ def build_frontend_step(edition, ver_mode, is_downstream=False):
],
}
def build_frontend_docs_step(edition):
if edition == 'enterprise':
return None
return {
'name': 'build-frontend-docs',
'image': build_image,
'depends_on': [
'build-frontend'
],
'commands': [
'./scripts/ci-reference-docs-lint.sh ci',
]
}
def build_plugins_step(edition, sign=False):
if sign:
env = {
@@ -603,6 +618,7 @@ def build_docs_website_step():
'image': 'grafana/docs-base:latest',
'depends_on': [
'initialize',
'build-frontend-docs',
],
'commands': [
'mkdir -p /hugo/content/docs/grafana',
+2
View File
@@ -13,6 +13,7 @@ load(
'e2e_tests_server_step',
'e2e_tests_step',
'build_storybook_step',
'build_frontend_docs_step',
'build_docs_website_step',
'copy_packages_for_docker_step',
'build_docker_images_step',
@@ -52,6 +53,7 @@ def get_steps(edition, is_downstream=False):
e2e_tests_step(),
build_storybook_step(edition=edition, ver_mode=ver_mode),
publish_storybook_step(edition=edition, ver_mode=ver_mode),
build_frontend_docs_step(edition=edition),
build_docs_website_step(),
copy_packages_for_docker_step(),
build_docker_images_step(edition=edition, ver_mode=ver_mode, publish=publish),
+2
View File
@@ -13,6 +13,7 @@ load(
'e2e_tests_server_step',
'e2e_tests_step',
'build_storybook_step',
'build_frontend_docs_step',
'build_docs_website_step',
'copy_packages_for_docker_step',
'build_docker_images_step',
@@ -42,6 +43,7 @@ def pr_pipelines(edition):
e2e_tests_server_step(),
e2e_tests_step(),
build_storybook_step(edition=edition, ver_mode=ver_mode),
build_frontend_docs_step(edition=edition),
build_docs_website_step(),
copy_packages_for_docker_step(),
build_docker_images_step(edition=edition, ver_mode=ver_mode, archs=['amd64',]),