Skip to content

Commit 005c883

Browse files
authored
Merge pull request #20 from gchq/gh-18-fix-version-enumerations
fixes gh-18 - fix version enumerations, add version number validation script, set version to 3.1.1
2 parents 616d259 + ce26626 commit 005c883

File tree

5 files changed

+125
-7
lines changed

5 files changed

+125
-7
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ before_install:
66
- sudo apt-get -qq update
77
- sudo apt-get install -y libxml2-utils
88

9-
script: xmllint --noout --schema http://www.w3.org/2001/XMLSchema.xsd ./event-logging.xsd
9+
script:
10+
- xmllint --noout --schema http://www.w3.org/2001/XMLSchema.xsd ./event-logging.xsd
11+
- ./validateSchemaVersions.py
1012

1113
##TODO Gte travis to push the xsd file as an artifact in a github release, renaming the file to event-logging-vX.xsd

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The namespace of the schema includes the major version, e.g. _event-logging:3_.
1111

1212
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.
1313

14-
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.
14+
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.
1515

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

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

2121
### Changed
2222

23+
## [v3.1.1] - 2017-07-17
24+
25+
### Changed
26+
27+
* Issue **#18** : Remove `pattern` from `VersionSimpleType` as this is trumped by the enumerations. Add past versions as enumerations.
28+
29+
2330
## [v3.1.0] - 2017-07-12
2431

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

4552
* Intial open source release
4653

47-
[Unreleased]: https://github.com/gchq/event-logging-schema/compare/v3.1.0...HEAD
54+
[Unreleased]: https://github.com/gchq/event-logging-schema/compare/v3.1.1...HEAD
55+
[v3.1.1]: https://github.com/gchq/event-logging-schema/compare/v3.1.0...v3.1.1
4856
[v3.1.0]: https://github.com/gchq/event-logging-schema/compare/v3.0.0...v3.1.0
4957
[v3.0.0]: https://github.com/gchq/event-logging-schema/compare/v3.0.0...v3.0.0

docs/releaseProcess.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ The definition of breaking change is one which is not backwards compatible with
2222
1. Increment the major version number in `targetNamespace`, e.g. `event-logging:4`
2323
1. Change the `version` attribute to the intended version number, e.g. `4.1.2`
2424
1. Change the `id` attribute to the intended version number, e.g. `event-logging-v4.1.2`
25+
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.
26+
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)
2527
1. Ensure CHANGELOG.md has all changes documented in it
2628
1. Commit and push the new version number changes
2729
1. Create a tag in git for the new release, e.g. `git tag v4.1.2`

event-logging.xsd

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
targetNamespace="event-logging:3"
2020
elementFormDefault="qualified"
2121
attributeFormDefault="unqualified"
22-
version="3.2.0-SNAPSHOT"
23-
id="event-logging-v3.2.0-SNAPSHOT">
22+
version="3.1.1"
23+
id="event-logging-v3.1.1">
2424
<xs:annotation>
2525
<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>
2626
</xs:annotation>
@@ -3192,11 +3192,12 @@
31923192
</xs:simpleType>
31933193
<xs:simpleType name="VersionSimpleType">
31943194
<xs:annotation>
3195-
<xs:documentation>Type for specifying version numbers in a common way, e.g. 2.4</xs:documentation>
3195+
<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>
31963196
</xs:annotation>
31973197
<xs:restriction base="xs:string">
3198-
<xs:pattern value="[0-9]+(\.[0-9]+)*"/>
31993198
<xs:enumeration value="3.0.0"/>
3199+
<xs:enumeration value="3.1.0"/>
3200+
<xs:enumeration value="3.1.1"/>
32003201
</xs:restriction>
32013202
</xs:simpleType>
32023203
<xs:simpleType name="VirtualSessionSessionStateSimpleType">

