-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from IanCa/dev_add_validation
Add an automatic validation check to schemas when changed
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Process Files | ||
|
||
on: | ||
push: | ||
branches: [ * ] | ||
pull_request: | ||
branches: [ * ] | ||
|
||
jobs: | ||
process-changed-files: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit. | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Get changed files | ||
id: changed-files | ||
uses: tj-actions/changed-files@v41 | ||
# To compare changes between the current commit and the last pushed remote commit set `since_last_remote_commit: true`. e.g | ||
# with: | ||
# since_last_remote_commit: true | ||
|
||
- name: List all changed files | ||
env: | ||
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} | ||
run: | | ||
for file in "$ALL_CHANGED_FILES"; do | ||
echo "$file was changed" | ||
done | ||
- name: Install dependencies | ||
run: pip install git+https://github.com/hed-standard/hed-python.git@develop | ||
|
||
- name: Run command on file list | ||
env: | ||
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} | ||
run: | | ||
python tests/validate_schemas.py $ALL_CHANGED_FILES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import sys | ||
from hed.schema import load_schema, from_string | ||
from hed.errors import get_printable_issue_string | ||
|
||
def main(): | ||
validation_issues = [] | ||
saving_failures = [] | ||
for file_path in sys.argv[1:]: # sys.argv[1:] contains all the arguments passed to the script | ||
# print(file_path) | ||
if file_path.endswith(".xml") or file_path.endswith(".mediawiki"): | ||
base_schema = load_schema(file_path) | ||
issues = base_schema.check_compliance() | ||
if issues: | ||
validation_issues.extend(issues) | ||
print(get_printable_issue_string(issues, title=file_path)) | ||
|
||
mediawiki_string = base_schema.get_as_mediawiki_string() | ||
reloaded_schema = from_string(mediawiki_string, schema_format=".mediawiki") | ||
|
||
if reloaded_schema != base_schema: | ||
error_text = f"Failed to reload {file_path} as mediawiki. There is either a problem with the source file, or the saving/loading code." | ||
saving_failures.append(error_text) | ||
print(error_text) | ||
|
||
xml_string = base_schema.get_as_xml_string() | ||
reloaded_schema = from_string(xml_string, schema_format=".xml") | ||
|
||
if reloaded_schema != base_schema: | ||
error_text = f"Failed to reload {file_path} as xml. There is either a problem with the source file, or the saving/loading code." | ||
saving_failures.append(error_text) | ||
print(error_text) | ||
|
||
# if saving_failures: | ||
# for issue in saving_failures: | ||
# print(issue) | ||
|
||
if validation_issues or saving_failures: | ||
return 1 | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
exit(main()) |