mirror of
https://github.com/Cockatrice/Magic-Spoiler.git
synced 2026-10-01 13:57:30 -05:00
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
This commit is contained in:
8
.github/workflows/deploy.yml
vendored
8
.github/workflows/deploy.yml
vendored
@@ -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}}
|
||||
|
||||
@@ -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__":
|
||||
|
||||
Reference in New Issue
Block a user