Skip to content

Commit

Permalink
Merge pull request #20 from gchq/gh-18-fix-version-enumerations
Browse files Browse the repository at this point in the history
fixes gh-18 - fix version enumerations, add version number validation script, set version to 3.1.1
  • Loading branch information
at055612 authored Jul 17, 2017
2 parents 616d259 + ce26626 commit 005c883
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ before_install:
- sudo apt-get -qq update
- sudo apt-get install -y libxml2-utils

script: xmllint --noout --schema http://www.w3.org/2001/XMLSchema.xsd ./event-logging.xsd
script:
- xmllint --noout --schema http://www.w3.org/2001/XMLSchema.xsd ./event-logging.xsd
- ./validateSchemaVersions.py

##TODO Gte travis to push the xsd file as an artifact in a github release, renaming the file to event-logging-vX.xsd
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The namespace of the schema includes the major version, e.g. _event-logging:3_.

Minor and patch versions will be backwards compatible with other versions at the same major version number. The minor and patch version numbers are included in the _version_ and _id_ attributes of the _xs:schema_ element.

Minor version changes may included new optional elements or attributes. They may also include changes to such things as enumerations or paterns that are addative in nature.
Minor version changes may included new optional elements or attributes. They may also include changes to such things as enumerations or patterns that are additive in nature.

