163 lines
6.1 KiB
YAML
163 lines
6.1 KiB
YAML
###########################################################
|
|
# Description: Compile OpenWrt by GitHub Actions #
|
|
# Based on: https://github.com/P3TERX/Actions-OpenWrt #
|
|
# Author: Hyy2001X #
|
|
###########################################################
|
|
|
|
name: AutoBuild-d-team_newifi-d2
|
|
|
|
### 以下内容请保持不变 (修改 环境变量设置 中的信息)
|
|
on:
|
|
repository_dispatch:
|
|
workflow_dispatch:
|
|
inputs:
|
|
ip_addr:
|
|
description: '固件 IP 地址 [可选]'
|
|
default: ''
|
|
### END
|
|
|
|
#push:
|
|
# branches:
|
|
# - master
|
|
|
|
#schedule:
|
|
# - cron: 0 8 * * 5
|
|
|
|
#watch:
|
|
# types: [started]
|
|
|
|
### 环境变量设置
|
|
env:
|
|
# 设备名称 (可在 README 中找到获取方法)
|
|
TARGET_PROFILE: d-team_newifi-d2
|
|
# 源码仓库:分支
|
|
DEFAULT_SOURCE: coolsnowwolf/lede:master
|
|
# 上传固件到 Github Releases
|
|
UPLOAD_RELEASES: true
|
|
# 上传固件到 Github Artifacts
|
|
UPLOAD_ARTIFACTS: false
|
|
# 上传 bin 文件夹到 Github Artifacts
|
|
UPLOAD_BIN_ARTIFACTS: false
|
|
# 删除无用文件以释放更多空间
|
|
DELETE_USELESS_FILES: true
|
|
# 删除早期的 workflow 任务
|
|
DELETE_OLD_WORKFLOW: true
|
|
### END
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@main
|
|
|
|
- name: Initialization Define Info
|
|
run: |
|
|
TARGET_PROFILE=${{ env.TARGET_PROFILE }}
|
|
DEFAULT_SOURCE=${{ env.DEFAULT_SOURCE }}
|
|
DELETE_USELESS_FILES=${{ env.DELETE_USELESS_FILES }}
|
|
echo "TARGET_PROFILE=$TARGET_PROFILE" >> $GITHUB_ENV
|
|
echo "DELETE_USELESS_FILES=$DELETE_USELESS_FILES" >> $GITHUB_ENV
|
|
[ ! -f "$GITHUB_WORKSPACE/Configs/$TARGET_PROFILE" ] && {
|
|
echo "[ERROR] config-file [/Config/$TARGET_PROFILE] is not detected!"
|
|
exit 1
|
|
}
|
|
export REPO_URL="https://github.com/$(echo $DEFAULT_SOURCE | cut -d \: -f 1)"
|
|
export REPO_BRANCH=$(echo $DEFAULT_SOURCE | cut -d \: -f 2)
|
|
[ -z $REPO_BRANCH ] && REPO_BRANCH=master
|
|
echo "REPO_URL=$REPO_URL" >> $GITHUB_ENV
|
|
echo "REPO_BRANCH=$REPO_BRANCH" >> $GITHUB_ENV
|
|
echo -e "TARGET_PROFILE: $TARGET_PROFILE\nSOURCE: $REPO_URL:$REPO_BRANCH"
|
|
|
|
- name: Initialization Environment
|
|
env:
|
|
DEBIAN_FRONTEND: noninteractive
|
|
run: |
|
|
sudo -E apt-get update
|
|
sudo -E apt-get -y install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch python3 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler g++-multilib antlr3 gperf wget curl swig rsync qemu-utils
|
|
sudo timedatectl set-timezone "Asia/Shanghai"
|
|
sudo mkdir -p /workdir
|
|
sudo chown $USER:$GROUPS /workdir
|
|
if [ "$DELETE_USELESS_FILES" == true ];then
|
|
echo "Deleting useless files,please wait ..."
|
|
docker rmi $(docker images -q)
|
|
sudo rm -rf /usr/share/dotnet /etc/mysql /etc/php
|
|
sudo -E apt-get -y autoremove --purge
|
|
sudo -E apt-get clean
|
|
fi
|
|
echo "Compile_Date=$(date +%Y%m%d%H%M)" > $GITHUB_WORKSPACE/Openwrt.info
|
|
echo "Display_Date=$(date +%Y/%m/%d)" >> $GITHUB_WORKSPACE/Openwrt.info
|
|
echo "Defined_IP_Address=${{ github.event.inputs.IP }}" >> $GITHUB_WORKSPACE/Openwrt.info
|
|
echo "Openwrt_Repo=$REPO_URL" >> $GITHUB_WORKSPACE/Openwrt.info
|
|
echo "Artifacts_Date=$(date +%m%d%H%M)" >> $GITHUB_ENV
|
|
touch Release_info
|
|
|
|
- name: Clone Openwrt Source Code
|
|
run: |
|
|
git clone -b $REPO_BRANCH $REPO_URL openwrt
|
|
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt
|
|
cd openwrt
|
|
./scripts/feeds update -a
|
|
./scripts/feeds install -a > /dev/null 2>&1
|
|
|
|
- name: Run AutoBuild_DiyScript.sh
|
|
run: |
|
|
chmod +x Scripts/AutoBuild_*.sh
|
|
cp $GITHUB_WORKSPACE/Configs/$TARGET_PROFILE openwrt/.config
|
|
cd openwrt
|
|
make defconfig > /dev/null 2>&1
|
|
source $GITHUB_WORKSPACE/Scripts/AutoBuild_DiyScript.sh
|
|
source $GITHUB_WORKSPACE/Scripts/AutoBuild_Function.sh
|
|
Firmware-Diy_Base
|
|
source $GITHUB_WORKSPACE/openwrt/VARIABLE_FILE_Sec && Firmware-Diy
|
|
rm -f .config && cp $GITHUB_WORKSPACE/Configs/$TARGET_PROFILE .config
|
|
|
|
- name: Compile
|
|
run: |
|
|
export Compile_Result=false
|
|
cd openwrt
|
|
source $GITHUB_WORKSPACE/Scripts/AutoBuild_Function.sh && Other_Scripts
|
|
rm -rf ./tmp && ./scripts/feeds install -a > /dev/null 2>&1
|
|
make defconfig
|
|
make download -j$(nproc)
|
|
make -j$(nproc) || make -j1 V=s
|
|
[ $? == 0 ] && Compile_Result=true
|
|
echo "Compile_Result=$Compile_Result" >> $GITHUB_ENV
|
|
|
|
- name: Process Firmware
|
|
if: env.Compile_Result == 'true' && !cancelled()
|
|
run: |
|
|
cd openwrt
|
|
source $GITHUB_WORKSPACE/Scripts/AutoBuild_Function.sh && PS_Firmware
|
|
|
|
- name: Upload Firmware to Artifacts
|
|
uses: actions/upload-artifact@main
|
|
if: env.UPLOAD_ARTIFACTS == 'true' && env.Compile_Result == 'true' && !cancelled()
|
|
with:
|
|
name: ${{ env.TARGET_PROFILE }}_${{ env.REPO_BRANCH }}_firmware_${{ env.Artifacts_Date }}
|
|
path: openwrt/bin/Firmware
|
|
|
|
- name: Upload bin to Artifacts
|
|
uses: actions/upload-artifact@main
|
|
if: env.UPLOAD_BIN_ARTIFACTS == 'true' && env.Compile_Result == 'true' && !cancelled()
|
|
with:
|
|
name: ${{ env.TARGET_PROFILE }}_${{ env.REPO_BRANCH }}_bin_${{ env.Artifacts_Date }}
|
|
path: openwrt/bin
|
|
|
|
- name: Upload Firmware to Github Releases
|
|
uses: softprops/action-gh-release@v1
|
|
if: env.UPLOAD_RELEASES == 'true' && env.Compile_Result == 'true' && !cancelled()
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
with:
|
|
tag_name: AutoUpdate
|
|
body_path: Release_info
|
|
files: openwrt/bin/Firmware/*
|
|
|
|
- name: Delete old Workflow Runs
|
|
uses: GitRML/delete-workflow-runs@main
|
|
if: env.DELETE_OLD_WORKFLOW == 'true' && !cancelled()
|
|
with:
|
|
retain_days: 1
|
|
keep_minimum_runs: 3 |