Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflows to validate and formatting fixes #28

Merged
merged 113 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
9c1052b
Merge pull request #16 from ukaea/bugfix/convert-to-camel-case
adam-parker1 Sep 10, 2024
7e94af6
Fix diagnostic schema and example
NathanCummings Sep 13, 2024
09b6eff
Merge pull request #17 from ukaea/feature/fix-example
NathanCummings Sep 13, 2024
647836c
feat: add custom camel case validator to git action
khalsz Sep 18, 2024
0fc0dfa
fix: add multiple file to json lint schema validation
khalsz Sep 18, 2024
1e97e6c
Merge pull request #1 from khalsz/bugfix/convert-to-camel-case
khalsz Sep 18, 2024
4b6db3f
fix: typo error in workflow file
khalsz Sep 18, 2024
a497538
Merge pull request #2 from khalsz/bugfix/convert-to-camel-case
khalsz Sep 18, 2024
c96139f
fix: typo bug in workflow
khalsz Sep 18, 2024
8c0cffd
Merge pull request #3 from khalsz/bugfix/convert-to-camel-case
khalsz Sep 18, 2024
ea7223c
fix: typo bug in workflow
khalsz Sep 18, 2024
18f791e
Merge pull request #4 from khalsz/bugfix/convert-to-camel-case
khalsz Sep 18, 2024
0b51c80
fix: typo bug in workflow
khalsz Sep 18, 2024
735aac6
Merge pull request #5 from khalsz/bugfix/convert-to-camel-case
khalsz Sep 18, 2024
1ed7104
fix: typo bug in workflow
khalsz Sep 18, 2024
e537e4c
Merge pull request #6 from khalsz/bugfix/convert-to-camel-case
khalsz Sep 18, 2024
7e80b42
Update medata-ci-workflows.yml
khalsz Sep 18, 2024
3fcae01
Update medata-ci-workflows.yml
khalsz Sep 18, 2024
c23d602
Update medata-ci-workflows.yml
khalsz Sep 18, 2024
fdb3b36
Update medata-ci-workflows.yml
khalsz Sep 18, 2024
1d29c98
Update medata-ci-workflows.yml
khalsz Sep 18, 2024
b3c194a
Update medata-ci-workflows.yml
khalsz Sep 18, 2024
bb8c641
Update medata-ci-workflows.yml
khalsz Sep 18, 2024
2f8aa81
Update medata-ci-workflows.yml
khalsz Sep 18, 2024
335d438
Update medata-ci-workflows.yml
khalsz Sep 18, 2024
bd48a7b
Update medata-ci-workflows.yml
khalsz Sep 18, 2024
93e3d25
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
7e82c96
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
99f47c0
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
56eec7c
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
4400b7d
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
9a4bf21
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
7388667
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
920f8d0
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
205fa21
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
f36dbc4
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
ed9a63c
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
ea502b4
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
a5d65df
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
df2ffe2
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
96fe6c5
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
354ad49
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
d3d4e64
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
a54f726
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
cd7f25a
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
7e391bc
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
1162148
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
b76c25f
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
044f55d
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
a4ca89c
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
74b6965
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
2621b85
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
8486500
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
44e26af
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
005684a
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
05aac1c
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
3431478
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
10ce7e3
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
992c94b
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
a0f851c
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
cd346fe
fix: change json file validator package
khalsz Sep 19, 2024
ab56308
fix: change json file validator package
khalsz Sep 19, 2024
be7608b
Merge branch 'main' into bugfix/convert-to-camel-case
khalsz Sep 19, 2024
d26749f
Merge pull request #7 from khalsz/bugfix/convert-to-camel-case
khalsz Sep 19, 2024
9e1450a
Merge pull request #8 from khalsz/main
khalsz Sep 19, 2024
05da49e
Merge pull request #9 from khalsz/bugfix/convert-to-camel-case
khalsz Sep 19, 2024
29a8eb4
fix: change json file validator package
khalsz Sep 19, 2024
500c735
fix: errors
khalsz Sep 19, 2024
af150a1
Revert "fix: change json file validator package"
khalsz Sep 19, 2024
7ddb5b7
fix: remote pull
khalsz Sep 19, 2024
1223941
feat: add new json validator package
khalsz Sep 19, 2024
698640d
Merge pull request #10 from khalsz/bugfix/convert-to-camel-case
khalsz Sep 19, 2024
7bf2c5f
fix: Error in worlflow file
khalsz Sep 19, 2024
5fb828e
Merge pull request #11 from khalsz/bugfix/convert-to-camel-case
khalsz Sep 19, 2024
97dec28
fix: sample.schema.json validation error
khalsz Sep 19, 2024
a1fd98e
Merge pull request #12 from khalsz/bugfix/convert-to-camel-case
khalsz Sep 19, 2024
2a3f28b
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
3c93cde
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
4f19e52
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
ae9eeff
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
1ec388f
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
4a6819f
Update medata-ci-workflows.yml
khalsz Sep 19, 2024
4601e7c
Pull: from remote main to use cardinality validator
khalsz Sep 19, 2024
4e619f6
fix: changed schema-based validator package to cardinalby
khalsz Sep 19, 2024
ecdca5a
fix: faclity json has wrong facility-id value
khalsz Sep 19, 2024
dc34065
fix: error in custom validation python file
khalsz Sep 19, 2024
b5b06e2
fix: file path error in custom validation python file
khalsz Sep 19, 2024
3613970
Revert "fix: error in custom validation python file"
khalsz Sep 19, 2024
b84362e
fix: revert to python bug fix
khalsz Sep 19, 2024
b397781
fix: json file argument
khalsz Sep 19, 2024
23ffb5f
fix: json file argument
khalsz Sep 19, 2024
0380d68
fix: Error and regex pattern in calidate_camel_case.py
khalsz Sep 20, 2024
abfc40f
fix: convert args for python file into list
khalsz Sep 20, 2024
3c0a26f
fix: convert args for python file into list
khalsz Sep 20, 2024
032ae42
fix: convert args for python file into list
khalsz Sep 20, 2024
186cb3f
fix: convert args for python file into list
khalsz Sep 20, 2024
043ba35
fix: convert args for python file into list
khalsz Sep 20, 2024
34b3165
fix: convert args for python file into list
khalsz Sep 20, 2024
ce865f3
fix: changed python file to accept single args
khalsz Sep 20, 2024
b4158fb
fix: changed python file to accept single args
khalsz Sep 20, 2024
ebef1fe
feat: Add snack case to check camelCase validator
khalsz Sep 20, 2024
e01904a
fix: adjusted the rege4x pattern to match more than 1 upper after low…
khalsz Sep 20, 2024
6281df2
fix: adjusted the rege4x pattern to match more than 1 upper after low…
khalsz Sep 20, 2024
f60cca8
fix: returned adjusted case
khalsz Sep 20, 2024
cdf29c3
feat: added exit to python code if validation fails
khalsz Sep 20, 2024
6735713
feat: added exit to python code if validation fails
khalsz Sep 20, 2024
3ec6e68
feat: added exit to python code if validation fails
khalsz Sep 20, 2024
8e07311
feat: added exit to python code if validation fails
khalsz Sep 20, 2024
c979b1c
fix: changed error message
khalsz Sep 20, 2024
51f99a7
fix: returned campaign.schema.json file to normal
khalsz Sep 20, 2024
ad740ea
Merge pull request #20 from ukaea/feat/schema-validation-workflow
khalsz Sep 20, 2024
1c021f6
fix: returned campaign.schema.json file to normal
khalsz Sep 20, 2024
bc87b24
Merge pull request #21 from ukaea/feat/schema-validation-workflow
khalsz Sep 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/medata-ci-workflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Metadata CI Workflow
on:
push:
branches:
- main
pull_request:
branches:
- main


