Skip to content

Commit

Permalink
fix(wifi_remote): Fix checking API compat against reference dir
Browse files Browse the repository at this point in the history
rather than git history, as it might now work in GitHub CI (due to
shallow cloning)
  • Loading branch information
david-cermak committed Sep 26, 2024
1 parent 73c4830 commit 1a57a87
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/wifi_remote__build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ jobs:
run: |
. ${IDF_PATH}/export.sh
pip install idf-component-manager idf-build-apps --upgrade
cp -r ./components/esp_wifi_remote ./components/esp_wifi_remote_base
cd ./components/esp_wifi_remote/scripts
python generate_and_check.py
python generate_and_check.py --base-dir ../../esp_wifi_remote_base
build_wifi_remote:
if: contains(github.event.pull_request.labels.*.name, 'wifi_remote') || github.event_name == 'push'
Expand Down
48 changes: 32 additions & 16 deletions components/esp_wifi_remote/scripts/generate_and_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,25 @@ def generate_kconfig(idf_path, component_path):
return [remote_kconfig]


def compare_files(base_dir, component_path, files_to_check):
failures = []
for file_path in files_to_check:
relative_path = os.path.relpath(file_path, component_path)
base_file = os.path.join(base_dir, relative_path)

if not os.path.exists(base_file):
failures.append((relative_path, 'File does not exist in base directory'))
continue

diff_cmd = ['diff', '-I', 'Copyright', file_path, base_file]
result = subprocess.run(diff_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

if result.returncode != 0: # diff returns 0 if files are identical
failures.append((relative_path, result.stdout.decode('utf-8')))

return failures


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Build all projects',
Expand All @@ -346,6 +365,7 @@ def generate_kconfig(idf_path, component_path):
making changes you might need to modify 'copyright_header.h' in the script directory.
''')
parser.add_argument('-s', '--skip-check', help='Skip checking the versioned files against the re-generated', action='store_true')
parser.add_argument('--base-dir', help='Base directory to compare generated files against', required=True)
args = parser.parse_args()

component_path = os.path.normpath(os.path.join(os.path.realpath(__file__),'..', '..'))
Expand All @@ -371,21 +391,17 @@ def generate_kconfig(idf_path, component_path):

files_to_check += generate_kconfig(idf_path, component_path)

fail_test = False
failures = []
for f in files_to_check:
print(f'checking {f}')
rc, out, err, cmd = exec_cmd(['git', 'difftool', '-y', '-x', 'diff -I Copyright', '--', f])
if out == '' or out.isspace():
print(' - ok')
else:
print(' - FAILED!')
failures.append((f, out))
fail_test = True

if fail_test:
if args.skip_check:
exit(0)

failures = compare_files(args.base_dir, component_path, files_to_check)

if failures:
print(parser.epilog)
print('\nDIfferent files:\n')
for i in failures:
print(f'{i[0]}\nChanges:\n{i[1]}')
print('\nDifferent files:\n')
for file, diff in failures:
print(f'{file}\nChanges:\n{diff}')
exit(1)
else:
print('All files are identical to the base directory.')
exit(0)

0 comments on commit 1a57a87

Please sign in to comment.