github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/tests/suites/static_analysis/schema.sh (about)

     1  run_schema() {
     2  	CUR_SHA=$(git show HEAD:apiserver/facades/schema.json | shasum -a 1 | awk '{ print $1 }')
     3  	TMP=$(mktemp /tmp/schema-XXXXX)
     4  	OUT=$(make --no-print-directory SCHEMA_PATH="${TMP}" rebuild-schema 2>&1)
     5  	OUT_CODE=$?
     6  	if [ $OUT_CODE -ne 0 ]; then
     7  		echo ""
     8  		echo "$(red 'Found some issues:')"
     9  		echo "${OUT}"
    10  		exit 1
    11  	fi
    12  	# shellcheck disable=SC2002
    13  	NEW_SHA=$(cat "${TMP}" | shasum -a 1 | awk '{ print $1 }')
    14  
    15  	if [ "${CUR_SHA}" != "${NEW_SHA}" ]; then
    16  		(echo >&2 "\\nError: facades schema is not in sync. Run 'make rebuild-schema' and commit source.")
    17  		exit 1
    18  	fi
    19  }
    20  
    21  test_schema() {
    22  	if [ "$(skip 'test_schema')" ]; then
    23  		echo "==> TEST SKIPPED: static schema analysis"
    24  		return
    25  	fi
    26  
    27  	(
    28  		set_verbosity
    29  
    30  		cd .. || exit
    31  
    32  		# Check for schema changes and ensure they've been committed
    33  		run_linter "run_schema"
    34  	)
    35  }