Patch version changes will typically include cosmetic changes (e.g. _xs:documentation_ changes.

Expand All @@ -20,6 +20,13 @@ Patch version changes will typically include cosmetic changes (e.g. _xs:document

### Changed

## [v3.1.1] - 2017-07-17

### Changed

* Issue **#18** : Remove `pattern` from `VersionSimpleType` as this is trumped by the enumerations. Add past versions as enumerations.


## [v3.1.0] - 2017-07-12

### Added
Expand All @@ -44,6 +51,7 @@ Patch version changes will typically include cosmetic changes (e.g. _xs:document

* Intial open source release

[Unreleased]: https://github.com/gchq/event-logging-schema/compare/v3.1.0...HEAD
[Unreleased]: https://github.com/gchq/event-logging-schema/compare/v3.1.1...HEAD
[v3.1.1]: https://github.com/gchq/event-logging-schema/compare/v3.1.0...v3.1.1
[v3.1.0]: https://github.com/gchq/event-logging-schema/compare/v3.0.0...v3.1.0
[v3.0.0]: https://github.com/gchq/event-logging-schema/compare/v3.0.0...v3.0.0
2 changes: 2 additions & 0 deletions docs/releaseProcess.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ The definition of breaking change is one which is not backwards compatible with
1. Increment the major version number in `targetNamespace`, e.g. `event-logging:4`
1. Change the `version` attribute to the intended version number, e.g. `4.1.2`
1. Change the `id` attribute to the intended version number, e.g. `event-logging-v4.1.2`
1. Change or add to the list of enumerations in `VersionSimplType`. If the change is a breaking change the remove all existign enumerations and add in one for the new version. If it is not a breaking changed add the new version to the list of existing versions.
1. Run the script `validateSchemaVersions.py` to ensure all the schema versions have been set correctly (this will be run by the travis build anyway)
1. Ensure CHANGELOG.md has all changes documented in it
1. Commit and push the new version number changes
1. Create a tag in git for the new release, e.g. `git tag v4.1.2`
Expand Down
9 changes: 5 additions & 4 deletions event-logging.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
targetNamespace="event-logging:3"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="3.2.0-SNAPSHOT"
id="event-logging-v3.2.0-SNAPSHOT">
version="3.1.1"
id="event-logging-v3.1.1">
<xs:annotation>
<xs:documentation>This schema describes the allowed element structure for event logging. Please refer to the documentation and examples for a description of how to use this schema in addition to the descriptions given for each element within this schema.</xs:documentation>
</xs:annotation>
Expand Down Expand Up @@ -3192,11 +3192,12 @@
</xs:simpleType>
<xs:simpleType name="VersionSimpleType">
<xs:annotation>
<xs:documentation>Type for specifying version numbers in a common way, e.g. 2.4</xs:documentation>
<xs:documentation>Type for specifying the version numbers of XML documents that are supported by this version of the XMLSchema. A version of the schema will support XML documents conforming to its version and all past version where the major version number is the same.</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]+(\.[0-9]+)*"/>
<xs:enumeration value="3.0.0"/>
<xs:enumeration value="3.1.0"/>
<xs:enumeration value="3.1.1"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="VirtualSessionSessionStateSimpleType">
Expand Down
105 changes: 105 additions & 0 deletions validateSchemaVersions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env python
#**********************************************************************
# Copyright 2016 Crown Copyright
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#**********************************************************************


#**********************************************************************
# Script to ensure all the version numbers in the event-logging
# XMLSchema are valid
#**********************************************************************


import os
import re
import xml.etree.ElementTree as ET

SCHEMA_FILENAME = "event-logging.xsd"

root_path = os.path.dirname(os.path.realpath(__file__))

def getMinorVersion(versionStr):
minorVer = re.match("[0-9]*\.([0-9]*)\..*", versionStr).group(1)
return minorVer

def validateVersions():
print "Validating file %s" % SCHEMA_FILENAME
print ""

# pattern = re.compile("xmlns:evt\"event-logging:.*\"")
xsdFile = open(SCHEMA_FILENAME, 'r')
filetext = xsdFile.read()
xsdFile.close()
matches = re.findall("xmlns:evt=\"event-logging:(.*)\"", filetext)
if (len(matches) != 1):
raise ValueError("Unexpected matches for evt namespace", matches)
namespaceVersion = matches[0]
print "namespace version: %s" % namespaceVersion

xml_root = ET.parse(SCHEMA_FILENAME).getroot()

targetNamespaceAttr = xml_root.get("targetNamespace")
targetNamespaceVersion = re.match(".*:([0-9]*)$", targetNamespaceAttr).group(1)
print "targetNamespace: %s" % targetNamespaceVersion

versionAttrVersion = xml_root.get("version")
print "version: %s" % versionAttrVersion

idAttr = xml_root.get("id")
idAttrVersion = re.match("event-logging-v([0-9\.]*)", idAttr).group(1)
print "id: %s" % idAttrVersion

ns = {'xs': 'http://www.w3.org/2001/XMLSchema'}
enumVersions = []
print "Version enumerations:"
for enumElm in xml_root.findall("./xs:simpleType[@name='VersionSimpleType']/xs:restriction/xs:enumeration", ns):
print " %s" % enumElm.get("value")
enumVersions.append(enumElm.get("value"))

# print enumVersions

if (namespaceVersion != targetNamespaceVersion):
raise ValueError("namespace version and targetNamespace version do not match", namespaceVersion, targetNamespaceVersion)

versionRegex = "[0-9]+\.[0-9]+\.[0-9]+"
if (not re.match(versionRegex, versionAttrVersion)):
raise ValueError("version attribute does not match the valid regex", versionAttrVersion, versionRegex)

if (versionAttrVersion != idAttrVersion):
raise ValueError("version attribute and id attribute do not match", versionAttrVersion, idAttrVersion)

if (not versionAttrVersion.startswith(targetNamespaceVersion)):
raise ValueError("Major version of the version attribute does not match the targetNamespace version", versionAttrVersion, targetNamespaceVersion)

if (not versionAttrVersion in enumVersions):
raise ValueError("Schema version is not in the list of version enumerations", versionAttrVersion, enumVersions)

minorVer = getMinorVersion(versionAttrVersion)

for enumVer in enumVersions:
if (not enumVer.startswith(targetNamespaceVersion)):
raise ValueError("Major version of the enumeration version does not match the targetNamespace version", enumVer, targetNamespaceVersion)
minorVerOfEnum = getMinorVersion(enumVer)

if (minorVerOfEnum > minorVer):
raise ValueError("Minor version of enumeration version is higher than the minor version of the schema version. Should be less than or equal to the schema version", enumVer, versionAttrVersion)



validateVersions()

print ""
print "Done!"
exit(0)

0 comments on commit 005c883

Please sign in to comment.