Skip to content

测试编译固件

测试编译固件 #4

Workflow file for this run

#============================================================================================
# https://github.com/ophub/amlogic-s9xxx-openwrt
# Description: Build OpenWrt
#============================================================================================
name: 测试编译固件
on:
repository_dispatch:
workflow_dispatch:
inputs:
source_branch:
description: "Select the source branch"
required: false
default: "immortalwrt-master"
type: choice
options:
- openwrt-main
- lede-master
- immortalwrt-master
- Lienol-master
#是否连接到ssh,进行一些配置?
ssh:
description: '是否ssh连接到actions,进行一些配置?true or false,默认:false'
required: false
default: 'false'
env:
FEEDS_CONF: config/${{ inputs.source_branch }}/feeds.conf.default
#与make menuconfig生成的对应的.config文件相同
CONFIG_FILE: config/${{ inputs.source_branch }}/config
#自定义的插件包配置+自定义配置IP地址等配置
DIY_P1_SH: config/${{ inputs.source_branch }}/diy-part1.sh
DIY_P2_SH: config/${{ inputs.source_branch }}/diy-part2.sh
UPLOAD_BIN_DIR: true
UPLOAD_FIRMWARE: true
UPLOAD_RELEASE: true
TZ: Asia/Shanghai
jobs:
build:
runs-on: ubuntu-22.04
if: ${{ github.event.repository.owner.id }} == ${{ github.event.sender.id }}
steps:
- name: Checkout
uses: actions/checkout@main
- name: 检查服务器配置
run: |
echo "若分配的服务器性能不足,务必及时取消,重新运行!"
echo -e "------------------------------- CPU信息 -------------------------------\n"
echo "CPU物理数量:$(cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l)"
echo -e "CPU核心及版本信息: $(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c) \n"
echo -e "------------------------------- 内存信息 -------------------------------\n"
echo "已安装内存详细信息: "
sudo lshw -short -C memory | grep GiB
echo -e "\n"
echo -e "------------------------------- 磁盘信息 -------------------------------\n"
echo -e "磁盘数量: $(ls /dev/sd* | grep -v [1-9] | wc -l) \n"
echo "------------------------------- 磁盘详情 -------------------------------\n"
df -Th
- name: 初始化编译环境
id: init
env:
DEBIAN_FRONTEND: noninteractive
run: |
docker rmi `docker images -q`
[[ -n "${AGENT_TOOLSDIRECTORY}" ]] && sudo rm -rf "${AGENT_TOOLSDIRECTORY}"
sudo rm -rf /usr/share/dotnet /etc/apt/sources.list.d /usr/local/lib/android 2>/dev/null
sudo -E apt-get -y update
sudo -E apt-get -y purge azure-cli ghc* zulu* llvm* firefox google* dotnet* powershell openjdk* mongodb* moby* || true
sudo -E apt-get -y install $(curl -fsSL https://is.gd/depend_ubuntu2204_openwrt)
sudo -E systemctl daemon-reload
#sudo -E apt-get -y full-upgrade
sudo -E apt-get -y autoremove --purge
sudo -E apt-get clean
sudo mkdir -p /workdir
sudo chown ${USER}:${GROUPS} /workdir
sudo timedatectl set-timezone "${TZ}"
echo "status=success" >> ${GITHUB_OUTPUT}
- name: 克隆源码 [ ${{ inputs.source_branch }} ]
id: codes
working-directory: /workdir
if: ${{ steps.init.outputs.status }} == 'success' && !cancelled()
run: |
# Set up compilation source code
if [[ "${{ inputs.source_branch }}" == *"openwrt"* ]]; then
REPO_URL="https://github.com/openwrt/openwrt"
REPO_BRANCH="main"
TAGS_NAME="official"
elif [[ "${{ inputs.source_branch }}" == *"lede"* ]]; then
REPO_URL="https://github.com/coolsnowwolf/lede"
REPO_BRANCH="master"
TAGS_NAME="lede"
elif [[ "${{ inputs.source_branch }}" == *"immortalwrt"* ]]; then
REPO_URL="https://github.com/immortalwrt/immortalwrt"
#REPO_BRANCH="master"
REPO_BRANCH="v23.05.3"
TAGS_NAME="immortalwrt"
elif [[ "${{ inputs.source_branch }}" == *"Lienol"* ]]; then
REPO_URL="https://github.com/Lienol/openwrt"
REPO_BRANCH="22.03"
TAGS_NAME="Lienol"
else
echo "Unknown source code repository."
exit 1
fi
# Clone source code
git clone -q --single-branch --depth=1 --branch=${REPO_BRANCH} ${REPO_URL} openwrt
ln -sf /workdir/openwrt ${GITHUB_WORKSPACE}/openwrt
# Set output information
echo "build_tag=OpenWrt_${TAGS_NAME}_${{ inputs.openwrt_storage }}_$(date +"%Y.%m")" >> ${GITHUB_OUTPUT}
echo -e "REPO_URL: [ ${REPO_URL} ]\nREPO_BRANCH: [ ${REPO_BRANCH} ]\nTAGS_NAME: [ ${TAGS_NAME} ]"
df -hT ${PWD}
echo "status=success" >> ${GITHUB_OUTPUT}
#个人添加,添加参数给后面的release显示使用
echo "::set-output name=repo_url::${REPO_URL}"
echo "::set-output name=repo_branch::${REPO_BRANCH}"
# - name: 加载自定义 feeds
# run: |
# [[ -f "${FEEDS_CONF}" ]] && cp -f ${FEEDS_CONF} openwrt/feeds.conf.default
# chmod +x ${DIY_P1_SH}
# cd openwrt/
# ${GITHUB_WORKSPACE}/${DIY_P1_SH}
# - name: 更新 feeds
# run: cd openwrt/ && ./scripts/feeds update -a
# - name: 安装 feeds
# run: cd openwrt/ && ./scripts/feeds install -a
# - name: 加载自定义配置
# run: |
# [[ -d "files" ]] && mv -f files openwrt/files
# [[ -e "${CONFIG_FILE}" ]] && cp -f ${CONFIG_FILE} openwrt/.config
# chmod +x ${DIY_P2_SH}
# cd openwrt/
# ${GITHUB_WORKSPACE}/${DIY_P2_SH}
# - name: SSH 连接到 Actions
# uses: P3TERX/[email protected]
# if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh')
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: 下载软件包
# id: package
# run: |
# cd openwrt/
# make defconfig
# make download -j8
# find dl -size -1024c -exec ls -l {} \;
# find dl -size -1024c -exec rm -f {} \;
# - name: 编译openwrt固件
# id: compile
# run: |
# cd openwrt/
# echo -e "$(nproc) thread compile"
# make -j$(($(nproc) + 1)) V=s || make -j1 || make -j1 V=s
# echo "status=success" >> ${GITHUB_OUTPUT}
- name: 检查磁盘空间
if: (!cancelled())
run: df -hT
- name: 上传 bin 文件夹
uses: actions/upload-artifact@main
if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true'
with:
name: OpenWrt_bin${{ env.DEVICE_NAME }}${{ env.FILE_DATE }}
path: openwrt/bin
- name: 整理固件文件
id: organize
if: env.UPLOAD_FIRMWARE == 'true' && !cancelled()
run: |
cd openwrt/bin/targets/*/*
rm -rf packages
echo "FIRMWARE=$PWD" >> $GITHUB_ENV
echo "::set-output name=status::success"
- name: 上传固件目录
uses: actions/upload-artifact@main
if: steps.organize.outputs.status == 'success' && !cancelled()
with:
name: OpenWrt_firmware${{ env.DEVICE_NAME }}${{ env.FILE_DATE }}
path: ${{ env.FIRMWARE }}
- name: 生成发布release标签
id: tag
if: env.UPLOAD_RELEASE == 'true' && !cancelled()
run: |
echo "::set-output name=release_tag::$(date +"%Y.%m.%d-%H%M")"
touch release.txt
#下面这个自己设置的,添加release显示信息,加了这个不显示commit信息,奇怪
echo "
📂 源码: ${{ steps.codes.outputs.repo_url }}
🌳 分支: ${{ steps.codes.outputs.repo_branch }}
🌐 管理地址: 192.168.123.1
👤 用户名: root
🔒 密码: password
" >> release.txt
[ $UPLOAD_COWTRANSFER = true ] && echo "🔗 [Cowtransfer](${{ steps.cowtransfer.outputs.url }})" >> release.txt
[ $UPLOAD_WETRANSFER = true ] && echo "🔗 [WeTransfer](${{ steps.wetransfer.outputs.url }})" >> release.txt
echo "::set-output name=status::success"
- name: Upload firmware to release
uses: softprops/action-gh-release@v1
if: steps.tag.outputs.status == 'success' && !cancelled()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag.outputs.release_tag }}
body_path: release.txt
files: ${{ env.FIRMWARE }}/*
- name: Delete workflow runs
uses: GitRML/delete-workflow-runs@main
with:
retain_days: 1
keep_minimum_runs: 3
token: ${{ secrets.GH_TOKEN }}
body: |
### OpenWrt Image information
- Default IP: 192.168.1.1
- Default username: root
- Default password: password
- Default WIFI name: OpenWrt
- Default WIFI password: none
### Install to EMMC
- Login to OpenWrt → System → Amlogic Service → Install OpenWrt
### OpenWrt Image Verification
- sha256sum