From 38caa773d7b62ed3dd0c76418bf350e52bb648de Mon Sep 17 00:00:00 2001 From: Ing Date: Wed, 17 Sep 2025 12:59:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20GitHub=20Actions=20?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=EF=BC=8C=E6=94=B9=E8=BF=9B=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E8=AE=BE=E7=BD=AE=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/issues.yml | 89 +++++++++++++++--------------------- 1 file changed, 36 insertions(+), 53 deletions(-) diff --git a/.github/workflows/issues.yml b/.github/workflows/issues.yml index 88664089..6281b4e6 100644 --- a/.github/workflows/issues.yml +++ b/.github/workflows/issues.yml @@ -27,68 +27,51 @@ jobs: shell: python run: | # -*- coding: utf-8 -*- - import json, subprocess - def set_output(name, value): - subprocess.call(f'echo "{name}<> $GITHUB_ENV', shell=True) - subprocess.call(f'echo "{value}" >> $GITHUB_ENV', shell=True) - subprocess.call(f'echo "EOF" >> $GITHUB_ENV', shell=True) + import json + import os - issuetitle = ${{ toJSON(github.event.issue.title) }} - issuebody = ${{ toJSON(github.event.issue.body) }} + def set_env(name, value): + with open(os.environ['GITHUB_ENV'], 'a', encoding='utf-8') as f: + f.write(f'{name}={value}\n') + + issuetitle = """${{ github.event.issue.title }}""" + issuebody = """${{ github.event.issue.body }}""" iscustom = 'false' warinfo = 'false' - format = '' - size = '' - template = '' - language= '' - sn = '' - macs = '' - tips = '' - model = '' - version = '' - kernel = '' - addons = '' - modules = '' + fields = { + "format": "", + "size": "", + "template": "", + "language": "", + "sn": "", + "macs": "", + "tips": "", + "model": "", + "version": "", + "kernel": "", + "addons": "", + "modules": "" + } + try: - if issuetitle.lower().startswith('custom'): - jsonbody = json.loads(issuebody) - iscustom = 'true' - format = jsonbody.get('format', '') - size = jsonbody.get('size', '') - template = jsonbody.get('template', '') - language = jsonbody.get('language', '') - sn = jsonbody.get('sn', '') - macs = jsonbody.get('macs', '') - tips = jsonbody.get('tips', '') - model = jsonbody.get('model', '') - version = jsonbody.get('version', '') - kernel = jsonbody.get('kernel', '') - addons = jsonbody.get('addons', '') - modules = jsonbody.get('modules', '') - except ValueError as e: - pass + if issuetitle.strip().lower().startswith('custom'): + jsonbody = json.loads(issuebody) + iscustom = 'true' + for k in fields: + fields[k] = jsonbody.get(k, "") + except Exception: + pass if iscustom == 'false': - if issuebody.find('DMI') < 0 and issuebody.find('CPU') < 0 and issuebody.find('NIC') < 0: - warinfo = 'true' + if not any(x in issuebody for x in ['DMI', 'CPU', 'NIC']): + warinfo = 'true' - set_output("iscustom", iscustom) - set_output("warinfo", warinfo) - - set_output("format", format) - set_output("size", size) - set_output("template", template) - set_output("language", language) - set_output("sn", sn) - set_output("macs", macs) - set_output("tips", tips) - set_output("model", model) - set_output("version", version) - set_output("kernel", kernel) - set_output("addons", addons) - set_output("modules", modules) + set_env("iscustom", iscustom) + set_env("warinfo", warinfo) + for k, v in fields.items(): + set_env(k, v) - name: Update Comment Warinfo if: env.warinfo == 'true'