Skip to content

Commit d6bb79c

Browse files
Fix CI for DM XMLs (project-chip#34907)
* Fix CI for data model changes * test change * Apply suggestions from code review * Update .github/workflows/check-data-model-directory-updates.yaml * update the workflow * Restyled by isort * linter * Not sure why this isn't running, remove condition * a bit more * Exit with correct code * simplify the checkout a bit * also allow scraper version changes * Revert "test change" This reverts commit 67eea59. --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 79c73bf commit d6bb79c

File tree

2 files changed

+70
-10
lines changed

2 files changed

+70
-10
lines changed

.github/workflows/check-data-model-directory-updates.yaml

+18-10
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,28 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
name: Check for changes to data_model directory without a sha update
15+
name: Data model directory checks
1616

1717
on:
1818
pull_request:
19-
paths:
20-
- "data_model/**"
2119

2220
jobs:
23-
check-submodule-update-label:
24-
name: Check for changes to data_model directory without a sha update
21+
check-data_model-updates:
22+
name: Check for updates to data model directory without SHA updates
2523
runs-on: ubuntu-latest
26-
if: "git diff --name-only HEAD^..HEAD data_model/ | grep -q spec_sha"
24+
container:
25+
image: ghcr.io/project-chip/chip-build
2726
steps:
28-
- name: Error Message
29-
run: echo This pull request attempts to update data_model directory, but is missing updates to spec_sha file with the latest version of the sha. Files in the data_model directory are generated automatically and should not be updated manually.
30-
- name: Fail Job
31-
run: exit 1
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 2
31+
- name: Check for changes to master data_model directory without a SHA update
32+
run: |
33+
python3 scripts/dm_xml_ci_change_enforcement.py data_model/master
34+
- name: Check for changes to 1.3 data_model directory without a SHA update
35+
run: |
36+
python3 scripts/dm_xml_ci_change_enforcement.py data_model/1.3
37+
- name: Check for changes to 1.4 data_model directory without a SHA update
38+
run: |
39+
python3 scripts/dm_xml_ci_change_enforcement.py data_model/1.4
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright (c) 2024 Project CHIP Authors
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+
import os
17+
import subprocess
18+
import sys
19+
20+
import click
21+
22+
23+
@click.command()
24+
@click.argument('dir', nargs=1, type=click.Path(exists=True))
25+
def check_dm_directory(dir):
26+
clusters = os.path.join(dir, 'clusters')
27+
device_types = os.path.join(dir, 'device_types')
28+
if not os.path.isdir(clusters) or not os.path.isdir(device_types):
29+
print(f"Invalid data model directory {dir}")
30+
sys.exit(1)
31+
32+
# We are operating in a VM, and although there is a checkout, it is working in a scratch directory
33+
# where the ownership is different than the runner.
34+
# Adding an exception for this directory so that git can function properly.
35+
subprocess.run("git config --global --add safe.directory '*'", shell=True)
36+
37+
def check_dir(dir):
38+
cmd = f'git diff HEAD^..HEAD --name-only -- {dir}'
39+
output = subprocess.check_output(cmd, shell=True).decode().splitlines()
40+
if output and 'spec_sha' not in output and 'scraper_version' not in output:
41+
print(f'Data model directory {dir} had changes to the following files without a corresponding update to the spec SHA')
42+
print(output)
43+
print("Note that the data_model directory files are automatically updated by a spec scraper and should not be manually updated.")
44+
return 1
45+
return 0
46+
47+
ret = check_dir(clusters) + check_dir(device_types)
48+
sys.exit(ret)
49+
50+
51+
if __name__ == '__main__':
52+
check_dm_directory()

0 commit comments

Comments
 (0)