Skip to content

Build Image [basic, No.6, @latest] #110

Build Image [basic, No.6, @latest]

Build Image [basic, No.6, @latest] #110

Workflow file for this run

#
# Copyright (c) 2019-2020 P3TERX <https://p3terx.com>
#
# This is free software, licensed under the MIT License.
# See /LICENSE for more information.
#
# https://github.com/P3TERX/Actions-OpenWrt
# Description: Build OpenWrt using GitHub Actions
#
name: Build Image
run-name: Build Image [${{ inputs.config_tag }}, No.${{ inputs.device_choice }}, @${{ inputs.commit_sha }}]
on:
repository_dispatch:
workflow_dispatch:
inputs:
device_choice:
description: '选择型号(device-env.sh中的编号)'
required: false
default: 5
type: number
config_tag:
type: choice
required: true
description: '选择配置版本'
default: 'func'
options:
- clean
- basic
- func
- test
commit_sha:
description: '使用指定的commit(可选)'
required: false
default: 'latest'
use_cache:
description: '尝试使用缓存的tool和toolchain'
required: false
default: true
type: boolean
ssh:
description: '编译前进行SSH调试'
required: false
default: false
type: boolean
env:
# REPO_URL: https://github.com/openwrt/openwrt
# REPO_BRANCH: master
FEEDS_CONF: feeds.conf.default
CONFIG_FILE: .config
COMMIT_SHA: ${{ inputs.commit_sha }}
DIY_P1_SH: diy-part1.sh
# DIY_P2_SH: diy-part2/[OpenWrt]RE-SP-01B-part2.sh
UPLOAD_BIN_DIR: true
UPLOAD_FIRMWARE: true
UPLOAD_TRANSFER: true
UPLOAD_RELEASE: false
TZ: Asia/Shanghai
jobs:
init:
runs-on: ubuntu-22.04
outputs:
DEVICE_TAG: ${{steps.job_tag.outputs.DEVICE_TAG}}
steps:
- uses: actions/checkout@main
- name: Load environment variable
run: |
chmod +x $GITHUB_WORKSPACE/device-env.sh
$GITHUB_WORKSPACE/device-env.sh ${{ inputs.device_choice }}
- id: job_tag
run: |
# notifications
# echo "::set-output name=DEVICE_TAG::${DEVICE_TAG}"
echo "DEVICE_TAG=${DEVICE_TAG}" >> $GITHUB_OUTPUT
echo "::notice title=Task Summary::Compile using the ${{ inputs.config_tag }}.config of device No.${{ inputs.device_choice }}(${DEVICE_TAG})"
# 若指定了 commit 提个醒
if [ "$USE_COMMIT_SHA" == "latest" ]; then
LATEST_SHA=$(curl "https://api.github.com/repos/$REPO_USE/commits/$REPO_BRANCH" | grep sha | head -n1 | cut -d\" -f4)
echo "::notice title=Using commit::[latest] https://github.com/$REPO_USE/tree/$LATEST_SHA"
else
echo "::notice title=Using commit::[specific] https://github.com/$REPO_USE/tree/$USE_COMMIT_SHA"
fi
build:
runs-on: ubuntu-22.04
needs: init
name: ${{needs.init.outputs.DEVICE_TAG}}
steps:
- uses: actions/checkout@main
- name: Load Environment Variable
run: |
chmod +x $GITHUB_WORKSPACE/device-env.sh
$GITHUB_WORKSPACE/device-env.sh ${{ inputs.device_choice }}
- name: Initialize Environment
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc
sudo -E apt-get -qq update
sudo -E apt-get -qq install $DEPENDS
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
# docker image prune -a -f
sudo timedatectl set-timezone "$TZ"
sudo mkdir -p /workdir
sudo chown $USER:$GROUPS /workdir
- name: Clone Source Code
working-directory: /workdir
run: |
df -hT | tee /workdir/df.before
git clone https://github.com/$REPO_USE -b $REPO_BRANCH openwrt
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt
# 若指定了 commit
if [ "$USE_COMMIT_SHA" != "latest" ]; then
cd openwrt
git checkout "$USE_COMMIT_SHA"
cd ..
fi
- name: Cache
uses: klever1988/cachewrtbuild@main
if: ${{ inputs.use_cache }}
with:
ccache: 'false'
prefix: ${{ github.workspace }}/openwrt
- name: Load Custom Feeds
run: |
[ -e $FEEDS_CONF ] && mv $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: |
[ -e files ] && echo '::notice title=Image Type:: 已启用files大法!' && mv -v files openwrt/files
[ -e $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config
chmod +x "$DIY_P2_SH"
cd openwrt
# 使用脚本生成配置
"$GITHUB_WORKSPACE/$DIY_P2_SH" ${{ inputs.config_tag }}
echo ==============.config===============
[ -e .config ] && cat .config || (echo '.config NOT FOUND!' && exit 1)
echo ====================================
- name: Download Packages
id: download
run: |
cd openwrt
make defconfig
# 分析配置文件是否包含补丁
subset_check=$(comm -23 <(sed '/# -/d' .config.old | sort | uniq) <(sort .config | uniq) | tee .notfound)
if [[ -z $subset_check ]]; then
echo "自定义配置(${{ inputs.config_tag }})是 .conifg 的子集"
else
echo "自定义配置(${{ inputs.config_tag }})不是 .conifg 的子集!以下配置行未在 .config 中找到"
cat .notfound
echo "=====================EOF======================="
echo "::warning title=Config fault::Custom config is not a subset of .config, please check..."
fi
# 从DIY_P2_SH中截取型号信息
grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/' > DEVICE_NAME
[ -s DEVICE_NAME ] && echo "::notice title=Target Name in .config:: $(cat DEVICE_NAME)" && echo "DEVICE_NAME=$(cat DEVICE_NAME)" >> $GITHUB_ENV
echo =============current .config DIFF default config=============
./scripts/diffconfig.sh
echo ===========================EoDIFF============================
# 下载包,如若出错生成警告
# 一轮八线程
make download -j8 | tee make_download.log
grep 'ERROR:' make_download.log | xargs -i echo "::warning:: [Download Trial 1]" {}
find dl -size -1024c -exec ls -l {} \;
find dl -size -1024c -exec rm -f {} \;
# 二轮单线程
grep 'ERROR:' -q -m1 make_download.log && make download -j1 V=s | tee make_download.log
grep 'ERROR:' make_download.log | xargs -i echo "::warning:: [Download Trial 2]" {}
find dl -size -1024c -exec ls -l {} \;
find dl -size -1024c -exec rm -f {} \;
- name: SSH Before Compile
uses: mxschmitt/action-tmate@v3
with:
limit-access-to-actor: false
if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh')
- name: Compile
id: compile
run: |
# 计时起点,启动打点计时器
start_time=$(date +%s)
( while true; do echo "...Timer.$[ $(date +%s)-${start_time} ]s" >&2 && sleep 20; done ) &
TIMER_PID=$!
# 启动编译任务
cd openwrt
echo -e "Initiate Compilation. Try $(($(nproc)+1)) thread first..."
make -j $(($(nproc)+1)) || make -j1 || make -j1 V=s.
echo "TimeStamp=$(date +"%Y%m%d-%H%M")" >> $GITHUB_ENV
# 复制配置文件到 bin/targets/[arch]/[subtarget]/ 目录,最终一并打包
SUBTARGET_FOLDER=$(realpath bin/targets/*/*)
cp -v .config ${SUBTARGET_FOLDER}/
# 计时终点,关闭打点计时器
kill -15 $TIMER_PID
end_time=$(date +%s)
cost_time=$[ ${end_time}-${start_time} ]
echo "==============================================="
echo -ne "Start Time:\t${start_time}\nEnd Time:\t${end_time}\nCost Time:\t${cost_time}\n" | tee ${SUBTARGET_FOLDER}/Timer.log
echo "==============================================="
- name: Check Space Usage
if: (!cancelled())
run: |
echo "=======================BEFORE========================"
cat /workdir/df.before
echo "========================AFTER========================"
df -hT
- name: Upload Bin Directory
uses: actions/upload-artifact@main
if: steps.compile.conclusion == 'success' && env.UPLOAD_BIN_DIR == 'true'
with:
name: OpenWrt_bin_${{ env.DEVICE_NAME }}_${{ env.TimeStamp }}
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
- name: Upload Firmware Directory
uses: actions/upload-artifact@main
if: steps.organize.conclusion == 'success' && !cancelled()
with:
name: OpenWrt_firmware_${{ env.DEVICE_NAME }}_${{ env.TimeStamp }}
path: ${{ env.FIRMWARE }}
- name: Upload Using File-transfer
id: transfer
if: steps.organize.conclusion == 'success' && env.UPLOAD_TRANSFER == 'true' && !cancelled()
run: |
curl -fsSL git.io/file-transfer | sh
# 返回链接格式:【 Download Link: https://we.tl/t-fLXXXXXXzJ 】
touch release.txt
echo 'wetransfer(2GB)'
(
./transfer wet -s -p 4 --no-progress ${FIRMWARE} 2>&1 | tee transfer.wet.log
echo "::notice title=@wetransfer.com::$(cat transfer.wet.log | grep https)"
echo "🔗 [WeTransfer]($(cat transfer.wet.log | grep https | cut -f3 -d' '))" >> release.txt
)
echo 'Musetransfer(10GB)'
(
./transfer muse -s -p 4 --no-progress ${FIRMWARE} 2>&1 | tee transfer.muse.log
echo "::notice title=@musetransfer.com::$(cat transfer.muse.log | grep https)"
echo "🔗 [Musetransfer]($(cat transfer.muse.log | grep https | cut -f3 -d' '))" >> release.txt
)
echo 'GoFile(-)'
(
./transfer gof -s --no-progress ${FIRMWARE} 2>&1 | tee transfer.gof.log
echo "::notice title=@gofile.io::$(cat transfer.gof.log | grep https)"
echo "🔗 [GoFile]($(cat transfer.gof.log | grep https | cut -f3 -d' '))" >> release.txt
)
# echo 'DownloadGG(25GB, no single mode yet)'
# (
# ./transfer gg --no-progress ${FIRMWARE} 2>&1 | tee transfer.gg.log
# echo "::notice title=@download.gg::$(cat transfer.gg.log | grep https)"
# echo "🔗 [DownloadGG]($(cat transfer.gg.log | grep https | cut -f3 -d' '))" >> release.txt
# )
# echo 'Wenshushu(2GB, meet captcha)'
# echo ref: https://github.com/Mikubill/transfer/issues/55
# (
# ./transfer wss -s -p 4 --no-progress ${FIRMWARE} 2>&1 | tee transfer.wss.log
# echo "::notice title=@wenshushu.cn::$(cat transfer.wss.log | grep https)"
# echo "🔗 [Wenshushu]($(cat transfer.wss.log | grep https | cut -f3 -d' '))" >> release.txt
# )
# echo 'cowtransfer(need login)'
# (
# ./transfer cow --block 2621440 -s -p 64 --no-progress ${FIRMWARE} 2>&1 | tee transfer.cow.log
# echo "::notice title=@cowtransfer.com::$(cat cowtransfer.log | grep https)"
# echo "🔗 [Cowtransfer]($(cat transfer.cow.log | grep https | cut -f3 -d' '))" >> release.txt
# )
# echo 'LitterBox(1GB, no single mode)'
# (
# ./transfer lit --no-progress ${FIRMWARE} 2>&1 | tee transfer.lit.log
# echo "::notice title=@litterbox.catbox.moe::$(cat transfer.lit.log | grep https)"
# echo "🔗 [LitterBox]($(cat transfer.lit.log | grep https | cut -f3 -d' '))" >> release.txt
# )
# echo '1Fichier(300GB, no single mode)'
# (
# ./transfer fic --no-progress ${FIRMWARE} 2>&1 | tee transfer.fic.log
# echo "::notice title=@1fichier.com::$(cat transfer.fic.log | grep https)"
# echo "🔗 [1Fichier]($(cat transfer.fic.log | grep https | cut -f3 -d' '))" >> release.txt
# )
# echo 'Anonfile(10GB, no single mode)'
# (
# ./transfer anon --no-progress ${FIRMWARE} 2>&1 | tee transfer.anon.log
# echo "::notice title=@anonfile.com::$(cat transfer.anon.log | grep https)"
# echo "🔗 [Anonfile]($(cat transfer.anon.log | grep https | cut -f3 -d' '))" >> release.txt
# )
# echo 'Transfer.sh(-, will be zip/tar)'
# (
# ./transfer trs -s --no-progress ${FIRMWARE} 2>&1 | tee transfer.trs.log
# echo "::notice title=@Transfer.sh::$(cat transfer.trs.log | grep https)"
# echo "🔗 [Transfer.sh]($(cat transfer.trs.log | grep https | cut -f3 -d' '))" >> release.txt
# )
wait
# for release
# echo "::set-output name=release_tag::$(date +"%Y.%m.%d-%H%M")"
echo "release_tag=$(date +"%Y.%m.%d-%H%M")" >> $GITHUB_OUTPUT
- name: SSH After Compile
uses: mxschmitt/action-tmate@v3
if: ${{ failure() }}
- name: Upload Firmware to Release
uses: softprops/action-gh-release@v1
if: env.UPLOAD_RELEASE == 'true' && steps.transfer.conclusion == 'success' && !cancelled()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.transfer.outputs.release_tag }}
body_path: release.txt
files: ${{ env.FIRMWARE }}/*
- name: Delete Workflow Runs
uses: Mattraks/delete-workflow-runs@main
with:
retain_days: 30
keep_minimum_runs: 5
- name: Remove Old Releases
uses: dev-drprasad/delete-older-releases@v0.2.0
if: env.UPLOAD_RELEASE == 'true' && !cancelled()
with:
keep_latest: 3
delete_tags: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}