From 6a927073548945c0516c2ae1c3048af7d57b6938 Mon Sep 17 00:00:00 2001 From: ebbit1q Date: Sun, 11 Dec 2022 17:33:07 -0500 Subject: [PATCH] update github action (#293) use the node-16 version of checkout replace use of set-output with adding to GITHUB_OUTPUT fix xml comparison using the info tags fix deploy being triggered while only date has changed --- .github/workflows/deploy.yml | 8 +++--- magic_spoiler/__main__.py | 48 +++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 05dee10b..b42e198b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -30,12 +30,12 @@ jobs: steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Checkout output branch # Run only when triggered from master if: env.DEPLOY == 'true' - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: ref: files fetch-depth: 0 @@ -47,7 +47,7 @@ jobs: CFLAGS: '-O0' run: | python3 -m pip install --upgrade pip setuptools - python3 -m pip install --requirement requirements.txt + python3 -m pip install requests requests_cache lxml - name: Run script id: run @@ -57,7 +57,7 @@ jobs: - name: Upload artifacts # Run only when triggered from a PR if: github.event_name == 'pull_request' - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: spoiler-output path: ${{github.workspace}}/${{env.OUTPUT_PATH}} diff --git a/magic_spoiler/__main__.py b/magic_spoiler/__main__.py index 820aad28..b0051e98 100644 --- a/magic_spoiler/__main__.py +++ b/magic_spoiler/__main__.py @@ -5,6 +5,7 @@ import contextvars import datetime import hashlib import json +import os import pathlib import shutil import time @@ -472,29 +473,26 @@ def compare_json_content(f1: str, f2: str) -> bool: return False -def compare_xml_content(f1: str, f2: str) -> bool: +def compare_xml_content(a: str, b: str) -> bool: """ Compare the contents of two XML files and report - if the contents are the same, minus comments - :param f1: File 1 - :param f2: File 2 - :return: Is file content, minus comments, the same? + if the contents are the same, minus the info part and comments + :param a: File a + :param b: File b + :return: Is file content, minus info and comments, the same? """ - file1 = pathlib.Path(f1) - file2 = pathlib.Path(f2) + files = [pathlib.Path(file_n) for file_n in (a, b)] - if file1.is_file() and file2.is_file(): - parser = etree.XMLParser(remove_blank_text=True) - root = etree.parse(str(file1), parser).getroot() - etree.strip_tags(root, etree.Comment) - f1_hash = hashlib.sha512(etree.tostring(root)).hexdigest() + if all([filepath.is_file() for filepath in files]): + hashes = [] + for filepath in files: + parser = etree.XMLParser(remove_blank_text=True) + root = etree.parse(str(filepath), parser).getroot() + etree.strip_elements(root, "info", etree.Comment) + digest = hashlib.sha512(etree.tostring(root)).hexdigest() + hashes.append(digest) - parser = etree.XMLParser(remove_blank_text=True) - root = etree.parse(str(file2), parser).getroot() - etree.strip_tags(root, etree.Comment) - f2_hash = hashlib.sha512(etree.tostring(root)).hexdigest() - - return f1_hash == f2_hash + return hashes[0] == hashes[1] return False @@ -655,11 +653,17 @@ def main() -> None: changed |= delete_old_files() # Enable deployment on changes (used in CI) - if changed: - print("::set-output name=deploy::true") + try: + github_output = os.environ["GITHUB_OUTPUT"] + except KeyError: + print(f"not in ci but deploy={str(changed).lower()}") else: - print("::set-output name=deploy::false") - print("::notice title=No updates available::No new spoiler cards found for deployment") + with open(github_output, "a") as fp: + print(f"deploy={str(changed).lower()}", file=fp) + + if not changed: + print("::notice title=No updates available::" + "No new spoiler cards found for deployment") if __name__ == "__main__":