Skip to content

Commit

Permalink
Fix CI for DM XMLs (project-chip#34907)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
cecille and restyled-commits authored Dec 13, 2024
1 parent 79c73bf commit d6bb79c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 10 deletions.
28 changes: 18 additions & 10 deletions .github/workflows/check-data-model-directory-updates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.

name: Check for changes to data_model directory without a sha update
name: Data model directory checks

on:
pull_request:
paths:
- "data_model/**"

jobs:
check-submodule-update-label:
name: Check for changes to data_model directory without a sha update
check-data_model-updates:
name: Check for updates to data model directory without SHA updates
runs-on: ubuntu-latest
if: "git diff --name-only HEAD^..HEAD data_model/ | grep -q spec_sha"
container:
image: ghcr.io/project-chip/chip-build
steps:
- name: Error Message
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.
- name: Fail Job
run: exit 1
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check for changes to master data_model directory without a SHA update
run: |
python3 scripts/dm_xml_ci_change_enforcement.py data_model/master
- name: Check for changes to 1.3 data_model directory without a SHA update
run: |
python3 scripts/dm_xml_ci_change_enforcement.py data_model/1.3
- name: Check for changes to 1.4 data_model directory without a SHA update
run: |
python3 scripts/dm_xml_ci_change_enforcement.py data_model/1.4
52 changes: 52 additions & 0 deletions scripts/dm_xml_ci_change_enforcement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3

# Copyright (c) 2024 Project CHIP Authors
#
# 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.
import os
import subprocess
import sys

import click


@click.command()
@click.argument('dir', nargs=1, type=click.Path(exists=True))
def check_dm_directory(dir):
clusters = os.path.join(dir, 'clusters')
device_types = os.path.join(dir, 'device_types')
if not os.path.isdir(clusters) or not os.path.isdir(device_types):
print(f"Invalid data model directory {dir}")
sys.exit(1)

# We are operating in a VM, and although there is a checkout, it is working in a scratch directory
# where the ownership is different than the runner.
# Adding an exception for this directory so that git can function properly.
subprocess.run("git config --global --add safe.directory '*'", shell=True)

def check_dir(dir):
cmd = f'git diff HEAD^..HEAD --name-only -- {dir}'
output = subprocess.check_output(cmd, shell=True).decode().splitlines()
if output and 'spec_sha' not in output and 'scraper_version' not in output:
print(f'Data model directory {dir} had changes to the following files without a corresponding update to the spec SHA')
print(output)
print("Note that the data_model directory files are automatically updated by a spec scraper and should not be manually updated.")
return 1
return 0

ret = check_dir(clusters) + check_dir(device_types)
sys.exit(ret)


if __name__ == '__main__':
check_dm_directory()

0 comments on commit d6bb79c

Please sign in to comment.