diff --git a/.github/workflows/schema-validation.v3.2.yml b/.github/workflows/schema-validation.v3.2.yml deleted file mode 100644 index 1dc3f49..0000000 --- a/.github/workflows/schema-validation.v3.2.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Validate iTop datamodel XML version 3.2 - -on: - pull_request: - branches: [ main ] - -jobs: - validate-xml: - runs-on: ubuntu-latest - - steps: - - name: Check out repository - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - - name: Install lxml - run: pip install lxml - - - name: Verify files exist - run: | - test -f 3.2/itop_design.xsd || (echo "XSD file missing!" && exit 1) - test -f test/datamodel.must-validate.xml || (echo "XML file missing!" && exit 1) - - - name: Validate datamodel.must-validate.xml against itop_design.xsd - run: | - python -c ' - import lxml.etree as ET - schema = ET.XMLSchema(file="3.2/itop_design.xsd") - parser = ET.XMLParser(schema=schema) - with open("test/datamodel.must-validate.xml", "rb") as f: - ET.parse(f, parser) - print("XML is valid.") - ' diff --git a/.github/workflows/validate-xml.v3.2.yml b/.github/workflows/validate-xml.v3.2.yml new file mode 100644 index 0000000..bc2facf --- /dev/null +++ b/.github/workflows/validate-xml.v3.2.yml @@ -0,0 +1,35 @@ +# +# GitHub Actions Workflow: Validate iTop datamodel XML v3.2 +# +# This workflow runs on every pull request to the 'main' branch. +# It validates an XML data model against the corresponding XSD schema. +# The validation logic is implemented in a separate Python script. +# + +name: Validate iTop datamodel XML version 3.2 + +on: + pull_request: + branches: [ main ] + +jobs: + validate-xml: + runs-on: ubuntu-latest + env: + XSD_PATH: 3.2/itop_design.xsd + XML_PATH: test/datamodel.must-validate.xml + + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Prepare Python environment + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Install XML validation dependencies + run: pip install -r scripts/requirements.txt + + - name: Validate XML datamodel against schema + run: python scripts/validate_xml.py $XSD_PATH $XML_PATH diff --git a/.vscode/settings.json b/.vscode/settings.json index f3504bd..a845341 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "cSpell.words": [ + "addprevious", "attcode", "autoincrement", "cmdb", @@ -7,6 +8,7 @@ "Combodo", "dashlet", "dashlets", + "datamodels", "extkey", "fileref", "finalclass", @@ -15,6 +17,7 @@ "ITSM", "jointype", "jqueryui", + "lxml", "metavalue", "metavalues", "mgmt", @@ -24,6 +27,7 @@ "networkflow", "Nihilo", "noout", + "NSMAP", "stylesheet", "teemip", "timespent", diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 0000000..4b17651 --- /dev/null +++ b/scripts/requirements.txt @@ -0,0 +1 @@ +lxml>=4.9.0 diff --git a/scripts/validate_xml.py b/scripts/validate_xml.py new file mode 100644 index 0000000..c09b073 --- /dev/null +++ b/scripts/validate_xml.py @@ -0,0 +1,22 @@ +import os +import sys +import lxml.etree as ET + +if len(sys.argv) != 3: + print("Usage: python validate_xml.py ") + sys.exit(1) + +XSD_PATH = sys.argv[1] +XML_PATH = sys.argv[2] + +for path in [XSD_PATH, XML_PATH]: + if not os.path.isfile(path): + raise FileNotFoundError(f"Missing required file: {path}") + +schema = ET.XMLSchema(file=XSD_PATH) +parser = ET.XMLParser(schema=schema) + +with open(XML_PATH, "rb") as f: + ET.parse(f, parser) + +print("✅ XML is valid against schema.")