jobs:
validate-json:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: validate-json-files
id: json-validate
uses: GrantBirki/json-yaml-validate@v3
with:
comment: "true"

- name: Validate campaign JSON
uses: cardinalby/schema-validator-action@v3
with:
schema: ukaea-schema/facility/hive/campaign.schema.json
file: ./ukaea-schema/examples/hive/campaign.json
- name: Validate experiment JSON
uses: cardinalby/schema-validator-action@v3
with:
schema: ./ukaea-schema/facility/hive/campaign.schema.json
file: ./ukaea-schema/examples/hive/campaign.json

# - name: Validate facility JSON
# uses: cardinalby/schema-validator-action@v3
# with:
# schema: ./ukaea-schema/facility/facility.schema.json
# file: ./ukaea-schema/examples/facility.json
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: custom-camel-case-validation
run: |
readarray -d '' json_file_paths < <(find . -name *.json -print0)
echo ${json_file_paths[@]}
for json_file in ${json_file_paths[@]}; do
python validate_camel_case.py $json_file
done

1 change: 1 addition & 0 deletions scicat-schema/scicat.sample.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"key": "value"}
53 changes: 38 additions & 15 deletions ukaea-schema/examples/hive/experiment.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"campaignID": "HIVE-20230901",
"experimentID": "HIVE-E-20230905",
"campaignID": "HIVE-20230901",
"experimentID": "HIVE-E-20230905",
"leadInvestigator": {
"firstName": "Alice",
"lastName": "Johnson",
"email": "[email protected]"
},
"customer": "ACME Corp",
"experimentStart": "2023-09-05T10:00:00Z",
"experimentEnd": "2023-09-05T16:00:00Z",
"experimentType": "Induction",
"experimentStart": "2023-09-05T10:00:00Z",
"experimentEnd": "2023-09-05T16:00:00Z",
"experimentType": "Induction",
"sampleCooling": true,
"pulse": {
"pulseID": "123e4567-e89b-12d3-a456-426614174000",
"pulseID": "123e4567-e89b-12d3-a456-426614174000",
"firstOperator": {
"firstName": "Bob",
"lastName": "Smith",
Expand All @@ -23,9 +23,9 @@
"lastName": "Davis",
"email": "[email protected]"
},
"pulseStart": "2023-09-05T12:00:00Z",
"pulseDuration": 120,
"dataCaptureStart": "2023-09-05T12:00:10Z",
"pulseStart": "2023-09-05T12:00:00Z",
"pulseDuration": 120,
"dataCaptureStart": "2023-09-05T12:00:10Z",
"operatorComment": "Pulse completed without issues. Slight delay in data capture start.",
"pulseQuality": "Success",
"coolantInformation": {
Expand Down Expand Up @@ -62,6 +62,8 @@
},
"diagnostics": [
{
"diagnosticName": "TC01",
"diagnosticType": "Thermocouple",
"port": {
"portID": "Port_1",
"portDescription": "Front Port",
Expand All @@ -71,13 +73,19 @@
"status": "Active",
"attachment": "spot weld with inert gas shield",
"tcType": "K",
"location": [18.065, 2.355, 23.0],
"location": [
18.065,
2.355,
23.0
],
"areaType": "Circular",
"circleDiameter": 1.31,
"noiseFloor": "not captured - assume standard resolution"
}
},
{
"diagnosticName": "Cam01",
"diagnosticType": "Camera",
"port": {
"portID": "Port_6",
"portDescription": "Bottom Port",
Expand All @@ -100,7 +108,10 @@
"patternSpeckle": "White speckles",
"approxFeatureSize": 50.0,
"calTargetMake": "OptiCal",
"calTargetDims": [100, 100],
"calTargetDims": [
100,
100
],
"calTargetSpacing": 0.5
},
"cameraSetup": {
Expand All @@ -110,15 +121,21 @@
"make": "Canon",
"model": "EOS 5D Mark IV",
"serialNumber": "CN12345678",
"resolution": [6720, 4480]
"resolution": [
6720,
4480
]
},
"lensInformation": {
"make": "Canon",
"model": "EF 50mm f/1.8",
"serialNumber": "LN98765432",
"focalLength": 50,
"aperture": "f/1.8",
"fieldOfView": [6720, 4480]
"fieldOfView": [
6720,
4480
]
},
"captureSettings": {
"imageAcquisitionRate": 30,
Expand All @@ -131,15 +148,21 @@
"make": "Nikon",
"model": "D850",
"serialNumber": "NK87654321",
"resolution": [8256, 5504]
"resolution": [
8256,
5504
]
},
"lensInformation": {
"make": "Nikon",
"model": "AF-S NIKKOR 24-70mm f/2.8E",
"serialNumber": "LN12345678",
"focalLength": 70,
"aperture": "f/2.8",
"fieldOfView": [8256, 5504]
"fieldOfView": [
8256,
5504
]
},
"captureSettings": {
"imageAcquisitionRate": 25,
Expand Down
2 changes: 2 additions & 0 deletions ukaea-schema/facility/hive/diagnostic.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"description": "Metadata schema for a HIVE diagnostic",
"type": "object",
"required": [
"diagnosticName",
"diagnosticType",
"port",
"diagnostic"
],
Expand Down
57 changes: 57 additions & 0 deletions validate_camel_case.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import re
import json
import argparse
from pathlib import Path
import sys


# regex to match camel case
def match_camel_case(s):
# match camelCase format using regular expression
return bool(re.match(r'^[$a-z]+([.A-Z0-9]+[a-z]*)*$', s))


def validate_camel_case(data):
# validate camelCase in json key
for key, value in data.items():
if not match_camel_case(key):
return False, f"Invalid key format (not CamelCase): {key}"

# check if json value is a dictionary
if isinstance(value, dict):
is_valid, message = validate_camel_case(value) # recursive check nested dictionary
if not is_valid:
return False, f"{message}"
return True, None


def val_json_file(json_file):
# initialize empty list to store error result for invalid json file validation
try:
with open(Path(json_file), 'r') as jf:
data = json.load(jf)
is_valid, message = validate_camel_case(data)
if not is_valid:
# append result of json file with non cameCase keys
print(f"json file: {json_file} contains {message}")
sys.exit(1)
else:
return(f"json file: {json_file} contains valid camelCase keys")
except json.JSONDecodeError as e:
# append result of invalid json file
print(f"Error in file {json_file}, Invalid JSON format {e}")
sys.exit(1)





if __name__ == "__main__":

parser = argparse.ArgumentParser(description="all json files in the repository")
parser.add_argument("json_file_paths", type=str,
help="pass the paths to all json files in the repository")
arg = parser.parse_args()

validation_result = val_json_file(arg.json_file_paths)
print(validation_result)
Loading