From b1c42cc08e8b8d83137e06a30d7bb14be0ef6406 Mon Sep 17 00:00:00 2001 From: Aurelian Shuttleworth Date: Fri, 22 Sep 2023 12:12:25 +0200 Subject: [PATCH 1/3] Add dependency check to Makefile A new Bash script `dependancy_check.sh` has been added to ensure that the minimum required Bash version is used. This script is now called in the Makefile as part of the `check_dependencies` task. This aims to prevent errors due to incompatible Bash versions. --- Makefile | 3 +++ scripts/dependancy_check.sh | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100755 scripts/dependancy_check.sh diff --git a/Makefile b/Makefile index cab1d83f..d7145e56 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ LATEST := v10.0.0 +check_dependencies: + ./scripts/dependancy_check.sh + generate: ./scripts/generate.sh v10.0.0 ./scripts/generate_latest.sh v10.0.0 diff --git a/scripts/dependancy_check.sh b/scripts/dependancy_check.sh new file mode 100755 index 00000000..54322c45 --- /dev/null +++ b/scripts/dependancy_check.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -euo pipefail +set -x + +bash_version_check () { + MIN_BASH_VERSION=4 + + if [ "${BASH_VERSINFO:-0}" -ge ${MIN_BASH_VERSION} ] + then + echo "Warning bash version ${BASH_VERSINFO:-0} in use a minimum of bash version ${MIN_BASH_VERSION} is required" + exit 1 + fi +} + +check_dependencies () { + bash_version_check +} + +check_dependencies \ No newline at end of file From e1a2a148c92fc247b745344f444453e40b0cd649 Mon Sep 17 00:00:00 2001 From: Aurelian Shuttleworth Date: Fri, 22 Sep 2023 12:59:34 +0200 Subject: [PATCH 2/3] Refined bash version & command availability checks The `dependancy_check.sh` script has been expanded to improve the verification process. It not only checks the running bash version for compatibility, but also ensures that a set list of commands are available before proceeding. This eliminates potential breakdowns due to missing dependencies or unsupported bash versions. --- scripts/dependancy_check.sh | 49 +++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/scripts/dependancy_check.sh b/scripts/dependancy_check.sh index 54322c45..cadbffcb 100755 --- a/scripts/dependancy_check.sh +++ b/scripts/dependancy_check.sh @@ -1,19 +1,54 @@ #!/usr/bin/env bash set -euo pipefail -set -x -bash_version_check () { - MIN_BASH_VERSION=4 +MIN_BASH_VERSION=4 +REQUIRED_COMMANDS=( + "mapfile" + "jb" + "jsonnet" + "jsonnetfmt" + "jrsonnet" + ) - if [ "${BASH_VERSINFO:-0}" -ge ${MIN_BASH_VERSION} ] - then - echo "Warning bash version ${BASH_VERSINFO:-0} in use a minimum of bash version ${MIN_BASH_VERSION} is required" +function check_command_availability () { + if ! command -v "${1}" >/dev/null 2>&1; then + echo "Warning: $1 could not be found." exit 1 + else + echo "$1 found. Carry on." fi } +bash_version_check () { + local bash_version="${BASH_VERSINFO[0]:-0}" + + if ((bash_version < MIN_BASH_VERSION)); then + echo "Warning: bash version ${bash_version} found. A minimum bash version of ${MIN_BASH_VERSION} is required." + return 1 + else + echo "Bash version ${bash_version} is sufficient. Carry on." + fi +} + +required_commands_availability_check () { + for cmd in "${REQUIRED_COMMANDS[@]}" + do + if command -v $cmd >/dev/null 2>&1 + then + echo "$cmd found. Carry on." + else + echo "Warning: $cmd could not be found." + exit 1 + fi + done +} + check_dependencies () { - bash_version_check + bash_version_check || exit 1 + + for cmd in "${REQUIRED_COMMANDS[@]}"; do + check_command_availability "$cmd" || exit 1 + done } check_dependencies \ No newline at end of file From 054e2abafa35323cd26bf15338ed164acedd3700 Mon Sep 17 00:00:00 2001 From: Aurelian Shuttleworth Date: Fri, 22 Sep 2023 13:07:10 +0200 Subject: [PATCH 3/3] Refactor documentation for clarity and precision Reshaped the DEVELOPMENT.md file to provide thorough and more explicit instructions. Each section is now easily accessible and comprehensible, eliminating any potential ambiguity for the user. This streamlines the development process by clearly laying out instructions for checking dependencies, generating Jsonnet libraries and documents, as well as understanding usage of the Grafonnet-base library and examples. --- DEVELOPMENT.md | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 5fcdd166..c01ff542 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -1,16 +1,10 @@ # Development +**Check Dependencies**: Use the `make check_dependencies` command to ensure that all necessary commands are available for generation. -`make generate` uses `generate.jsonnet` to create Jsonnet libraries for each version in -`gen//`, it also creates `gen/grafonnet-latest/` which refers to the newest -version. These Jsonnet libraries depend on the JSON Schemas from Grok and `grafonnet-base/`. +**Generate Jsonnet Libraries**: The `make generate` command uses `generate.jsonnet` to generate Jsonnet libraries for each version found in `gen//`. It also produces `gen/grafonnet-latest/` referring to the latest version. These libraries are dependent on the JSON schemas from Grok and the `grafonnet-base/`. -`make libdocs` will generate the docs for every version in `gen//` and `make -latestdocs` will generate the docs in `docs/` for the `gen/grafonnet-latest/`. `make docs` -combines them. +**Generate Library Documentation**: By running `make libdocs`, you can produce documentation for every version in `gen//`. To create documentation for the `gen/grafonnet-latest/` you can use the `make latestdocs` command, which outputs documentation to `docs/`. Use `make docs` to combine these generated documents. -The `grafonnet-base/` library provides the logic to convert JSON Schemas to a runtime -library and adds veneer on top. The veneer is a thin layer on top of the raw library to -improve the user experience. +**Grafonnet-base Library**: The `grafonnet-base/` library forms the basis for converting JSON schemas into a compiled library, additionally providing an overlay for improved user experience. -In `examples/` there are few example dashboard configurations that serve as inspiration as -well as an experimentation playground for library features. +**Examples**: The `examples/` directory contains several example dashboard configurations, which can be used both for inspiration and as a testing ground for library features. \ No newline at end of file