通用设备编译固件 #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#============================================================================================ | |
# 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: "openwrt-main" | |
type: choice | |
options: | |
- openwrt-main | |
- lede-master | |
- immortalwrt-master | |
- Lienol-master | |
env: | |
FEEDS_CONF: config/${{ inputs.source_branch }}/feeds.conf.default | |
CONFIG_FILE: config/${{ inputs.source_branch }}/config | |
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: Initialization environment | |
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: Clone source code [ ${{ 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" | |
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} | |
- name: Load custom 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: Update feeds | |
run: cd openwrt/ && ./scripts/feeds update -a | |
- name: Install feeds | |
run: cd openwrt/ && ./scripts/feeds install -a | |
- name: Load custom configuration | |
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: Download package | |
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: Compile the 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: Check space usage | |
if: (!cancelled()) | |
run: df -hT | |
- name: Upload bin directory | |
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: Organize files | |
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: Upload firmware directory | |
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: Generate release tag | |
id: tag | |
if: env.UPLOAD_RELEASE == 'true' && !cancelled() | |
run: | | |
echo "::set-output name=release_tag::$(date +"%Y.%m.%d-%H%M")" | |
touch 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 | |