validateSchemaVersions.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env python
2+
#**********************************************************************
3+
# Copyright 2016 Crown Copyright
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#**********************************************************************
17+
18+
19+
#**********************************************************************
20+
# Script to ensure all the version numbers in the event-logging
21+
# XMLSchema are valid
22+
#**********************************************************************
23+
24+
25+
import os
26+
import re
27+
import xml.etree.ElementTree as ET
28+
29+
SCHEMA_FILENAME = "event-logging.xsd"
30+
31+
root_path = os.path.dirname(os.path.realpath(__file__))
32+
33+
def getMinorVersion(versionStr):
34+
minorVer = re.match("[0-9]*\.([0-9]*)\..*", versionStr).group(1)
35+
return minorVer
36+
37+
def validateVersions():
38+
print "Validating file %s" % SCHEMA_FILENAME
39+
print ""
40+
41+
# pattern = re.compile("xmlns:evt\"event-logging:.*\"")
42+
xsdFile = open(SCHEMA_FILENAME, 'r')
43+
filetext = xsdFile.read()
44+
xsdFile.close()
45+
matches = re.findall("xmlns:evt=\"event-logging:(.*)\"", filetext)
46+
if (len(matches) != 1):
47+
raise ValueError("Unexpected matches for evt namespace", matches)
48+
namespaceVersion = matches[0]
49+
print "namespace version: %s" % namespaceVersion
50+
51+
xml_root = ET.parse(SCHEMA_FILENAME).getroot()
52+
53+
targetNamespaceAttr = xml_root.get("targetNamespace")
54+
targetNamespaceVersion = re.match(".*:([0-9]*)$", targetNamespaceAttr).group(1)
55+
print "targetNamespace: %s" % targetNamespaceVersion
56+
57+
versionAttrVersion = xml_root.get("version")
58+
print "version: %s" % versionAttrVersion
59+
60+
idAttr = xml_root.get("id")
61+
idAttrVersion = re.match("event-logging-v([0-9\.]*)", idAttr).group(1)
62+
print "id: %s" % idAttrVersion
63+
64+
ns = {'xs': 'http://www.w3.org/2001/XMLSchema'}
65+
enumVersions = []
66+
print "Version enumerations:"
67+
for enumElm in xml_root.findall("./xs:simpleType[@name='VersionSimpleType']/xs:restriction/xs:enumeration", ns):
68+
print " %s" % enumElm.get("value")
69+
enumVersions.append(enumElm.get("value"))
70+
71+
# print enumVersions
72+
73+
if (namespaceVersion != targetNamespaceVersion):
74+
raise ValueError("namespace version and targetNamespace version do not match", namespaceVersion, targetNamespaceVersion)
75+
76+
versionRegex = "[0-9]+\.[0-9]+\.[0-9]+"
77+
if (not re.match(versionRegex, versionAttrVersion)):
78+
raise ValueError("version attribute does not match the valid regex", versionAttrVersion, versionRegex)
79+
80+
if (versionAttrVersion != idAttrVersion):
81+
raise ValueError("version attribute and id attribute do not match", versionAttrVersion, idAttrVersion)
82+
83+
if (not versionAttrVersion.startswith(targetNamespaceVersion)):
84+
raise ValueError("Major version of the version attribute does not match the targetNamespace version", versionAttrVersion, targetNamespaceVersion)
85+
86+
if (not versionAttrVersion in enumVersions):
87+
raise ValueError("Schema version is not in the list of version enumerations", versionAttrVersion, enumVersions)
88+
89+
minorVer = getMinorVersion(versionAttrVersion)
90+
91+
for enumVer in enumVersions:
92+
if (not enumVer.startswith(targetNamespaceVersion)):
93+
raise ValueError("Major version of the enumeration version does not match the targetNamespace version", enumVer, targetNamespaceVersion)
94+
minorVerOfEnum = getMinorVersion(enumVer)
95+
96+
if (minorVerOfEnum > minorVer):
97+
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)
98+
99+
100+
101+
validateVersions()
102+
103+
print ""
104+
print "Done!"
105+
exit(0)

0 commit comments

Comments
 (0)