From 31e4cf7489776640e42b11f3c2b3b0209a33e79e Mon Sep 17 00:00:00 2001 From: Hyy2001X <1804430051@qq.com> Date: Wed, 26 May 2021 21:28:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20workflow=20=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E4=B8=BA=20AutoBuild-Test.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/AutoBuild-Sample.yml | 166 ------------------------ .github/workflows/AutoBuild-Test.yml | 168 +++++++++++++++++++++++++ 2 files changed, 168 insertions(+), 166 deletions(-) delete mode 100644 .github/workflows/AutoBuild-Sample.yml create mode 100644 .github/workflows/AutoBuild-Test.yml diff --git a/.github/workflows/AutoBuild-Sample.yml b/.github/workflows/AutoBuild-Sample.yml deleted file mode 100644 index 5fa777e..0000000 --- a/.github/workflows/AutoBuild-Sample.yml +++ /dev/null @@ -1,166 +0,0 @@ -#======================================================= -# Description: Build OpenWrt using GitHub Actions -# https://github.com/Hyy2001X/AutoBuild-Actions -# Lisence: MIT -# Author: P3TERX -# Modify: Hyy2001X -#======================================================= - -name: AutoBuild-Sample - -on: - repository_dispatch: - workflow_dispatch: - inputs: - ssh: - description: 'SSH 连接到 Actions' - required: true - default: 'false' - target_name: - description: '设备名称 [必选]' - default: 'x86_64' - openwrt_sc: - description: 'Openwrt 源码:分支 [必选]' - default: 'coolsnowwolf/lede:master' - ip_addr: - description: '固件 IP 地址 [可选]' - default: '' - -env: - DIY_SCRIPT: Scripts/AutoBuild_DiyScript.sh - FUNCTION_SCRIPT: Scripts/AutoBuild_Function.sh - UPLOAD_RELEASE: true - UPLOAD_FIRMWARE: false - UPLOAD_BIN_DIR: false - REMOVE_USELESS_FILES: true - REMOVE_WORKFLOW_RUNS: true - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@main - - - name: Initialization Defined Info - run: | - [[ -n "${{ github.event.inputs.target_name }}" ]] && { - echo "设备名称: ${{ github.event.inputs.target_name }}" - } || { - echo "[ERROR] 未输入设备名称!" - exit 1 - } - [ ! -f "$GITHUB_WORKSPACE/Configs/${{ github.event.inputs.target_name }}" ] && { - echo "[ERROR] 未检测到设备对应的 [${{ github.event.inputs.target_name }}] 的配置文件!" - exit 1 - } - URL_BRANCH=${{ github.event.inputs.openwrt_sc }} - URL="https://github.com/$(echo $URL_BRANCH | egrep -o ".*:")" - REPO_URL=${URL%?} - REPO_BRANCH=$(echo $URL_BRANCH | egrep -o ":.*" | cut -c2-100) - [[ -z $REPO_BRANCH ]] && REPO_BRANCH=master - echo "REPO_URL=$REPO_URL" >> $GITHUB_ENV - echo "REPO_BRANCH=$REPO_BRANCH" >> $GITHUB_ENV - echo -e "源码地址: $REPO_URL\n分支: $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 - 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_addr }}" >> $GITHUB_WORKSPACE/Openwrt.info - echo "Artifacts_Date=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV - touch update_log.txt - - - name: Remove useless files - if: env.REMOVE_USELESS_FILES == 'true' && !cancelled() - run: | - 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 - - - name: Clone Openwrt source code - run: | - git clone -b $REPO_BRANCH $REPO_URL openwrt - ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt - [ -f Configs/${{ github.event.inputs.target_name }} ] && cp Configs/${{ github.event.inputs.target_name }} openwrt/.config || { - echo "未检测到该设备的 ${{ github.event.inputs.target_name }} 配置文件!" - exit 1 - } - cd openwrt - ./scripts/feeds update -a > /dev/null 2>&1 - ./scripts/feeds install -a - - - name: Run Customize Diy-Scripts - run: | - chmod +x $DIY_SCRIPT - chmod +x $FUNCTION_SCRIPT - cd openwrt - source $GITHUB_WORKSPACE/$DIY_SCRIPT - source $GITHUB_WORKSPACE/$FUNCTION_SCRIPT - Firmware-Diy_Base - Firmware-Diy - - - name: SSH connection to Actions - uses: P3TERX/ssh2actions@v1.0.0 - if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh') - env: - TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} - TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} - - - name: Compile the Openwrt - run: | - cd openwrt - ./scripts/feeds install -a - make defconfig - make download -j8 - echo "Start to compile OpenWrt for $CONFIG_FILE..." - make -j$(nproc) || make -j1 V=s - - - name: Process the AutoBuild Firmware - run: | - cd openwrt - source $GITHUB_WORKSPACE/$FUNCTION_SCRIPT && PS_Firmware - - - name: Upload Firmware to Artifacts - uses: actions/upload-artifact@main - if: env.UPLOAD_FIRMWARE == 'true' && !cancelled() - with: - name: ${{ github.event.inputs.target_name }}_${{ env.REPO_BRANCH }}_Firmware - path: openwrt/bin/Firmware - - - name: Upload bin directory to Artifacts - uses: actions/upload-artifact@main - if: env.UPLOAD_BIN_DIR == 'true' && !cancelled() - with: - name: ${{ github.event.inputs.target_name }}_${{ env.REPO_BRANCH }}_BINDir - path: openwrt/bin - - - name: Upload Firmware to Release - uses: softprops/action-gh-release@v1 - if: env.UPLOAD_RELEASE == 'true' && !cancelled() - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: AutoUpdate - body_path: update_log.txt - files: openwrt/bin/Firmware/* - - - name: Remove workflow runs - uses: GitRML/delete-workflow-runs@main - if: env.REMOVE_WORKFLOW_RUNS == 'true' && !cancelled() - with: - retain_days: 1 - keep_minimum_runs: 3 diff --git a/.github/workflows/AutoBuild-Test.yml b/.github/workflows/AutoBuild-Test.yml new file mode 100644 index 0000000..b6c370d --- /dev/null +++ b/.github/workflows/AutoBuild-Test.yml @@ -0,0 +1,168 @@ +########################################################### +# Description: Compile OpenWrt by GitHub Actions # +# Based on: https://github.com/P3TERX/Actions-OpenWrt # +# Author: Hyy2001X # +########################################################### + +name: AutoBuild-Test + +### 以下内容请保持不变 +on: + repository_dispatch: + workflow_dispatch: + inputs: + SSH: + description: 'SSH 连接到 Actions' + required: true + default: 'false' + DEFAULT_TARGET: + description: '设备名称 [必选]' + default: 'x86_64' + DEFAULT_SOURCE: + description: '源码:分支 [必选]' + default: 'coolsnowwolf/lede:master' + IP: + description: '固件 IP 地址 [可选]' + default: '' + DELETE_USELESS_FILES: + description: '清理无用文件 [可选]' + default: 'true' +### END + +### 环境变量设置 +env: +# 上传固件到 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: | + DEFAULT_TARGET=${{ github.event.inputs.DEFAULT_TARGET }} + DEFAULT_SOURCE=${{ github.event.inputs.DEFAULT_SOURCE }} + DELETE_USELESS_FILES=${{ github.event.inputs.DELETE_USELESS_FILES }} + echo "DEFAULT_TARGET=$DEFAULT_TARGET" >> $GITHUB_ENV + echo "DELETE_USELESS_FILES=$DELETE_USELESS_FILES" >> $GITHUB_ENV + [ ! -f "$GITHUB_WORKSPACE/Configs/$DEFAULT_TARGET" ] && { + echo "[ERROR] No target_config file: [$DEFAULT_TARGET] 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: $DEFAULT_TARGET\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/$DEFAULT_TARGET 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 && Firmware-Diy + rm -f .config && cp $GITHUB_WORKSPACE/Configs/$DEFAULT_TARGET .config + + - name: SSH Connection to Actions + uses: P3TERX/ssh2actions@v1.0.0 + if: (github.event.inputs.SSH == 'true' && github.event.inputs.SSH != 'false') || contains(github.event.action, 'SSH') + env: + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + + - 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.DEFAULT_TARGET }}_${{ 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.DEFAULT_TARGET }}_${{ 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 \ No newline at end of file