diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml new file mode 100644 index 0000000..e07c82c --- /dev/null +++ b/.github/workflows/python-ci.yml @@ -0,0 +1,31 @@ +name: python-ci-main + +on: + pull_request: + paths: + - '/versions/v1/units.json' + branches: + - main + +jobs: + compare-json: + runs-on: ubuntu-latest + steps: + - name: Checkout main + uses: actions/checkout@v3 + with: + ref: main + path: main + + - name: Checkout PR + uses: actions/checkout@v3 + with: + path: pr + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Compare JSON + run: python ./src/compare_external_ids.py diff --git a/README.md b/README.md index 8652107..5489e82 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ To ensure the integrity of the catalog, the following tests are conducted: 5. **Consistent References**: All quantity references in `unitSystems.json` must exist in `units.json`. 6. **Unique aliases**: All pairs of (`alias` and `quantity`) must be unique, for all **aliases** in `aliasNames`. 7. **ExternalId Format**: All unit `externalIds` must follow the pattern `{quantity}:{unit}`, where both `quantity` and `unit` are in **snake_case**. +8. **Avoid breaking changes**: There can be no removals of unit `externalIds` in `units.json`. Only additions are supported. ## Attribution Some of the units are sourced from QUDT.org, which is licensed under the [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/). diff --git a/src/compare_external_ids.py b/src/compare_external_ids.py new file mode 100644 index 0000000..95a43ce --- /dev/null +++ b/src/compare_external_ids.py @@ -0,0 +1,20 @@ +import json + + +def get_external_ids(file_path: str) -> set: + with open(file_path, "r") as f: + data = json.load(f) + return set(item["externalId"] for item in data) + + +main_external_ids: set = get_external_ids("main/versions/v1/units.json") +pr_external_ids: set = get_external_ids("pr/versions/v1/units.json") + +# 8. Avoid breaking changes: There can be no removals of unit `externalIds` in `units.json`. +# Only additions are supported. +removed_external_ids: set = main_external_ids - pr_external_ids + +if removed_external_ids: + raise Exception( + f'externalId(s) [{", ".join(removed_external_ids)}] have been removed from the unit catalogue.' + ) diff --git a/versions/v1/units.json b/versions/v1/units.json index ba0edf8..e553a77 100644 --- a/versions/v1/units.json +++ b/versions/v1/units.json @@ -47,55 +47,6 @@ "source": "qudt.org", "sourceReference": "http://qudt.org/vocab/unit/FT-PER-SEC2" }, - { - "externalId": "acceleration:in-per-sec2", - "name": "IN-PER-SEC2", - "quantity": "Acceleration", - "longName": "Inch per Square second", - "aliasNames": [ - "in per square second", - "Inch / SEC2", - "IN / square second", - "IN PER SEC2", - "inch / SEC2", - "Inch per s²", - "in / Square Second", - "inch / s²", - "in / square second", - "Inch per Square Second", - "Inch / Square Second", - "Inch / square second", - "Inch / s²", - "inch / Square Second", - "in / SEC2", - "in / s²", - "inch / square second", - "inch per square second", - "Inch per Square second", - "Inch per SEC2", - "in per Square Second", - "Inch per square second", - "inch per Square Second", - "IN per Square Second", - "inch per s²", - "in per s²", - "IN / s²", - "IN per s²", - "inch per SEC2", - "IN / Square Second", - "in per SEC2", - "IN per square second", - "IN per SEC2", - "IN / SEC2" - ], - "symbol": "in/s²", - "conversion": { - "multiplier": 0.0254, - "offset": 0.0 - }, - "source": "qudt.org", - "sourceReference": "http://qudt.org/vocab/unit/IN-PER-SEC2" - }, { "externalId": "acceleration:m-per-sec2", "name": "M-PER-SEC2",