Skip to content

Commit

Permalink
multi: update
Browse files Browse the repository at this point in the history
Multiple preset deployments add the feature to switch branches
  • Loading branch information
hugcabbage committed Dec 16, 2023
1 parent 8fbe569 commit 44c4784
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 52 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/build-immortalwrt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#
# <https://github.com/hugcabbage/shared-lede>
#
# The firmware code comes from immortalwrt openwrt-21.02 branch
# The firmware code comes from immortalwrt
#
name: build immortalwrt 21.02
name: build immortalwrt

on:
workflow_dispatch:
Expand Down Expand Up @@ -37,6 +37,18 @@ on:
- 'glinet-microuter-n300'
- 'miwifi-mini'
- 'miwifi-r3'
branch:
description: '选择版本'
required: true
type: choice
options:
- 'openwrt-23.05'
- 'openwrt-21.02'
- 'master'
latest_tag:
description: '切换到最近稳定版本(master分不勾选)'
required: false
type: boolean
lan_ipad:
description: '设置LAN口IP地址(会覆盖modify脚本中的设置)'
required: false
Expand Down Expand Up @@ -95,9 +107,10 @@ jobs:
id: prepare-deployment
env:
MODEL_NAME: ${{ inputs.model }}
BRANCH_NAME: ${{ inputs.branch }}
LATEST_TAG: ${{ inputs.latest_tag }}
LOGIN_IP: ${{ inputs.lan_ipad }}
LOGIN_PWD: ${{ inputs.login_pwd }}
SWITCH_TAG: ${{ inputs.switch_tag }}
TEMP_PREFIX: ${{ env.EXTRA_STR }}
DEPLOY_DIR: ${{ env.EXTRA_STR }}/preset-immortalwrt
TRANSIT_PY: ${{ env.EXTRA_STR }}/extra-files/transit.py
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/build-lede.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ on:
required: true
type: choice
options:
- 'xiaomi-4a-gigabit'
- 'xiaomi-3g-v2'
- 'xiaomi-cr6608'
- 'xiaomi-cr6606'
- 'xiaomi-cr6609'
- 'redmi-ac2100'
- 'xiaomi-ac2100'
- 'xiaomi-4a-gigabit'
- 'xiaomi-4a-gigabit-v2'
- 'xiaomi-3g-v2'
- 'xiaomi-3g'
- 'xiaomi-4'
- 'xiaomi-3-pro'
- 'redmi-ac2100'
- 'xiaomi-ac2100'
- 'phicomm-k2p'
- 'redmi-ax6s'
- 'xiaomi-4a-100m'
Expand Down Expand Up @@ -74,7 +75,7 @@ permissions:

jobs:
to-build:
name: build lede
name: build
runs-on: ubuntu-latest
env:
EXTRA_STR: _some
Expand Down Expand Up @@ -104,7 +105,6 @@ jobs:
MODEL_NAME: ${{ inputs.model }}
LOGIN_IP: ${{ inputs.lan_ipad }}
LOGIN_PWD: ${{ inputs.login_pwd }}
SWITCH_TAG: ${{ inputs.switch_tag }}
TEMP_PREFIX: ${{ env.EXTRA_STR }}
DEPLOY_DIR: ${{ env.EXTRA_STR }}/preset-lede
TRANSIT_PY: ${{ env.EXTRA_STR }}/extra-files/transit.py
Expand Down
23 changes: 16 additions & 7 deletions .github/workflows/build-lienol-openwrt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# <https://github.com/hugcabbage/shared-lede>
#
# The firmware code comes from lienol openwrt master branch
# The firmware code comes from lienol openwrt
#
name: build lienol openwrt

