Skip to content

Commit

Permalink
update github action
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashkumar committed May 20, 2024
1 parent 2939991 commit 174c6d4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xmlschema==3.3.1
31 changes: 31 additions & 0 deletions .github/python/xsd_validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import argparse
import os
import xmlschema

def validate_xml_files(xsd_path, xml_dir):
"""Validates XML files in a directory against a given XSD schema."""
schema = xmlschema.XMLSchema(xsd_path)
at_least_one_invalid = False
for filename in os.listdir(xml_dir):
if filename.endswith(".xml"):
xml_path = os.path.join(xml_dir, filename)
try:
schema.validate(xml_path)
print(f"✅ {filename} is valid")
except xmlschema.XMLSchemaValidationError as e:
print(f"❌ {filename} is NOT valid:\n {e}")
at_least_one_invalid = True

if at_least_one_invalid:
os._exit(1)

def main():
parser = argparse.ArgumentParser(description="Validate XML files against an XSD schema.")
parser.add_argument("-xsd_file", help="Path to the XSD schema file")
parser.add_argument("-xml_directory", help="Directory containing XML files to validate")
args = parser.parse_args()

validate_xml_files(args.xsd_file, args.xml_directory)

if __name__ == "__main__":
main()
14 changes: 14 additions & 0 deletions .github/workflows/xsd_validation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: XML Validation

on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Validate CQL Test XML
run: python .github/python/xsd_validate.py -xsd_file tests/testSchema.xsd -xml_directory tests/cql

0 comments on commit 174c6d4

Please sign in to comment.