|
5 | 5 | import datetime |
6 | 6 | import hashlib |
7 | 7 | import json |
| 8 | +import os |
8 | 9 | import pathlib |
9 | 10 | import shutil |
10 | 11 | import time |
@@ -472,29 +473,26 @@ def compare_json_content(f1: str, f2: str) -> bool: |
472 | 473 | return False |
473 | 474 |
|
474 | 475 |
|
475 | | -def compare_xml_content(f1: str, f2: str) -> bool: |
| 476 | +def compare_xml_content(a: str, b: str) -> bool: |
476 | 477 | """ |
477 | 478 | Compare the contents of two XML files and report |
478 | | - if the contents are the same, minus comments |
479 | | - :param f1: File 1 |
480 | | - :param f2: File 2 |
481 | | - :return: Is file content, minus comments, the same? |
| 479 | + if the contents are the same, minus the info part and comments |
| 480 | + :param a: File a |
| 481 | + :param b: File b |
| 482 | + :return: Is file content, minus info and comments, the same? |
482 | 483 | """ |
483 | | - file1 = pathlib.Path(f1) |
484 | | - file2 = pathlib.Path(f2) |
| 484 | + files = [pathlib.Path(file_n) for file_n in (a, b)] |
485 | 485 |
|
486 | | - if file1.is_file() and file2.is_file(): |
487 | | - parser = etree.XMLParser(remove_blank_text=True) |
488 | | - root = etree.parse(str(file1), parser).getroot() |
489 | | - etree.strip_tags(root, etree.Comment) |
490 | | - f1_hash = hashlib.sha512(etree.tostring(root)).hexdigest() |
| 486 | + if all([filepath.is_file() for filepath in files]): |
| 487 | + hashes = [] |
| 488 | + for filepath in files: |
| 489 | + parser = etree.XMLParser(remove_blank_text=True) |
| 490 | + root = etree.parse(str(filepath), parser).getroot() |
| 491 | + etree.strip_elements(root, "info", etree.Comment) |
| 492 | + digest = hashlib.sha512(etree.tostring(root)).hexdigest() |
| 493 | + hashes.append(digest) |
491 | 494 |
|
492 | | - parser = etree.XMLParser(remove_blank_text=True) |
493 | | - root = etree.parse(str(file2), parser).getroot() |
494 | | - etree.strip_tags(root, etree.Comment) |
495 | | - f2_hash = hashlib.sha512(etree.tostring(root)).hexdigest() |
496 | | - |
497 | | - return f1_hash == f2_hash |
| 495 | + return hashes[0] == hashes[1] |
498 | 496 |
|
499 | 497 | return False |
500 | 498 |
|
@@ -655,11 +653,17 @@ def main() -> None: |
655 | 653 | changed |= delete_old_files() |
656 | 654 |
|
657 | 655 | # Enable deployment on changes (used in CI) |
658 | | - if changed: |
659 | | - print("::set-output name=deploy::true") |
| 656 | + try: |
| 657 | + github_output = os.environ["GITHUB_OUTPUT"] |
| 658 | + except KeyError: |
| 659 | + print(f"not in ci but deploy={str(changed).lower()}") |
660 | 660 | else: |
661 | | - print("::set-output name=deploy::false") |
662 | | - print("::notice title=No updates available::No new spoiler cards found for deployment") |
| 661 | + with open(github_output, "a") as fp: |
| 662 | + print(f"deploy={str(changed).lower()}", file=fp) |
| 663 | + |
| 664 | + if not changed: |
| 665 | + print("::notice title=No updates available::" |
| 666 | + "No new spoiler cards found for deployment") |
663 | 667 |
|
664 | 668 |
|
665 | 669 | if __name__ == "__main__": |
|
0 commit comments