Expand All @@ -17,17 +17,17 @@ on:
required: true
type: choice
options:
- 'xiaomi-4a-gigabit'
- 'xiaomi-4a-gigabit-v2'
- 'xiaomi-3g-v2'
- 'xiaomi-cr6608'
- 'xiaomi-cr6606'
- 'xiaomi-cr6609'
- 'redmi-ac2100'
- 'xiaomi-ac2100'
- 'xiaomi-4a-gigabit'
- 'xiaomi-4a-gigabit-v2'
- 'xiaomi-3g-v2'
- 'xiaomi-3g'
- 'xiaomi-4'
- 'xiaomi-3-pro'
- 'redmi-ac2100'
- 'xiaomi-ac2100'
- 'phicomm-k2p'
- 'redmi-ax6s'
- 'xiaomi-4a-100m'
Expand All @@ -37,6 +37,15 @@ on:
- 'glinet-microuter-n300'
- 'miwifi-mini'
- 'miwifi-r3'
branch:
description: '选择版本'
required: true
type: choice
options:
- 'openwrt-23.05'
- 'openwrt-22.03'
- 'openwrt-21.02'
- 'main'
lan_ipad:
description: '设置LAN口IP地址(会覆盖modify脚本中的设置)'
required: false
Expand Down Expand Up @@ -95,9 +104,9 @@ jobs:
id: prepare-deployment
env:
MODEL_NAME: ${{ inputs.model }}
BRANCH_NAME: ${{ inputs.branch }}
LOGIN_IP: ${{ inputs.lan_ipad }}
LOGIN_PWD: ${{ inputs.login_pwd }}
SWITCH_TAG: ${{ inputs.switch_tag }}
TEMP_PREFIX: ${{ env.EXTRA_STR }}
DEPLOY_DIR: ${{ env.EXTRA_STR }}/preset-lienol-openwrt
TRANSIT_PY: ${{ env.EXTRA_STR }}/extra-files/transit.py
Expand Down
24 changes: 17 additions & 7 deletions .github/workflows/build-openwrt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#
# <https://github.com/hugcabbage/shared-lede>
#
# The firmware code comes from openwrt openwrt-23.05 branch
# The firmware code comes from openwrt
#
name: build openwrt 23.05
name: build openwrt

on:
workflow_dispatch:
Expand Down Expand Up @@ -37,6 +37,19 @@ on:
- 'glinet-microuter-n300'
- 'miwifi-mini'
- 'miwifi-r3'
branch:
description: '选择版本'
required: true
type: choice
options:
- 'openwrt-23.05'
- 'openwrt-22.03'
- 'openwrt-21.02'
- 'master'
latest_tag:
description: '切换到最近稳定版本(master分不勾选)'
required: false
type: boolean
lan_ipad:
description: '设置LAN口IP地址(会覆盖modify脚本中的设置)'
required: false
Expand All @@ -52,10 +65,6 @@ on:
required: false
default: '升级内容:内核升级,更新应用版本'
type: string
switch_tag:
description: '切换到最近稳定版本'
required: false
type: boolean
release:
description: '上传到release'
required: false
Expand Down Expand Up @@ -99,9 +108,10 @@ jobs:
id: prepare-deployment
env:
MODEL_NAME: ${{ inputs.model }}
BRANCH_NAME: ${{ inputs.branch }}
LATEST_TAG: ${{ inputs.latest_tag }}
LOGIN_IP: ${{ inputs.lan_ipad }}
LOGIN_PWD: ${{ inputs.login_pwd }}
SWITCH_TAG: ${{ inputs.switch_tag }}
TEMP_PREFIX: ${{ env.EXTRA_STR }}
DEPLOY_DIR: ${{ env.EXTRA_STR }}/preset-openwrt
TRANSIT_PY: ${{ env.EXTRA_STR }}/extra-files/transit.py
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/build-x-wrt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# <https://github.com/hugcabbage/shared-lede>
#
# The firmware code comes from x-wrt master branch
# The firmware code comes from x-wrt
#
name: build x-wrt

