import os, re, json, shutil, string, requests, subprocess
def set_output(name, value):
subprocess.call(["echo '{}={}' >> $GITHUB_ENV".format(name, value)], shell=True)
if __name__ == '__main__':
issues = 'false'
iscustom = 'true'
errinfo = ''
warinfo = ''
repository = ''
model = ''
version = ''
platform = ''
lkm = ''
config = ''
maxdisks = ''
maxlanport = ''
internalportcfg = ''
esataportcfg = ''
usbportcfg = ''
sn = ''
mac = ''
netif_num = ''
vid = ''
pid = ''
diskidxmap = ''
sataportmap = ''
sasidxmap = ''
dtb = ''
addons = ''
modules = ''
ext3rds = ''
dev = '0'
try:
body = {}
bodyOriginal = {}
if '${{ github.event_name }}' == 'issues':
if '${{ env.issuetitle }}'.lower().startswith('custom'):
issues = 'true'
bodyOriginal = json.loads('${{ env.issuebody }}')
else:
iscustom = 'false'
else:
bodyOriginal = json.loads('${{ inputs.body }}')
for k, v in bodyOriginal.items():
body[k.lower()] = v
if len(body) == 0:
iscustom = 'false'
errinfo = 'body 错误, body is null'
else:
# l = lambda x: x.strip() if isinstance(x, str) else str(x)
if 'repository' in body: repository = body['repository'].strip()
if 'model' in body: model = body['model'].strip()
if 'version' in body: version = body['version'].strip()
# if 'platform' in body: platform = body['platform'].strip()
if 'lkm' in body: lkm = body['lkm'].strip()
if 'config' in body: config = body['config'] #l(body['config']).strip()
if 'maxdisks' in body: maxdisks = body['maxdisks'].strip()
if 'maxlanport' in body: maxlanport = body['maxlanport'].strip()
if 'internalportcfg' in body: internalportcfg = body['internalportcfg'].strip()
if 'esataportcfg' in body: esataportcfg = body['esataportcfg'].strip()
if 'usbportcfg' in body: usbportcfg = body['usbportcfg'].strip()
#if 'sn' in body: sn = body['sn'].strip()
#if 'mac' in body: mac = body['mac'].strip()
if 'netif_num' in body: netif_num = body['netif_num'].strip()
if 'vid' in body: vid = body['vid'].strip()
if 'pid' in body: pid = body['pid'].strip()
if 'diskidxmap' in body: diskidxmap = body['diskidxmap'].strip()
if 'sataportmap' in body: sataportmap = body['sataportmap'].strip()
if 'sasidxmap' in body: sasidxmap = body['sasidxmap'].strip()
if 'dtb' in body: dtb = body['dtb'].strip()
if 'addons' in body: addons = body['addons'].strip()
if 'modules' in body: modules = body['modules'].strip()
if 'ext3rds' in body: ext3rds = body['ext3rds'].strip()
except Exception as e:
iscustom = 'false'
errinfo = 'body 错误, 不符合JSON规范 {}.'.format(e)
loads = {}
with open('docs/loads.json', mode="r", encoding='utf-8') as f:
loads = json.loads(f.read())
repositorys = loads.keys()
if iscustom == 'true' and not repository in repositorys:
iscustom = 'false'
errinfo = 'repository 参数错误, 当前仅支持 {}.'.format(', '.join(repositorys))
if iscustom == 'true':
models = loads[repository].keys()
if not model in models:
iscustom = 'false'
errinfo = 'model 参数错误, 当前仅支持 {}.'.format(', '.join(models))
if iscustom == 'true':
versions = loads[repository][model]
if not version in versions:
iscustom = 'false'
errinfo = 'version 参数错误, 当前仅支持 {}.'.format(', '.join(versions))
if iscustom == 'true':
models = {}
with open('docs/models.json', mode="r", encoding='utf-8') as f:
models = json.loads(f.read())
toolchain = {}
with open('docs/toolchain.json', mode="r", encoding='utf-8') as f:
toolchain = json.loads(f.read())
PackageArch = [ item["PackageArch"] for item in models if item["Model"] == model ][0]
PackageKVer = [ toolchain[item][PackageArch] for item in toolchain if item[0:3] == version[0:3] ][0]
platform = PackageArch + "-" + PackageKVer
if iscustom == 'true':
lkms = []
with open('docs/parameter.json', mode="r", encoding='utf-8') as f:
parameter = json.loads(f.read())
lkms = parameter['lkm']['options']
if lkm == '':
lkm = lkms[0]
if not lkm in lkms:
iscustom = 'false'
errinfo = 'lkm 参数错误, 当前仅支持 {}.'.format(', '.join(lkms))
if config != '':
try:
if isinstance(config, str):
config = json.loads(config)
if isinstance(config, dict):
config = json.dumps(config)
json.loads(config)
else:
if iscustom == 'true':
iscustom = 'false'
errinfo = 'config 参数错误, 不符合JSON规范.'
except Exception as e:
if iscustom == 'true':
iscustom = 'false'
errinfo = 'config 参数错误, 不符合JSON规范 {}.'.format(e)
if iscustom == 'true' and maxdisks != '' and (not maxdisks.isdigit() or int(maxdisks) < 1 or int(maxdisks) > 48):
iscustom = 'false'
errinfo = 'maxdisks 参数错误, 请填写 1 - 48 之间的数字.'
if iscustom == 'true' and maxlanport != '' and (not maxlanport.isdigit() or int(maxlanport) < 0 or int(maxlanport) > 47):
iscustom = 'false'
errinfo = 'maxlanport 参数错误, 请填写 0 - 47 之间的数字.'
if iscustom == 'true' and internalportcfg != '':
if len(internalportcfg) > 2 and internalportcfg[:2].lower().startswith('0x') and all(c in string.hexdigits for c in internalportcfg[2:]):
pass
elif all(c in string.hexdigits for c in internalportcfg):
internalportcfg = '0x' + internalportcfg
else:
iscustom = 'false'
errinfo = 'internalportcfg 参数错误, 请填写十六进制数.'
if iscustom == 'true' and esataportcfg != '':
if len(esataportcfg) > 2 and esataportcfg[:2].lower().startswith('0x') and all(c in string.hexdigits for c in esataportcfg[2:]):
pass
elif all(c in string.hexdigits for c in esataportcfg):
esataportcfg = '0x' + esataportcfg
else:
iscustom = 'false'
errinfo = 'esataportcfg 参数错误, 请填写十六进制数.'
if iscustom == 'true' and usbportcfg != '':
if len(usbportcfg) > 2 and usbportcfg[:2].lower().startswith('0x') and all(c in string.hexdigits for c in usbportcfg[2:]):
pass
elif all(c in string.hexdigits for c in usbportcfg):
usbportcfg = '0x' + usbportcfg
else:
iscustom = 'false'
errinfo = 'usbportcfg 参数错误, 请填写十六进制数.'
if iscustom == 'true' and sn != '':
warinfo = 'sn'
if not sn.isalnum():
iscustom = 'false'
errinfo = 'sn 参数错误.'
warinfo = 'sn'
if iscustom == 'true' and mac != '':
warinfo = 'mac' if warinfo == '' else 'sn, mac'
macs = [x.strip() for x in re.split(',| |\|', mac) if x.strip() != '']
if len(macs) > 0 or len(macs) <= 8:
mac = ','.join(macs)
else:
iscustom = 'false'
errinfo = 'mac 参数错误.'
if iscustom == 'true' and netif_num != '' and (not netif_num.isdigit() or int(netif_num) < 1 or int(netif_num) > 8):
iscustom = 'false'
errinfo = 'netif_num 参数错误, 请填写 1 - 8 之间的数字.'
if iscustom == 'true' and mac != '' and netif_num != '' and int(netif_num) != len(mac.split(',')):
iscustom = 'false'
errinfo = 'netif_num 应该与 mac 的个数相等, 请填写匹配的数值.'
if iscustom == 'true' and vid != '':
if len(vid) == 6 and vid.lower().startswith('0x') and all(c in string.hexdigits for c in vid[2:]):
pass
elif len(vid) == 4 and all(c in string.hexdigits for c in vid):
vid = '0x' + vid
else:
iscustom = 'false'
errinfo = 'vid 参数错误, 请填写十六进制数.'
if iscustom == 'true' and pid != '':
if len(pid) == 6 and pid.lower().startswith('0x') and all(c in string.hexdigits for c in pid[2:]):
pass
elif len(pid) == 4 and all(c in string.hexdigits for c in pid):
pid = '0x' + pid
else:
iscustom = 'false'
errinfo = 'pid 参数错误, 请填写十六进制数.'
if iscustom == 'true' and ((vid != '' and pid == '') or (vid == '' and pid != '')):
iscustom = 'false'
errinfo = 'vid 和 pid 参数不可单独定制, 应成对出现, 请填写完整的两个参数.'
if iscustom == 'true' and diskidxmap != '' and not all(c in string.hexdigits for c in diskidxmap):
iscustom = 'false'
errinfo = 'diskidxmap 参数错误, 请填写十六进制数..'
if iscustom == 'true' and sataportmap != '' and not sataportmap.isdigit():
iscustom = 'false'
errinfo = 'sataportmap 参数错误, 请填写数字.'
if iscustom == 'true' and sasidxmap != '' and not sasidxmap.isdigit():
iscustom = 'false'
errinfo = 'sasidxmap 参数错误, 请填写数字.'
#if iscustom == 'true' and ((diskidxmap != '' and sataportmap == '') or (diskidxmap == '' and sataportmap != '') or len(diskidxmap) < len(sataportmap)):
# iscustom = 'false'
# errinfo = 'diskidxmap 和 sataportmap 参数不可单独定制, 且 diskidxmap的位数应该为sataportmap位数的2倍.'
if iscustom == 'true' and dtb != '': # and dtb != 'auto':
url = dtb
try:
try:
import wget, filetype
except ModuleNotFoundError:
os.system('pip3 install wget filetype')
import wget, filetype
res = wget.download(url)
if res:
down = res
kind = filetype.guess(down)
name = 'user'
if os.path.exists('extract'):
shutil.rmtree('extract')
if kind != None and kind.extension == 'zip':
import zipfile
z = zipfile.ZipFile(down, 'r')
z.extractall('extract')
if kind != None and kind.extension in ['tar', 'gz']:
import tarfile
z = tarfile.open(down)
z.extractall('extract')
if os.path.exists('extract'):
isfind = False
for root, dirs, files in os.walk('extract'):
for file in files:
if file.endswith('.dts') or file.endswith('.dtb'):
isfind = True
down = name + os.path.splitext(file)[-1]
shutil.move(os.path.join(root, file), down)
break
if isfind is True:
break
if os.path.exists(down) and (down.endswith('dts') or down.endswith('dtb')):
if down.endswith('dts'):
wget.download('https://raw.githubusercontent.com/pocopico/rp-ext/main/redpill-dtb-static/releases/dtc')
if os.path.exists('dtc'):
print('./dtc -q -I dts -O dtb {} >{}.dtb'.format(down, name))
os.system('sudo chmod a+x dtc')
# os.system('sudo ./dtc -q -I dts -O dtb {} >{}.dtb'.format(down, name))
p = subprocess.Popen('sudo ./dtc -q -I dts -O dtb {} >{}.dtb'.format(down, name), shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
errinfo = p.stderr.read().decode('utf-8')
if os.path.exists('{}.dtb'.format(name)) and os.path.getsize('{}.dtb'.format(name)) > 0:
print('dtc ok ...')
dtb = os.path.abspath('{}.dtb'.format(name))
else:
iscustom = 'false'
errinfo = 'dtb 参数错误, dts文件内容存在错误 <{}>.'.format(errinfo.
lace('\r', '').replace('\n', ' '))
else:
iscustom = 'false'
errinfo = 'dtb 参数错误, 下载 dtc(dts->dtb tools) 失败, 可能是服务器压力过大, 请稍后重试, 或者直接使用 dtb 文件跳过转换.'
else:
dtb = os.path.abspath(down)
else:
iscustom = 'false'
errinfo = 'dtb 参数错误, 该url下载的文件不是所支持的格式.'
except ValueError as e:
iscustom = 'false'
errinfo = 'dtb 参数错误, {}, 请填写 dts/dtb 文件有效的 http(s) 下载链接.'.format(e)
except Exception as e:
iscustom = 'false'
errinfo = 'dtb 参数错误, {}, 请稍后重试.'.format(e)
if iscustom == 'true' and addons != '':
req = requests.get('https://raw.githubusercontent.com/wjz304/rp-ext/main/addons.json')
req.encoding = 'utf-8'
gitAddons = json.loads(req.text)
curAddons = [ x.strip() for x in re.split(',| |\|', addons) if x.strip() != '' ]
extc = [ x for x in curAddons if x not in gitAddons.keys() or (platform not in gitAddons[x]['platforms'] and '_' not in gitAddons[x]['platforms']) ]
if len(extc) > 0:
iscustom = 'false'
errinfo = 'ext 参数错误, "{}" 无效, addons 当前仅支持 "{}".'.format(extc, ','.join([x for x in curAddons if x in gitAddons.keys() and (platform in gitAddons[x]['platforms'] or '_' in gitAddons[x]['platforms'])]))
else:
dtbs = ['DS920+', 'DS923+', 'DS1520+', 'DS1621+', 'DS1821+', 'DS2422+', 'DVA1622', 'FS2500', 'SA6400']
if model in dtbs:
if dtb == '':
if 'dtbstatic' in curAddons:
iscustom = 'false'
errinfo = 'addons 参数错误, "dtbstatic" 无效, dtbstatic 依赖自定义的 dtb 文件.'
elif 'disks' in curAddons and 'dtbpatch' in curAddons:
iscustom = 'false'
errinfo = 'addons 参数错误, "disks" 和 "dtbpatch" 只能选一个.'
elif 'disks' not in curAddons and 'dtbpatch' not in curAddons:
curAddons.append('disks')
else:
if 'disks' in curAddons or 'dtbpatch' in curAddons:
iscustom = 'false'
errinfo = 'addons 参数错误, "disks / dtbpatch" 无效, 自定义 dtb 文件时只能选 "dtbstatic".'
elif 'dtbstatic' not in curAddons:
curAddons.append('dtbstatic')
else:
if 'dtbstatic' in curAddons or 'disks' in curAddons or 'dtbpatch' in curAddons:
iscustom = 'false'
errinfo = 'addons 参数错误, "dtbstatic / disks / dtbpatch" 无效, "{}" 不需要 "dtb".'.format(model)
if iscustom == 'true' and addons != '':
addons = ','.join(curAddons)
if iscustom == 'true' and modules != '':
req = requests.get('https://raw.githubusercontent.com/wjz304/rp-ext/main/modules.json')
req.encoding = 'utf-8'
gitModules = json.loads(req.text)
curModules = [ x.strip() for x in re.split(',| |\|', modules) if x.strip() != '' ]
extc = [ x for x in curModules if x not in gitModules.keys() or (platform not in gitModules[x]['platforms'] and '_' not in gitModules[x]['platforms']) ]
if len(extc) > 0:
iscustom = 'false'
errinfo = 'ext 参数错误, "{}" 无效, modules 当前仅支持 "{}".'.format(extc, ','.join([x for x in curModules if x in gitModules.keys() and (platform in gitModules[x]['platforms'] or '_' in gitModules[x]['platforms'])]))
else:
modules = ','.join(curModules)
if iscustom == 'true' and ext3rds != '':
ext3rds = [ x.strip() for x in re.split(',| |\|', ext3rds) if x.strip() != '' ]
extc = [ x for x in ext3rds if not x.startswith('http') ]
if len(extc) > 0:
iscustom = 'false'
errinfo = 'ext3rds 参数错误, "{}" 无效, ext3rds 当前仅支持 url 地址.'.format(extc)
else:
ext3rds = ','.join(ext3rds)
if iscustom == 'true' and addons == '' and modules == '' and ext3rds == '':
addons = 'boot-wait' # 当一个 ext 都没有时 /include/file.sh 中 rpt_list_directories 直接 "exit 1"
if iscustom == 'true' and not dev in ['0', '1']:
dev = '0'
set_output('issues', issues)
set_output('iscustom', iscustom)
set_output('errinfo', errinfo)
set_output('warinfo', warinfo)
set_output('repository', repository)
set_output('model', model)
set_output('version', version)
set_output('platform', platform)
set_output('lkm', lkm)
set_output('config', config)
set_output('maxdisks', maxdisks)
set_output('maxlanport', maxlanport)
set_output('internalportcfg', internalportcfg)
set_output('esataportcfg', esataportcfg)
set_output('usbportcfg', usbportcfg)
set_output('sn', sn)
set_output('mac', mac)
set_output('netif_num', netif_num)
set_output('vid', vid)
set_output('pid', pid)
set_output('diskidxmap', diskidxmap)
set_output('sataportmap', sataportmap)
set_output('sasidxmap', sasidxmap)
set_output('dtb', dtb)
set_output('addons', addons)
set_output('modules', modules)
set_output('ext3rds', ext3rds)
set_output('dev', dev)
#
Copyright (C) 2022 Ing https://github.com/wjz304
This is free software, licensed under the MIT License.
See /LICENSE for more information.
#
name: Custom Redpill on: issues: types: [opened, reopened] workflow_dispatch: inputs: body: description: 'issuss body' required: true default: '' type: string
jobs: build: runs-on: ubuntu-latest steps:
name: Checkout uses: actions/checkout@main
name: Create Issues comment if: github.event_name == 'issues' id: comment uses: actions-cool/issues-helper@v3 with: actions: 'create-comment' token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ github.event.issue.number }} body: | 分析 title 和 body 内容 ..
name: Set up Ruby 3 uses: ruby/setup-ruby@v1 with: ruby-version: 3.1.2
name: Set up Python 3 uses: actions/setup-python@v4 with: python-version: '3.10'
name: Init Env run : | git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.name "github-actions[bot]" sudo timedatectl set-timezone "Asia/Shanghai" python -m pip install --upgrade pip setuptools python -m pip install requests
name: Get Issues Info if: github.event_name == 'issues' id: get-issues uses: actions/github-script@v6 with: script: | // '<???>': 替换一次; '/<???>/g': 替换全局; '/<???>/gi': 替换全局并忽略大小写; // \u0008 \b Backspace // \u0009 \t Tab // \u000A \n 换行符 // \u000B \v 垂直制表符 // \u000C \f 换页 // \u000D \r 回车 // \u0022 \" 双引号 (") // \u0027 \' 单引号 (') // \u005C \ 反斜杠 () // \u00A0 不间断空格 // \u2028 行分隔符 // \u2029 段落分隔符 // \uFEFF 字节顺序标记 var fs = require('fs'); // 引入fs模块 var issuenumber = ${{ toJSON(github.event.issue.number) }}; var issueauth = ${{ toJSON(github.event.issue.user.login) }}; var issuetitle = ${{ toJSON(github.event.issue.title) }}; var issuebody = ${{ toJSON(github.event.issue.body) }}; if (issuetitle != null) { issuetitle = issuetitle.replace(/\u000A|\u000D/g, ""); // 换行符,回车 }
name: Set Issues Info if: github.event_name == 'issues' && success() run: | echo issuenumber: '${{ steps.get-issues.outputs.issuenumber }}' echo issueauth: '${{ steps.get-issues.outputs.issueauth }}' echo issuetitle: '${{ steps.get-issues.outputs.issuetitle }}' echo issuebody: '${{ steps.get-issues.outputs.issuebody }}' echo "issuenumber="${{ steps.get-issues.outputs.issuenumber }}"" >> $GITHUB_ENV echo "issueauth="${{ steps.get-issues.outputs.issueauth }}"" >> $GITHUB_ENV echo "issuetitle="${{ steps.get-issues.outputs.issuetitle }}"" >> $GITHUB_ENV echo "issuebody="${{ steps.get-issues.outputs.issuebody }}"" >> $GITHUB_ENV if [ -f 'customshell.sh' ]; then echo "customshell.sh" cat customshell.sh fi
name: Get Build Info shell: python run: |
-- coding: utf-8 --
name: Echo Build Info run: | echo issues: '${{ env.issues }}' echo iscustom: '${{ env.iscustom }}' echo errinfo: '${{ env.errinfo }}' echo warinfo: '${{ env.warinfo }}' echo repository: '${{ env.repository }}' echo model: '${{ env.model }}' echo version: '${{ env.version }}' echo platform: '${{ env.platform }}' echo lkm: '${{ env.lkm }}' echo config: '${{ env.config }}' echo maxdisks: '${{ env.maxdisks }}' echo maxlanport: '${{ env.maxlanport }}' echo internalportcfg: '${{ env.internalportcfg }}' echo esataportcfg: '${{ env.esataportcfg }}' echo usbportcfg: '${{ env.usbportcfg }}' echo sn: '${{ env.sn }}' echo mac: '${{ env.mac }}' echo netif_num: '${{ env.netif_num }}' echo vid: '${{ env.vid }}' echo pid: '${{ env.pid }}' echo diskidxmap: '${{ env.diskidxmap }}' echo sataportmap: '${{ env.sataportmap }}' echo sasidxmap: '${{ env.sasidxmap }}' echo dtb: '${{ env.dtb }}' echo addons: '${{ env.addons }}' echo modules: '${{ env.modules }}' echo ext3rds: '${{ env.ext3rds }}' echo dev: '${{ env.dev }}'
name: Add Issues labels if: env.issues == 'true' && env.iscustom == 'true' uses: actions-cool/issues-helper@v3 with: actions: 'add-labels' token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ env.issuenumber }} labels: 'custom,${{ env.model }}'
name: Update Comment Begin if: env.issues == 'true' && env.iscustom == 'true' uses: actions-cool/issues-helper@v3 with: actions: 'update-comment' token: ${{ secrets.GITHUB_TOKEN }} comment-id: ${{ steps.comment.outputs.comment-id }} update-mode: replace body: | ${{ env.issueauth }} 您好.
您自定义的 Redpill 已开始构建. 请前往下面的 URL 查看详细信息.
name: Update Comment Error if: env.issues == 'true' && env.iscustom == 'false' uses: actions-cool/issues-helper@v3 with: actions: 'update-comment' token: ${{ secrets.GITHUB_TOKEN }} comment-id: ${{ steps.comment.outputs.comment-id }} update-mode: replace body: | ${{ env.issueauth }} 您好.
您自定义 Redpill 所填写的信息有误, 无法触发编译, 请参考模板和错误提示对body进行修改并请重新触发编译(Close & Reopen).
Error Info:
${{ env.errinfo }}
name: Update Comment Warinfo if: env.issues == 'true' && env.warinfo != '' uses: actions-cool/issues-helper@v3 with: actions: 'update-comment' token: ${{ secrets.GITHUB_TOKEN }} comment-id: ${{ steps.comment.outputs.comment-id }} update-mode: append body: |
name: Update Comment Invalid if: env.issues == 'false' uses: actions-cool/issues-helper@v3 with: actions: 'update-comment' token: ${{ secrets.GITHUB_TOKEN }} comment-id: ${{ steps.comment.outputs.comment-id }} update-mode: replace body: | ${{ env.issueauth }} 您好.
根据 title 和 body 内容的分析, 该 Issue 并非定制 Redpill. 将在管理员看到后会进行回复.
name: Create Config File if: env.iscustom == 'true' shell: python run: | import os, json if name == 'main': config = { "extra_cmdline": { "pid": "0x0001", "vid": "0x46f4", "sn": "", "mac1": "" }, "synoinfo": { "internalportcfg": "0xffff", "maxlanport": "7" }, "ramdisk_copy": {} } dat = [] if '${{ env.sn }}' == '' or '${{ env.mac }}' == '': model = '${{ env.model }}' dat = os.popen('bash ./serialnumbergen.sh {}'.format(model)).readlines() if '${{ env.config }}' != '': inconfig = json.loads('${{ env.config }}') config.update(inconfig) if not "extra_cmdline" in config: config["extra_cmdline"] = {} if '${{ env.vid }}' != '': config["extra_cmdline"]["vid"] = '${{ env.vid }}' if '${{ env.pid }}' != '': config["extra_cmdline"]["pid"] = '${{ env.pid }}' if '${{ env.sn }}' != '': config["extra_cmdline"]["sn"] = '${{ env.sn }}' if config["extra_cmdline"]["sn"] == '' and len(dat) == 2: config["extra_cmdline"]["sn"] = dat[1].strip() if '${{ env.mac }}' != '': macs = '${{ env.mac }}'.split(',') for index, item in enumerate(macs): config["extra_cmdline"]["mac{}".format(index+1)] = item.replace(':', '').upper() config["extra_cmdline"]["netif_num"] = len(macs) else: netnum = 2 if '${{ env.netif_num }}' != '': netnum = int('${{ env.netif_num }}') if len(dat) == 2: for index in range(netnum): config["extra_cmdline"]["mac{}".format(index+1)] = hex(int(dat[0].strip().replace(':', ''), 16) + index)[2:].rjust(12,'0').upper() config["extra_cmdline"]["netif_num"] = netnum if '${{ env.diskidxmap }}' != '': config["extra_cmdline"]["DiskIdxMap"] = '${{ env.diskidxmap }}' if '${{ env.sataportmap }}' != '': config["extra_cmdline"]["SataPortMap"] = '${{ env.sataportmap }}' if '${{ env.sasidxmap }}' != '': config["extra_cmdline"]["SasIdxMap"] = '${{ env.sasidxmap }}' if not "synoinfo" in config: config["synoinfo"] = {} if '${{ env.maxdisks }}' != '': config["synoinfo"]["maxdisks"] = '${{ env.maxdisks }}' if '${{ env.maxlanport }}' != '': config["synoinfo"]["maxlanport"] = '${{ env.maxlanport }}' if '${{ env.internalportcfg }}' != '': config["synoinfo"]["internalportcfg"] = '${{ env.internalportcfg }}' if '${{ env.esataportcfg }}' != '': config["synoinfo"]["esataportcfg"] = '${{ env.esataportcfg }}' if '${{ env.usbportcfg }}' != '': config["synoinfo"]["usbportcfg"] = '${{ env.usbportcfg }}' print(json.dumps(config, indent=4)) with open('user_config.json', 'w', encoding="utf-8") as f: f.write(json.dumps(config, indent=4))
name: Run Build if: env.iscustom == 'true' && success() run: |
累了, 毁灭吧
name: Generate release tag if: env.iscustom == 'true' && success() id: tag run: | echo "release_tag=$(date +"%Y.%m.%d-%H%M")" >> $GITHUB_ENV if [ ${{ env.issues }} == 'true' ]; then echo "### ${{ env.issueauth }}'s Redpill Custom" >> $GITHUB_STEP_SUMMARY echo "👉 issues: [#${{ env.issuenumber }}](${{ github.event.issue.html_url }})" >> $GITHUB_STEP_SUMMARY else echo "### ${{ github.triggering_actor }}'s Redpill Custom" >> $GITHUB_STEP_SUMMARY echo "👉 "model": "${{ env.model }}" " >> $GITHUB_STEP_SUMMARY echo "👉 "version": "${{ env.version }}" " >> $GITHUB_STEP_SUMMARY fi if [ '${{ env.warinfo }}' != '' ]; then echo " " >> $GITHUB_STEP_SUMMARY echo "‼️‼️‼️ " >> $GITHUB_STEP_SUMMARY echo 'Body 中含有自定义的 ${{ env.warinfo }} 敏感信息, 为防止其他人盗用, 建议附件下载完成后删除日志和附件. ' >> $GITHUB_STEP_SUMMARY echo '在👉Issues下评论 "delete builds" 即可删该Issues的所有历史编译记录. ' >> $GITHUB_STEP_SUMMARY fi if [ -f 'body#${{ env.issuenumber }}.txt' ]; then cp body#${{ env.issuenumber }}.txt redpill-load/body#${{ env.issuenumber }}.txt echo -e "\n\nBOOT:\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> redpill-load/body#${{ env.issuenumber }}.txt else echo -e "BOOT:\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> redpill-load/body#actions.txt fi configfile=./redpill-load/config/${{ env.model }}/${{ env.version }}/config.json paturl=$(cat ${configfile} | jq -r '.os .pat_url') echo -e "\nPAT:\n${paturl}" >> redpill-load/body#${{ env.issuenumber }}.txt
name: Upload to Artifacts if: env.iscustom == 'true' && success() uses: actions/upload-artifact@v3 with: name: Redpill-${{ env.model }}-${{ env.version }}-${{ env.release_tag }} path: | redpill-load/exts.txt redpill-load/body.txt redpill-load/user_config.json redpill-load/images/.img
name: Generate release tag if: env.iscustom == 'false' run: | if [ ${{ env.issues }} == 'true' ]; then echo "### ${{ env.issueauth }}'s Redpill Custom" >> $GITHUB_STEP_SUMMARY else echo "### ${{ github.triggering_actor }}'s Redpill Custom" >> $GITHUB_STEP_SUMMARY fi echo "😞 😔 😟 😕 🙁 ☹️ 😣 😖 😫 😩 🥺 😢 " >> $GITHUB_STEP_SUMMARY echo "您自定义 Redpill 所填写的信息有误, 无法触发编译, 请参考模板和错误提示对body进行修改并请重新触发编译(Close & Reopen). " >> $GITHUB_STEP_SUMMARY echo "
Error Info:
" >> $GITHUB_STEP_SUMMARY echo "${{ env.errinfo }}
" >> $GITHUB_STEP_SUMMARY if [ '${{ env.warinfo }}' != '' ]; then echo " " >> $GITHUB_STEP_SUMMARY echo "‼️‼️‼️ " >> $GITHUB_STEP_SUMMARY echo 'Body 中含有自定义的 ${{ env.warinfo }} 敏感信息, 为防止其他人盗用, 建议确认错误原因后删除日志和附件. ' >> $GITHUB_STEP_SUMMARY echo '在👉Issues下评论 "delete builds" 即可删👉Issues的所有历史编译记录. ' >> $GITHUB_STEP_SUMMARY finame: Update Comment Finish if: env.issues == 'true' && env.iscustom == 'true' && success() uses: actions-cool/issues-helper@v3 with: actions: 'update-comment' token: ${{ secrets.GITHUB_TOKEN }} comment-id: ${{ steps.comment.outputs.comment-id }} update-mode: replace body: | ${{ env.issueauth }} 您好. 您自定义的 Redpill 已构建完成. 请前往下面的 URL 下载.
name: Close Issues if: env.issues == 'true' && env.iscustom == 'true' && success() uses: actions-cool/issues-helper@v3 with: actions: 'close-issue' token: ${{ secrets.GITHUB_TOKEN }} issue-number: ${{ env.issuenumber }}
name: Update Comment Fail if: env.issues == 'true' && env.iscustom == 'true' && failure() uses: actions-cool/issues-helper@v3 with: actions: 'update-comment' token: ${{ secrets.GITHUB_TOKEN }} comment-id: ${{ steps.comment.outputs.comment-id }} update-mode: replace body: | ${{ env.issueauth }} 您好. 您自定义的 Redpill 构建失败. 请前往下面的 URL 查看详细信息对body进行修改并请重新触发编译(Close & Reopen).
name: Update Comment Warinfo if: env.issues == 'true' && env.warinfo != '' uses: actions-cool/issues-helper@v3 with: actions: 'update-comment' token: ${{ secrets.GITHUB_TOKEN }} comment-id: ${{ steps.comment.outputs.comment-id }} update-mode: append body: |