Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
1.python脚本重写,逻辑更加清晰。
2.流程文档替换actions即将弃用的set-output命令。
  • Loading branch information
hugcabbage committed Oct 14, 2022
1 parent d363b7c commit bbea118
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 54 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/固件编译CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ on:
default: 'xiaomi-4a-gigabit'
type: choice
options:
- mi-router-4a-gigabit
- mi-router-3g-v2
- mi-router-ac2100
- redmi-router-ac2100
- redmi-router-ax6s
- mi-router-cr6606
- mi-router-cr6608
- mi-router-cr6609
- mi-router-3g
- mi-router-4
- mi-router-3-pro
- phicomm_k2p
- 'xiaomi-4a-gigabit'
- 'xiaomi-3g-v2'
- 'xiaomi-cr6608'
- 'xiaomi-cr6606'
- 'xiaomi-cr6609'
- 'xiaomi-3g'
- 'xiaomi-4'
- 'xiaomi-3-pro'
- 'redmi-ac2100'
- 'xiaomi-ac2100'
- 'phicomm-k2p'
- 'redmi-ax6s'
version_description:
description: '输入版本描述'
required: true
Expand Down Expand Up @@ -88,8 +88,8 @@ jobs:
echo "你选择了:${{ github.event.inputs.model }}"
RELEASE_TITLE=$(yq ".model_${NUMBER}.title" $RELEASE_CO)
RELEASE_BODY=$(yq ".model_${NUMBER}.body[]" $RELEASE_CO); RELEASE_BODY="${RELEASE_BODY//$'\n'/'%0A'}"; RELEASE_BODY="${RELEASE_BODY//$'\r'/'%0D'}"
echo "::set-output name=RELEASE_TITLE::$RELEASE_TITLE"
echo "::set-output name=RELEASE_BODY::$RELEASE_BODY"
echo "RELEASE_TITLE=${RELEASE_TITLE}" >> $GITHUB_OUTPUT
echo "RELEASE_BODY=${RELEASE_BODY}" >> $GITHUB_OUTPUT
- name: 下载源码与插件
run: |
chmod +x $CLONE_SH
Expand Down
91 changes: 51 additions & 40 deletions preset-models/target_select.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,62 @@
#!/usr/bin/python3


import os
import sys
import shutil
import fileinput

os.chdir("preset-models")

main_targets = ["mi-router-4a-gigabit", "mi-router-cr6608", "redmi-router-ac2100", "phicomm_k2p", "redmi-router-ax6s"]
main_numbers = ["1", "2", "3", "4", "5"]
sub_targets = ["mi-router-cr6606", "mi-router-cr6609", "mi-router-3g", "mi-router-4", "mi-router-3-pro", "mi-router-ac2100", "mi-router-3g-v2"]
sub_numbers = ["2-1", "2-2", "2-3", "2-4", "2-5", "3-1", "1-1"]

def get_number():
for target in main_targets:
if target == sys.argv[1]:
i = main_targets.index(target)
return main_numbers[i]
break
headers = {
'xiaomi-4a-gigabit': ('1', 'ramips', 'mt7621', 'mi-router-4a-gigabit'),
'xiaomi-3g-v2': ('1-1', 'ramips', 'mt7621', 'mi-router-3g-v2'),
'xiaomi-cr6608': ('2', 'ramips', 'mt7621', 'mi-router-cr6608'),
'xiaomi-cr6606': ('2-1', 'ramips', 'mt7621', 'mi-router-cr6606'),
'xiaomi-cr6609': ('2-2', 'ramips', 'mt7621', 'mi-router-cr6609'),
'xiaomi-3g': ('2-3', 'ramips', 'mt7621', 'mi-router-3g'),
'xiaomi-4': ('2-4', 'ramips', 'mt7621', 'mi-router-4'),
'xiaomi-3-pro': ('2-5', 'ramips', 'mt7621', 'mi-router-3-pro'),
'redmi-ac2100': ('3', 'ramips', 'mt7621', 'redmi-router-ac2100'),
'xiaomi-ac2100': ('3-1', 'ramips', 'mt7621', 'mi-router-ac2100'),
'phicomm-k2p': ('4', 'ramips', 'mt7621', 'phicomm_k2p'),
'redmi-ax6s': ('5', 'ramips', 'mt7621', 'redmi-router-ax6s')
}


# model为机型名称, num为原始配置文件前缀(即编号),temp为即将用于编译流程中的临时文件前缀
def produce_temp_files(model: str, num: str, temp: str):
header = [
f'CONFIG_TARGET_{(t1 := headers[model][1])}=y\n',
f'CONFIG_TARGET_{t1}_{(t2 := headers[model][2])}=y\n',
f'CONFIG_TARGET_{t1}_{t2}_DEVICE_{headers[model][3]}=y\n'
]
# 生成临时clone.sh, modify.sh
shutil.copyfile(num + 'clone.sh', temp + 'clone.sh')
shutil.copyfile(num + 'modify.sh', temp + 'modify.sh')
# 生成临时.config
tindex = ()
with open(num + '.config') as f:
text = f.readlines()
for (index, value) in enumerate(text):
if 'CONFIG_TARGET' in value:
tindex += (index,)
if len(tindex) == 0:
text = header + text
else:
for target in sub_targets:
if target == sys.argv[1]:
j = sub_targets.index(target)
return sub_numbers[j]
break

def copy_files(old_pre, new_pre, old_str="", new_str=""):
co_files = [".config", "clone.sh", "modify.sh"]
for co_file in co_files:
shutil.copyfile(old_pre + co_file, new_pre + co_file)
if old_str != "" and new_str != "":
for line in fileinput.input(new_pre + co_files[0], inplace=1):
line = line.replace(old_str, new_str)
print(line, end = "")
for i in range(3):
text[tindex[i]] = header[i]
with open(temp + '.config', 'w') as f:
f.writelines(text)
return

# 获取序号
num = get_number()

print(num)

#复制子机型配置文件
if "-" in num:
num_part1 = num.split("-")[0]
m = main_numbers.index(num_part1)
n = sub_numbers.index(num)
copy_files(num_part1, "temp.", main_targets[m], sub_targets[n])
else:
copy_files(num, "temp.")
os.rename("temp..config", "temp.config")
if __name__ == '__main__':
os.chdir('preset-models')
modelname = sys.argv[1]
if modelname not in headers:
print('机型信息错误,请检查')
else:
modelnum = headers[modelname][0].split('-')[0]
produce_temp_files(modelname, modelnum, 'temp.')
os.rename('temp..config', 'temp.config')
# 输出对应机型的编号,以设置编译流程中的变量读取预设release内容
print(headers[modelname][0])

0 comments on commit bbea118

Please sign in to comment.