Skip to content

Commit 6a92707

Browse files
authored
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
1 parent ef39de8 commit 6a92707

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

.github/workflows/deploy.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ jobs:
3030

3131
steps:
3232
- name: Checkout repo
33-
uses: actions/checkout@v2
33+
uses: actions/checkout@v3
3434

3535
- name: Checkout output branch
3636
# Run only when triggered from master
3737
if: env.DEPLOY == 'true'
38-
uses: actions/checkout@v2
38+
uses: actions/checkout@v3
3939
with:
4040
ref: files
4141
fetch-depth: 0
@@ -47,7 +47,7 @@ jobs:
4747
CFLAGS: '-O0'
4848
run: |
4949
python3 -m pip install --upgrade pip setuptools
50-
python3 -m pip install --requirement requirements.txt
50+
python3 -m pip install requests requests_cache lxml
5151
5252
- name: Run script
5353
id: run
@@ -57,7 +57,7 @@ jobs:
5757
- name: Upload artifacts
5858
# Run only when triggered from a PR
5959
if: github.event_name == 'pull_request'
60-
uses: actions/upload-artifact@v2
60+
uses: actions/upload-artifact@v3
6161
with:
6262
name: spoiler-output
6363
path: ${{github.workspace}}/${{env.OUTPUT_PATH}}

magic_spoiler/__main__.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import datetime
66
import hashlib
77
import json
8+
import os
89
import pathlib
910
import shutil
1011
import time
@@ -472,29 +473,26 @@ def compare_json_content(f1: str, f2: str) -> bool:
472473
return False
473474

474475

475-
def compare_xml_content(f1: str, f2: str) -> bool:
476+
def compare_xml_content(a: str, b: str) -> bool:
476477
"""
477478
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?
482483
"""
483-
file1 = pathlib.Path(f1)
484-
file2 = pathlib.Path(f2)
484+
files = [pathlib.Path(file_n) for file_n in (a, b)]
485485

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)
491494

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]
498496

499497
return False
500498

@@ -655,11 +653,17 @@ def main() -> None:
655653
changed |= delete_old_files()
656654

657655
# 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()}")
660660
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")
663667

664668

665669
if __name__ == "__main__":

0 commit comments

Comments
 (0)