Expand Down Expand Up @@ -37,6 +37,10 @@ on:
- 'glinet-microuter-n300'
- 'miwifi-mini'
- 'miwifi-r3'
latest_tag:
description: '切换到最近稳定版本'
required: false
type: boolean
lan_ipad:
description: '设置LAN口IP地址(会覆盖modify脚本中的设置)'
required: false
Expand All @@ -52,10 +56,6 @@ on:
required: false
default: '升级内容:内核升级,更新应用版本'
type: string
switch_tag:
description: '切换到最近稳定版本'
required: false
type: boolean
release:
description: '上传到release'
required: false
Expand Down Expand Up @@ -99,9 +99,9 @@ jobs:
id: prepare-deployment
env:
MODEL_NAME: ${{ inputs.model }}
LATEST_TAG: ${{ inputs.latest_tag }}
LOGIN_IP: ${{ inputs.lan_ipad }}
LOGIN_PWD: ${{ inputs.login_pwd }}
SWITCH_TAG: ${{ inputs.switch_tag }}
TEMP_PREFIX: ${{ env.EXTRA_STR }}
DEPLOY_DIR: ${{ env.EXTRA_STR }}/preset-x-wrt
TRANSIT_PY: ${{ env.EXTRA_STR }}/extra-files/transit.py
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ Actions流程顺利完成后,去release(或者artifact)下载你的固件,re
|配置目录|流程名|源码|
|:----:|:----:|:----:|
|preset-lede|build lede|[coolsnowwolf/lede](https://github.com/coolsnowwolf/lede)|
|preset-lienol-openwrt|build lienol openwrt|[Lienol/openwrt master](https://github.com/Lienol/openwrt/tree/master)|
|preset-openwrt|build openwrt 23.05|[openwrt/openwrt openwrt-23.05](https://github.com/openwrt/openwrt/tree/openwrt-23.05)|
|preset-immortalwrt|build immortalwrt 21.02|[immortalwrt/immortalwrt openwrt-21.02](https://github.com/immortalwrt/immortalwrt/tree/openwrt-21.02)|
|preset-x-wrt|build x-wrt|[x-wrt/x-wrt master](https://github.com/x-wrt/x-wrt/tree/master)|
|preset-lienol-openwrt|build lienol openwrt|[Lienol/openwrt](https://github.com/Lienol/openwrt)|
|preset-openwrt|build openwrt|[openwrt/openwrt](https://github.com/openwrt/openwrt)|
|preset-immortalwrt|build immortalwrt|[immortalwrt/immortalwrt](https://github.com/immortalwrt/immortalwrt)|
|preset-x-wrt|build x-wrt|[x-wrt/x-wrt](https://github.com/x-wrt/x-wrt)|

## 各机型对应文件

Expand Down
25 changes: 19 additions & 6 deletions extra-files/transit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import glob
import json
import shutil
import requests


from tools.code_summary import CodeSummary
Expand Down Expand Up @@ -37,7 +38,7 @@ def produce_temp_workfiles(headers: dict, model: str, temp: str, *, ip=None, pwd
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'
f'CONFIG_TARGET_{t1}_{t2}_DEVICE_{(t3 := headers[model][3])}=y\n'
]
with open(num + '.config', encoding='utf-8') as f:
text = f.readlines()
Expand All @@ -60,11 +61,23 @@ def produce_temp_workfiles(headers: dict, model: str, temp: str, *, ip=None, pwd
num = '1'
with open(num + '.clone.sh', encoding='utf-8') as f:
text = f.readlines()
if os.getenv('SWITCH_TAG') == 'true':
for i, line in enumerate(text.copy()):
if line.startswith('SWITCH_TAG_FLAG='):
text[i] = 'SWITCH_TAG_FLAG=true\n'
break
for i, line in enumerate(text.copy()):
if line.startswith('CODE_URL=') and (bn := os.getenv('BRANCH_NAME')):
code_ = line.split('=')[-1].strip().removeprefix('https://github.com/').removesuffix('.git')
subtarget_mk_url = f'https://raw.githubusercontent.com/{code_}/{bn}/target/linux/{t1}/image/{t2}.mk'
device_define_str = f'define Device/{t3}'
if device_define_str not in requests.get(subtarget_mk_url, timeout=5).text:
print(f'{bn} branch does not support this model, and the branch retains the default value in clone.sh')
can_switch_branch = False
else:
can_switch_branch = True
elif line.startswith('CODE_BRANCH=') and can_switch_branch:
text[i] = 'CODE_BRANCH=' + bn + '\n'
elif line.startswith('SWITCH_LATEST_TAG=') and os.getenv('LATEST_TAG') == 'true':
text[i] = 'SWITCH_LATEST_TAG=true\n'
break
elif i >= 10:
break
with open(tc2 := temp + '.clone.sh', 'w', encoding='utf-8') as f:
f.writelines(text)
files['clone_sh'] = tc2
Expand Down
17 changes: 16 additions & 1 deletion preset-immortalwrt/1.clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@

# download base code
CODE_DIR=_firmware_code
git clone --single-branch -b openwrt-21.02 https://github.com/immortalwrt/immortalwrt.git $CODE_DIR
CODE_URL=https://github.com/immortalwrt/immortalwrt.git
CODE_BRANCH=openwrt-23.05
SWITCH_LATEST_TAG=false
git clone --single-branch -b $CODE_BRANCH $CODE_URL $CODE_DIR
if $SWITCH_LATEST_TAG; then
cd $CODE_DIR
LATEST_TAG_HASH=$(git rev-list --tags --max-count=1)
if [ -z "$LATEST_TAG_HASH" ]; then
echo "No tag to switch, keep the latest commit"
else
git checkout $LATEST_TAG_HASH
LATEST_TAG=$(git describe --tags $LATEST_TAG_HASH)
echo "The code has been switched to the latest stable version$LATEST_TAG"
fi
cd ..
fi
mv ./$CODE_DIR/* ./

# download app codes
Expand Down
4 changes: 3 additions & 1 deletion preset-lienol-openwrt/1.clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

# download base code
CODE_DIR=_firmware_code
git clone --depth 1 -b main https://github.com/Lienol/openwrt $CODE_DIR
CODE_URL=https://github.com/Lienol/openwrt
CODE_BRANCH=23.05
git clone --depth 1 -b $CODE_BRANCH $CODE_URL $CODE_DIR
mv ./$CODE_DIR/* ./

# download app codes
Expand Down
19 changes: 13 additions & 6 deletions preset-openwrt/1.clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

# download base code
CODE_DIR=_firmware_code
SWITCH_TAG_FLAG=false
git clone --single-branch -b openwrt-23.05 https://git.openwrt.org/openwrt/openwrt.git $CODE_DIR
if $SWITCH_TAG_FLAG; then
CODE_URL=https://git.openwrt.org/openwrt/openwrt.git
CODE_BRANCH=openwrt-23.05
SWITCH_LATEST_TAG=false
git clone --single-branch -b $CODE_BRANCH $CODE_URL $CODE_DIR
if $SWITCH_LATEST_TAG; then
cd $CODE_DIR
LATEST_TAG=$(git tag | awk 'END {print}')
git checkout $LATEST_TAG
echo "已切换到最近稳定版本$LATEST_TAG"
LATEST_TAG_HASH=$(git rev-list --tags --max-count=1)
if [ -z "$LATEST_TAG_HASH" ]; then
echo "No tag to switch, keep the latest commit"
else
git checkout $LATEST_TAG_HASH
LATEST_TAG=$(git describe --tags $LATEST_TAG_HASH)
echo "The code has been switched to the latest stable version$LATEST_TAG"
fi
cd ..
fi
mv ./$CODE_DIR/* ./
Expand Down
15 changes: 10 additions & 5 deletions preset-x-wrt/1.clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

# download base code
CODE_DIR=_firmware_code
SWITCH_TAG_FLAG=false
SWITCH_LATEST_TAG=false
git clone https://github.com/x-wrt/x-wrt.git $CODE_DIR
if $SWITCH_TAG_FLAG; then
if $SWITCH_LATEST_TAG; then
cd $CODE_DIR
LATEST_TAG=$(git tag --sort=creatordate | awk 'END {print}')
git checkout $LATEST_TAG
echo "已切换到最近稳定版本$LATEST_TAG"
LATEST_TAG_HASH=$(git rev-list --tags --max-count=1)
if [ -z "$LATEST_TAG_HASH" ]; then
echo "No tag to switch, keep the latest commit"
else
git checkout $LATEST_TAG_HASH
LATEST_TAG=$(git describe --tags $LATEST_TAG_HASH)
echo "The code has been switched to the latest stable version$LATEST_TAG"
fi
cd ..
fi
mv ./$CODE_DIR/* ./
Expand Down

0 comments on commit 44c4784

Please sign in to comment.