Skip to content

Commit

Permalink
chore(codegen): sanity checks for generation scripts (#1498)
Browse files Browse the repository at this point in the history
* chore: add sanity checks

* feat: script to perform sanity checks

* fix: move check creation after downloading repos

* chore: improve lib generation sanity check

checks whether the library is empty, has empty values and so on

* chore: add generated files check

* chore: add same-length check between lib list and gen folders

* chore: remove unnecesary mkdir in gen lib list script

* chore: move to scripts folder

* chore: executable sanity check

* chore: adapt to new structure, comments

* chore: add sanity check step in workflow'

* chore: use correct snapshot of generator

* chore: debug mode

* chore: use multiline script determinant

* chore: correct file name
  • Loading branch information
diegomarquezp committed May 5, 2023
1 parent 1199430 commit abe3b07
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/generateAutoConfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ jobs:
bash scripts/generate-all.sh -m $MONOREPO_COMMITISH
env:
MONOREPO_COMMITISH: ${{ steps.generate_library_list.outputs.MONOREPO_COMMITISH }}
- name: Sanity checks
continue-on-error: false
working-directory: spring-cloud-generator/scripts
run: |
set -x
bash sanity-checks.sh
- name: Check for generation errors
continue-on-error: false
working-directory: spring-cloud-generator
Expand Down Expand Up @@ -171,4 +177,4 @@ jobs:
env:
GITHUB_ACTOR_EMAIL: ${{ steps.determine_workflow_author_email.outputs.GITHUB_ACTOR_EMAIL }}
GITHUB_ACTOR_NAME: ${{ steps.determine_workflow_author_email.outputs.GITHUB_ACTOR_NAME }}
GITHUB_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_spring_cloud_generator_version = "4.2.1-SNAPSHOT" # {x-version-update:spring-cloud-gcp:current}
_spring_cloud_generator_version = "4.3.1-SNAPSHOT" # {x-version-update:spring-cloud-gcp:current}

maven_install(
artifacts = [
Expand Down
89 changes: 89 additions & 0 deletions spring-cloud-generator/scripts/sanity-checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash
# This script performs the following sanity checks for the library generation
# workflow (runs in the workflow, after generation):
#
# - checks that the library list used as a source of truth for the generated
# starters is not empty
# - checks that each element of the library list is a non-empty-string
# - checks that the number of rows in the library list is equal to the number of
# autoconfig folders in spring-cloud-previews
# - checks the contents of every stater and confirms they have some basic
# required files such as pom.xml, [Client]AutoConfiguration.java, etc
#
WORKING_DIR=`pwd`
set -xe # TODO remove x

function fail() {
echo "sanity check failed:"
echo " $1"
exit 1
}
library_list_path=$WORKING_DIR/resources/library_list.txt
# checks that library list was generated and not empty
if [[ $(cat $library_list_path | wc -l) -lt 2 ]]; then fail "library list is empty"; fi

# checks that the contents of each entry in the library list is a string with
# length >= 1
libraries=$(cat $library_list_path | tail -n+2)
while IFS=, read -r library_name googleapis_location coordinates_version googleapis_commitish monorepo_folder; do

non_empty_check_items=(
"$library_name"
"$googleapis_location"
"$coordinates_version"
"$googleapis_commitish"
"$monorepo_folder"
)
for column in "${non_empty_check_items[@]}"; do
if [[ -z $column ]]; then
echo "$library_name, $googleapis_location, $coordinates_version, $googleapis_commitish, $monorepo_folder"
fail "the library list entry '$library_name' has an empty required cell - see $library_list_path"
fi
done
done <<< $libraries

starters=$(find ../../spring-cloud-previews -maxdepth 1 -name "google-*" -type d -printf "%p\n")
# confirms library_list and generated folders have the same length
lib_list_n_entries=$(cat $library_list_path | tail -n+2 | wc -l)
gen_folders_n_entries=$(printf "$starters" | cut -d' ' -f1- | wc -l)
if [[ $lib_list_n_entries -ne $gen_folders_n_entries ]]; then
fail "entries in library list and generated folders differ"
fi

# checks the existence of a pom, a *AutoConfiguration.java, *Properties.java in
# each of the generated libraries
while IFS=' ' read -r starter_folder_raw; do

starter_folder=$(realpath "$starter_folder_raw")
starter_name=$(basename $starter_folder)
base_error="generated file check for starter $starter_name"

# check existence of pom
if [[ ! -f $starter_folder/pom.xml ]]; then
fail "$base_error: pom.xml not found"
fi

# checks for at least 1 autoconfig file
if [[ $(find $starter_folder -name "*AutoConfiguration.java" | wc -l) -lt 1 ]]; then
fail "$base_error: no *AutoConfiguration.java files found"
fi

# checks for at least 1 properties file
if [[ $(find $starter_folder -name "*Properties.java" | wc -l) -lt 1 ]]; then
fail "$base_error: no *Properties.java files found"
fi

# checks for configuration metadata resource
if [[ $(find $starter_folder -name "additional-spring-configuration-metadata.json" | wc -l) -lt 1 ]]; then
fail "$base_error: no additional-spring-configuration-metadata.json found"
fi

# checks for AutoConfiguration imports file
if [[ $(find $starter_folder -name "org.springframework.boot.autoconfigure.AutoConfiguration.imports" | wc -l) -lt 1 ]]; then
fail "$base_error: no org.springframework.boot.autoconfigure.AutoConfiguration.imports file found"
fi

done <<< $starters


echo "sanity check OK"

0 comments on commit abe3b07

Please sign in to comment.