Build iStoreOS For Multi Platform Devices #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
# | |
# 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 iStoreOS For Multi Platform Devices | |
on: | |
repository_dispatch: | |
workflow_dispatch: | |
inputs: | |
ssh: | |
description: 'SSH connection to Actions' | |
required: false | |
default: 'false' | |
type: choice | |
options: | |
- true | |
- false | |
target: | |
description: '(Deprecated) Build target ["mt7621", "rk33xx", "rk35xx", "x86_64", "ALL"]' | |
required: false | |
default: 'x86_64' | |
architecture: | |
description: 'Build architecture ["mt7621", "rk33xx", "rk35xx", "x86_64"]' | |
required: true | |
default: 'x86_64' | |
type: choice | |
options: | |
- "ALL" | |
- mt7621 | |
- rk33xx | |
- rk35xx | |
- x86_64 | |
# schedule: | |
# - cron: 0 0 2 * * | |
env: | |
REPO_URL: https://github.com/istoreos/istoreos | |
# REPO_BRANCH: master | |
FEEDS_CONF: feeds.conf.default | |
CONFIG_FILE: .config | |
DIY_P1_SH: diy-part1.sh | |
DIY_P2_SH: diy-part2.sh | |
CACHE_TOOLCHAIN: true | |
UPLOAD_BIN_DIR: false | |
UPLOAD_FIRMWARE: true | |
UPLOAD_COWTRANSFER: false | |
UPLOAD_WETRANSFER: false | |
UPLOAD_RELEASE: true | |
TZ: Asia/Shanghai | |
jobs: | |
Matrix: | |
runs-on: ubuntu-22.04 | |
outputs: | |
MATRIX_TARGET: ${{ steps.set-matrix.outputs.MATRIX_TARGET }} | |
MATRIX_ARCHITECTURE: ${{ steps.set-matrix.outputs.MATRIX_ARCHITECTURE }} | |
steps: | |
- name: Detect Build Target | |
id: set-matrix | |
env: | |
INPUT_TARGET: ${{ github.event.inputs.target }} | |
INPUT_ARCHITECTURE: ${{ github.event.inputs.architecture }} | |
run: | | |
if [ "x${INPUT_TARGET}" = "x" -o "x${INPUT_TARGET}" = "xALL" ]; then \ | |
echo "MATRIX_TARGET={\"target\":[\"mt7621\", \"rk33xx\", \"rk35xx\", \"x86_64\"]}" >> $GITHUB_OUTPUT; \ | |
else \ | |
targets=""; \ | |
for target in ${INPUT_TARGET}; do \ | |
targets="$targets, \"$target\""; | |
done; \ | |
echo "MATRIX_TARGET={\"target\":[${targets#, }]}" >> $GITHUB_OUTPUT; \ | |
fi | |
if [ "x${INPUT_ARCHITECTURE}" = "x" -o "x${INPUT_ARCHITECTURE}" = "xALL" ]; then \ | |
echo "MATRIX_ARCHITECTURE=[\"mt7621\", \"rk33xx\", \"rk35xx\", \"x86_64\"]" >> $GITHUB_OUTPUT; \ | |
else \ | |
architectures=""; \ | |
for architecture in ${INPUT_ARCHITECTURE}; do \ | |
architectures="$architectures, \"$architecture\""; | |
done; \ | |
echo "MATRIX_ARCHITECTURE=[${architectures#, }]" >> $GITHUB_OUTPUT; \ | |
fi | |
Build: | |
needs: [Matrix] | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
REPO_BRANCH: | |
# - main | |
# - istoreos-21.02 | |
- istoreos-22.03 | |
# TARGET: ${{ fromJson(needs.Matrix.outputs.MATRIX_TARGET).target }} | |
ARCHITECTURE: ${{ fromJson(needs.Matrix.outputs.MATRIX_ARCHITECTURE) }} | |
# - mt7621 | |
# - rk33xx | |
# - rk35xx | |
# - x86_64 | |
os: | |
- ubuntu-22.04 | |
include: | |
- REPO_BRANCH: istoreos-23.05 | |
ARCHITECTURE: x86-alpha | |
os: ubuntu-22.04 | |
fail-fast: false | |
steps: | |
- name: Checkout | |
uses: actions/checkout@main | |
- name: Check Server Performance | |
run: | | |
echo "警告⚠" | |
echo "分配的服务器性能有限, 若选择的插件过多, 务必注意CPU性能!" | |
echo -e "已知CPU型号(降序): 7763, 8370C, 8272CL, 8171M, E5-2673\n" | |
echo "--------------------------CPU信息--------------------------" | |
echo "CPU物理数量: $(cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l)" | |
echo "CPU核心数量: $(nproc)" | |
echo -e "CPU型号信息:$(cat /proc/cpuinfo | grep -m1 name | awk -F: '{print $2}')\n" | |
echo "--------------------------内存信息--------------------------" | |
echo "已安装内存详细信息:" | |
echo -e "$(sudo lshw -short -C memory | grep GiB)\n" | |
echo "--------------------------硬盘信息--------------------------" | |
echo "硬盘数量: $(ls /dev/sd* | grep -v [1-9] | wc -l)" && df -hT | |
- name: Initialization Environment | |
env: | |
DEBIAN_FRONTEND: noninteractive | |
run: | | |
docker rmi $(docker images -q) | |
sudo rm -rf /usr/share/dotnet /etc/apt/sources.list.d /usr/local/lib/android $AGENT_TOOLSDIRECTORY | |
sudo -E apt-get -y purge azure-cli* docker* ghc* zulu* hhvm* llvm* firefox* google* dotnet* aspnetcore* powershell* openjdk* adoptopenjdk* mysql* php* mongodb* moby* snap* || true | |
sudo -E apt-get -y update | |
# sudo -E apt-get -y install $(curl -fsSL git.io/depends-ubuntu-2204) | |
# sudo -E apt-get -y install $(curl -fsSL is.gd/depends_ubuntu_2204) | |
sudo -E apt-get -yqq install $(cat $GITHUB_WORKSPACE/depends/${{ matrix.os }}) | |
sudo -E systemctl daemon-reload | |
sudo -E apt-get -y autoremove --purge | |
sudo -E apt-get -y clean | |
sudo timedatectl set-timezone "$TZ" | |
# - name: Combine Disks | |
# run: | | |
# sudo swapoff -a && sudo rm -f /mnt/swapfile | |
# export ROOT_FREE_KB=$(df --block-size=1024 --output=avail / | tail -1) | |
# export ROOT_LOOP_KB=$(expr $ROOT_FREE_KB - 1048576) | |
# export ROOT_LOOP_BYTES=$(expr $ROOT_LOOP_KB \* 1024) | |
# sudo fallocate -l $ROOT_LOOP_BYTES /root.img | |
# export ROOT_LOOP_DEVNAME=$(sudo losetup -Pf --show /root.img) | |
# sudo pvcreate -f $ROOT_LOOP_DEVNAME | |
# export MNT_FREE_KB=$(df --block-size=1024 --output=avail /mnt | tail -1) | |
# export MNT_LOOP_KB=$(expr $MNT_FREE_KB - 102400) | |
# export MNT_LOOP_BYTES=$(expr $MNT_LOOP_KB \* 1024) | |
# sudo fallocate -l $MNT_LOOP_BYTES /mnt/mnt.img | |
# export MNT_LOOP_DEVNAME=$(sudo losetup -Pf --show /mnt/mnt.img) | |
# sudo pvcreate -f $MNT_LOOP_DEVNAME | |
# sudo vgcreate vgstorage $ROOT_LOOP_DEVNAME $MNT_LOOP_DEVNAME | |
# sudo lvcreate -n lvstorage -l 100%FREE vgstorage | |
# export LV_DEVNAME=$(sudo lvscan | awk -F "'" '{print $2}') | |
# sudo mkfs.btrfs -L combinedisk $LV_DEVNAME | |
# sudo mount -o compress=zstd $LV_DEVNAME $GITHUB_WORKSPACE | |
# sudo chown -R runner:runner $GITHUB_WORKSPACE | |
# mkdir $GITHUB_WORKSPACE/tmp && chmod 777 $GITHUB_WORKSPACE/tmp | |
# sudo cp -rp /tmp/* $GITHUB_WORKSPACE/tmp | |
# sudo mount -B $GITHUB_WORKSPACE/tmp /tmp && df -hT | |
- name: Clone Source Code | |
run: | | |
df -hT $GITHUB_WORKSPACE | |
git clone $REPO_URL -b ${{ matrix.REPO_BRANCH }} openwrt | |
cd openwrt | |
echo "OPENWRT_PATH=$PWD" >> $GITHUB_ENV | |
COMMIT_AUTHOR=$(git show -s --date=short --format="作者: %an") | |
echo "COMMIT_AUTHOR=$COMMIT_AUTHOR" >> $GITHUB_ENV | |
COMMIT_DATE=$(git show -s --date=short --format="时间: %ci") | |
echo "COMMIT_DATE=$COMMIT_DATE" >> $GITHUB_ENV | |
COMMIT_MESSAGE=$(git show -s --date=short --format="日志: %s") | |
echo "COMMIT_MESSAGE=$COMMIT_MESSAGE" >> $GITHUB_ENV | |
COMMIT_HASH=$(git show -s --date=short --format="Hash: %H") | |
echo "COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_ENV | |
- name: Generate Variables | |
run: | | |
cp iStoreOS/${{ matrix.ARCHITECTURE }}/$CONFIG_FILE $OPENWRT_PATH/.config | |
cd $OPENWRT_PATH | |
make defconfig > /dev/null 2>&1 | |
SOURCE_REPO="$(echo $REPO_URL | awk -F '/' '{print $(NF)}')" | |
echo "SOURCE_REPO=$SOURCE_REPO" >> $GITHUB_ENV | |
DEVICE_TARGET=$(cat .config | grep CONFIG_TARGET_BOARD | awk -F '"' '{print $2}') | |
echo "DEVICE_TARGET=$DEVICE_TARGET" >> $GITHUB_ENV | |
DEVICE_SUBTARGET=$(cat .config | grep CONFIG_TARGET_SUBTARGET | awk -F '"' '{print $2}') | |
echo "DEVICE_SUBTARGET=$DEVICE_SUBTARGET" >> $GITHUB_ENV | |
- name: Cache Toolchain | |
if: env.CACHE_TOOLCHAIN == 'true' | |
uses: HiGarfield/cachewrtbuild@main | |
with: | |
ccache: true | |
mixkey: ${{ env.SOURCE_REPO }}-${{ matrix.REPO_BRANCH }}-${{ matrix.ARCHITECTURE }}-${{ env.DEVICE_TARGET }}-${{ env.DEVICE_SUBTARGET }} | |
prefix: ${{ env.OPENWRT_PATH }} | |
- name: Load Custom Feeds | |
env: | |
DIY_P1_SH_PATH: iStoreOS/${{ matrix.ARCHITECTURE }}/${{ env.DIY_P1_SH }} | |
run: | | |
[ -e $FEEDS_CONF ] && mv $FEEDS_CONF openwrt/feeds.conf.default | |
chmod +x $DIY_P1_SH_PATH | |
cd openwrt | |
$GITHUB_WORKSPACE/$DIY_P1_SH_PATH | |
- name: Install Feeds | |
run: | | |
cd $OPENWRT_PATH | |
./scripts/feeds update -a | |
./scripts/feeds install -a | |
- name: Load Custom Configuration | |
env: | |
CONFIG_FILE_PATH: iStoreOS/${{ matrix.ARCHITECTURE }}/${{ env.CONFIG_FILE }} | |
DIY_P2_SH_PATH: iStoreOS/${{ matrix.ARCHITECTURE }}/${{ env.DIY_P2_SH }} | |
run: | | |
[ -e files ] && mv files openwrt/files | |
[ -e $CONFIG_FILE_PATH ] && mv $CONFIG_FILE_PATH openwrt/.config | |
chmod +x $DIY_P2_SH_PATH | |
cd openwrt | |
$GITHUB_WORKSPACE/$DIY_P2_SH_PATH | |
- name: Download DL Package | |
run: | | |
cd $OPENWRT_PATH | |
make defconfig | |
make download -j8 | |
find dl -size -1024c -exec ls -l {} \; | |
find dl -size -1024c -exec rm -f {} \; | |
- name: Compile Firmware | |
id: compile | |
run: | | |
cd $OPENWRT_PATH | |
echo -e "$(nproc) thread compile" | |
make -j$(nproc) || make -j1 || make -j1 V=s | |
echo "DATE=$(date +"%Y-%m-%d %H:%M:%S")" >> $GITHUB_ENV | |
echo "FILE_DATE=$(date +"%Y.%m.%d_%H%M")" >> $GITHUB_ENV | |
echo "status=success" >> $GITHUB_OUTPUT | |
- name: Check Space Usage | |
if: (!cancelled()) | |
run: df -hT | |
- name: Upload Bin Directory | |
if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true' | |
uses: actions/upload-artifact@main | |
with: | |
name: ${{ env.SOURCE_REPO }}-bin-${{ env.DEVICE_TARGET }}-${{ env.DEVICE_SUBTARGET }}-${{ env.FILE_DATE }} | |
path: ${{ env.OPENWRT_PATH }}/bin | |
- name: Organize Files | |
id: organize | |
if: steps.compile.outputs.status == 'success' && !cancelled() | |
run: | | |
cd $OPENWRT_PATH/bin/targets/*/* | |
cat sha256sums | |
cp $OPENWRT_PATH/.config build.config | |
mv -f $OPENWRT_PATH/bin/packages/*/*/*.ipk packages | |
tar -zcf Packages.tar.gz packages | |
rm -rf istoreos-imagebuilder-* packages *kernel.bin *rootfs.img.gz | |
# rm -rf packages *.buildinfo *.manifest *kernel.bin *rootfs.img.gz profiles.json | |
echo "KERNEL=$(cat *.manifest | grep ^kernel | cut -d- -f2 | tr -d ' ')" >> $GITHUB_ENV | |
echo "FIRMWARE_PATH=$PWD" >> $GITHUB_ENV | |
echo "status=success" >> $GITHUB_OUTPUT | |
- name: Upload Firmware To Artifact | |
if: steps.organize.outputs.status == 'success' && !cancelled() | |
uses: actions/upload-artifact@main | |
with: | |
name: ${{ env.SOURCE_REPO }}-${{ matrix.ARCHITECTURE }}-firmware-${{ env.DEVICE_TARGET }}-${{ env.DEVICE_SUBTARGET }}-${{ env.FILE_DATE }} | |
path: ${{ env.FIRMWARE_PATH }} | |
- name: Upload Firmware To CowTransfer | |
id: cowtransfer | |
if: steps.organize.outputs.status == 'success' && env.UPLOAD_COWTRANSFER == 'true' && !cancelled() | |
run: | | |
curl -fsSL git.io/file-transfer | sh | |
./transfer cow --block 2621440 -s -p 64 --no-progress ${FIRMWARE_PATH} 2>&1 | tee cowtransfer.log | |
echo "::warning file=cowtransfer.com::$(cat cowtransfer.log | grep https)" | |
echo "url=$(cat cowtransfer.log | grep https | cut -f3 -d" ")" >> $GITHUB_OUTPUT | |
- name: Upload Firmware To WeTransfer | |
id: wetransfer | |
if: steps.organize.outputs.status == 'success' && env.UPLOAD_WETRANSFER == 'true' && !cancelled() | |
run: | | |
curl -fsSL git.io/file-transfer | sh | |
./transfer wet -s -p 16 --no-progress ${FIRMWARE_PATH} 2>&1 | tee wetransfer.log | |
echo "::warning file=wetransfer.com::$(cat wetransfer.log | grep https)" | |
echo "url=$(cat wetransfer.log | grep https | cut -f3 -d" ")" >> $GITHUB_OUTPUT | |
- name: Generate Release Tag | |
id: tag | |
if: env.UPLOAD_RELEASE == 'true' && !cancelled() | |
run: | | |
echo "COMMIT_HASH IS ${{ env.COMMIT_HASH }}" | |
echo "release_tag=istoreos-${{ matrix.ARCHITECTURE }}-${{ env.FILE_DATE }}" >> $GITHUB_OUTPUT | |
echo "release_name=R${{ env.DATE }} for ${{ matrix.ARCHITECTURE }}" >> $GITHUB_OUTPUT | |
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 " | |
**This is iStoreOS Firmware for ${{ matrix.ARCHITECTURE }}** | |
### 📖 固件信息 | |
- ⏱️ 编译时间: $(date +"%Y年%m月%d日%H时%M分") | |
- 💻 平台架构: ${{ env.DEVICE_TARGET }}-${{ env.DEVICE_SUBTARGET }} | |
- ⚽ 固件源码: ${{ env.REPO_URL }} | |
- 💝 源码分支: ${{ matrix.REPO_BRANCH }} | |
- 🚀 内核版本: ${{ env.KERNEL }} | |
- 🌐 默认地址: 192.168.1.254 | |
- 🧑 默认账号: root | |
- 🔑 默认密码: password | |
### 🧊 固件版本 | |
- 固件编译前最后一次➦[主源码](${{ env.REPO_URL }})更新记录 | |
- 👤 ${{ env.COMMIT_AUTHOR }} | |
- ⏱️ ${{ env.COMMIT_DATE }} | |
- 📒 ${{ env.COMMIT_MESSAGE }} | |
- 🏷 ${{ env.COMMIT_HASH }}" >> release.txt | |
echo "status=success" >> $GITHUB_OUTPUT | |
- name: Upload Firmware To Release | |
uses: softprops/action-gh-release@v1 | |
if: steps.tag.outputs.status == 'success' && !cancelled() | |
env: | |
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
with: | |
name: ${{ steps.tag.outputs.release_name }} | |
tag_name: ${{ steps.tag.outputs.release_tag }} | |
body_path: release.txt | |
files: ${{ env.FIRMWARE_PATH }}/* | |
# - name: Upload Firmware To Release | |
# if: steps.compile.outputs.status == 'success' && env.FIRMWARE_RELEASE == 'true' | |
# uses: ncipollo/release-action@v1 | |
# with: | |
# name: ${{ steps.tag.outputs.release_name }} | |
# allowUpdates: true | |
# tag: ${{ steps.tag.outputs.release_tag }} | |
# token: ${{ secrets.ACCESS_TOKEN }} | |
# artifacts: ${{ env.FIRMWARE_PATH }}/* | |
# body: release.txt | |
- name: Delete Workflow Runs | |
uses: GitRML/delete-workflow-runs@main | |
with: | |
token: ${{ secrets.ACCESS_TOKEN }} | |
repository: ${{ github.repository }} | |
retain_days: 1 | |
keep_minimum_runs: 3 | |
- name: Remove Old Releases | |
uses: dev-drprasad/[email protected] | |
if: env.UPLOAD_RELEASE == 'true' && !cancelled() | |
with: | |
keep_latest: 15 | |
delete_tags: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
# Delete: | |
# runs-on: ${{ matrix.os }} | |
# permissions: | |
# actions: write | |
# steps: | |
# - name: Delete workflow runs | |
# uses: Mattraks/delete-workflow-runs@v2 | |
# with: | |
# token: ${{ secrets.ACCESS_TOKEN }} | |
# repository: ${{ github.repository }} | |
# retain_days: 1 | |
# keep_minimum_runs: 3 | |
# delete_workflow_pattern: ${{ github.event.inputs.delete_workflow_pattern }} | |
# delete_workflow_by_state_pattern: ${{ github.event.inputs.delete_workflow_by_state_pattern }} | |
# delete_run_by_conclusion_pattern: >- | |
# ${{ | |
# startsWith(github.event.inputs.delete_run_by_conclusion_pattern, 'Unsuccessful:') | |
# && 'action_required,cancelled,failure,skipped' | |
# || github.event.inputs.delete_run_by_conclusion_pattern | |
# }} | |
# dry_run: ${{ github.event.inputs.dry_run }} |