Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: xml validation step #3527

Open
wants to merge 33 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions scripts/validateXMLFiles.bash
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ fi
if [ "$METHOD" = "git" ] && ! (hash git &> /dev/null); then
>&2 echo "Error: git is required when -g or --git is specified"
exit
else
GIT_REPO_DIR=$1;
echo "INFO: The specified GIT_REPO_DIR"
echo $GIT_REPO_DIR
# Check GIT_REPO_DIR and its existence. Then add it to Git safe directories
if [ -z "$GIT_REPO_DIR" ]; then
echo "Error: GIT_REPO_DIR is not set." && exit 1
elif [ ! -d "$GIT_REPO_DIR" ]; then
echo "Error: The specified GIT_REPO_DIR '$GIT_REPO_DIR' does not exist." && exit 1
else
echo "Adding '$GIT_REPO_DIR' to Git safe directories..."
git config --global --add safe.directory "$GIT_REPO_DIR" && \
echo "'$GIT_REPO_DIR' has been successfully added." || \
echo "Error: Failed to add '$GIT_REPO_DIR'."
echo "INFO: Printing safe.directory: "
git config --global --list | grep safe.directory
fi
fi

abs_path ()
Expand All @@ -62,15 +79,33 @@ list_xml_files_git ()
exit 1
fi
local prefix=$(cd $path; git rev-parse --show-prefix 2>/dev/null)
git --git-dir=$git_root/.git ls-files $prefix | grep -e .*[.]xml$ | sed "s|^|$git_root/|g"
git --git-dir=$git_root"/.git" ls-files $prefix | grep -e ".*[.]xml$" | sed "s|^|$git_root/|g"
}


git --version
# emit location
pwd

# create/nullify the log file
echo -n > $LOGFILE

# validate each path separately and write results in the log
for path in "$@"; do
list_xml_files_$METHOD $path | $XARGS xmllint --schema $SCHEMA --noout >> $LOGFILE 2>&1
# emit location
echo $path
cd "$path" || { echo "Directory not found: $path"; exit 1; }
pwd
ls -la
git status
git_root_c=$(git rev-parse --show-toplevel 2>/dev/null)
prefix_c=$(git rev-parse --show-prefix 2>/dev/null)
echo $git_root_c
echo $prefix_c
echo $git_root"/.git"
collected_xml_files=$(list_xml_files_$METHOD $path)
echo $collected_xml_files
$collected_xml_files | $XARGS xmllint --schema $SCHEMA --noout >> $LOGFILE 2>&1
done

# print any failed validations on the stderr
Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ if( ENABLE_XML_UPDATES AND ENABLE_MPI AND UNIX AND NOT ENABLE_CUDA AND NOT ENABL

set(SCHEMA_DIR ${CMAKE_SOURCE_DIR}/coreComponents/schema)
set(SCRIPT_DIR ${CMAKE_SOURCE_DIR}/../scripts)
set(GIT_SOURCE_DIR "${CMAKE_SOURCE_DIR}/..")

add_custom_target( geosx_generate_schema
ALL
Expand All @@ -179,7 +180,7 @@ if( ENABLE_XML_UPDATES AND ENABLE_MPI AND UNIX AND NOT ENABLE_CUDA AND NOT ENABL

add_custom_target( geosx_validate_all_xml_files
ALL
COMMAND bash ${SCRIPT_DIR}/validateXMLFiles.bash -g ${SCHEMA_DIR}/schema.xsd ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/../examples ${CMAKE_SOURCE_DIR}/../inputFiles
COMMAND bash ${SCRIPT_DIR}/validateXMLFiles.bash -g ${SCHEMA_DIR}/schema.xsd ${GIT_SOURCE_DIR} ${GIT_SOURCE_DIR}/examples ${GIT_SOURCE_DIR}/inputFiles
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS geosx_generate_schema
COMMENT "Validating all XML files in the repository against the schema"
Expand Down
Loading
Loading