Skip to content

Commit 1a57a87

Browse files
committed
fix(wifi_remote): Fix checking API compat against reference dir
rather than git history, as it might now work in GitHub CI (due to shallow cloning)
1 parent 73c4830 commit 1a57a87

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

.github/workflows/wifi_remote__build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ jobs:
2424
run: |
2525
. ${IDF_PATH}/export.sh
2626
pip install idf-component-manager idf-build-apps --upgrade
27+
cp -r ./components/esp_wifi_remote ./components/esp_wifi_remote_base
2728
cd ./components/esp_wifi_remote/scripts
28-
python generate_and_check.py
29+
python generate_and_check.py --base-dir ../../esp_wifi_remote_base
2930
3031
build_wifi_remote:
3132
if: contains(github.event.pull_request.labels.*.name, 'wifi_remote') || github.event_name == 'push'

components/esp_wifi_remote/scripts/generate_and_check.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,25 @@ def generate_kconfig(idf_path, component_path):
332332
return [remote_kconfig]
333333

334334

335+
def compare_files(base_dir, component_path, files_to_check):
336+
failures = []
337+
for file_path in files_to_check:
338+
relative_path = os.path.relpath(file_path, component_path)
339+
base_file = os.path.join(base_dir, relative_path)
340+
341+
if not os.path.exists(base_file):
342+
failures.append((relative_path, 'File does not exist in base directory'))
343+
continue
344+
345+
diff_cmd = ['diff', '-I', 'Copyright', file_path, base_file]
346+
result = subprocess.run(diff_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
347+
348+
if result.returncode != 0: # diff returns 0 if files are identical
349+
failures.append((relative_path, result.stdout.decode('utf-8')))
350+
351+
return failures
352+
353+
335354
if __name__ == '__main__':
336355
parser = argparse.ArgumentParser(
337356
description='Build all projects',
@@ -346,6 +365,7 @@ def generate_kconfig(idf_path, component_path):
346365
making changes you might need to modify 'copyright_header.h' in the script directory.
347366
''')
348367
parser.add_argument('-s', '--skip-check', help='Skip checking the versioned files against the re-generated', action='store_true')
368+
parser.add_argument('--base-dir', help='Base directory to compare generated files against', required=True)
349369
args = parser.parse_args()
350370

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

372392
files_to_check += generate_kconfig(idf_path, component_path)
373393

374-
fail_test = False
375-
failures = []
376-
for f in files_to_check:
377-
print(f'checking {f}')
378-
rc, out, err, cmd = exec_cmd(['git', 'difftool', '-y', '-x', 'diff -I Copyright', '--', f])
379-
if out == '' or out.isspace():
380-
print(' - ok')
381-
else:
382-
print(' - FAILED!')
383-
failures.append((f, out))
384-
fail_test = True
385-
386-
if fail_test:
394+
if args.skip_check:
395+
exit(0)
396+
397+
failures = compare_files(args.base_dir, component_path, files_to_check)
398+
399+
if failures:
387400
print(parser.epilog)
388-
print('\nDIfferent files:\n')
389-
for i in failures:
390-
print(f'{i[0]}\nChanges:\n{i[1]}')
401+
print('\nDifferent files:\n')
402+
for file, diff in failures:
403+
print(f'{file}\nChanges:\n{diff}')
391404
exit(1)
405+
else:
406+
print('All files are identical to the base directory.')
407+
exit(0)

0 commit comments

Comments
 (0)