Skip to content

Build iStore OS

Build iStore OS #586

name: Build iStore OS
on:
repository_dispatch:
workflow_dispatch:
inputs:
ssh:
description: 'SSH connection to Actions'
required: false
default: 'false'
schedule:
- cron: 0 16 * * *
env:
REPO_URL: https://github.com/istoreos/istoreos
# REPO_BRANCH: main
FEEDS_CONF: feeds.conf
CONFIG_FILE: .config
DIY_P1_SH: scripts/diy-part1.sh
DIY_P2_SH: scripts/diy-part2.sh
UPLOAD_BIN_DIR: true
UPLOAD_FIRMWARE: true
UPLOAD_RELEASE: true
TZ: Asia/Shanghai
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
REPO_BRANCH:
# - main
- istoreos-22.03
# - istoreos-23.05
ARCHITECTURE:
- rk33xx
- rk35xx
- x86
os:
- ubuntu-22.04
fail-fast: false
steps:
- name: 准备完成
uses: actions/checkout@main
- name: 检查服务器配置
run: |
echo "若分配的服务器性能不足,务必及时取消,重新运行!"
echo -e "------------------------------- CPU信息 -------------------------------\n"
echo "CPU物理数量:$(cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l)"
echo -e "CPU核心及版本信息: $(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c) \n"
echo -e "------------------------------- 内存信息 -------------------------------\n"
echo "已安装内存详细信息: "
sudo lshw -short -C memory | grep GiB
echo -e "\n"
echo -e "------------------------------- 磁盘信息 -------------------------------\n"
echo -e "磁盘数量: $(ls /dev/sd* | grep -v [1-9] | wc -l) \n"
echo "------------------------------- 磁盘详情 -------------------------------\n"
df -Th
- name: 安装 Go 1.21.1
uses: actions/setup-go@v1
with:
go-version: 1.21.1
- name: 初始化编译环境
env:
DEBIAN_FRONTEND: noninteractive
run: |
echo "------------------------------- 更新并安装依赖 -------------------------------"
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 $(cat $GITHUB_WORKSPACE/depends/${{ matrix.os }})
wget https://bootstrap.pypa.io/pip/3.6/get-pip.py
sudo python3 get-pip.py
sudo rm -rf get-pip.py
sudo pip install pyelftools
echo "------------------------------- 清理Docker镜像和软件 -------------------------------"
docker image prune -a -f
sudo -E apt-get -y purge azure-cli ghc* zulu* llvm* firefox google* dotnet* powershell openjdk* mysql* php* mongodb* dotnet* moby* snapd* android* || true
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
echo "------------------------------- 设置工作目录及时区 -------------------------------"
sudo timedatectl set-timezone "$TZ"
sudo mkdir -p /workdir
sudo chown $USER:$GROUPS /workdir
- name: 克隆源码
working-directory: /workdir
run: |
df -hT $PWD
git clone $REPO_URL -b ${{ matrix.REPO_BRANCH }} openwrt
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt
- name: 缓存构建动作
uses: klever1988/cachewrtbuild@main
with:
ccache: 'true'
mixkey: ${{ matrix.os }}-${{ matrix.ARCHITECTURE }}-${{ matrix.REPO_BRANCH }}
prefix: ${{ github.workspace }}/openwrt
- name: 加载自定义 feeds
env:
FEEDS_CONF_PATH: ${{ matrix.ARCHITECTURE }}/${{ env.FEEDS_CONF }}
run: |
[ -e $FEEDS_CONF_PATH ] && mv $FEEDS_CONF_PATH openwrt/$FEEDS_CONF
chmod +x $DIY_P1_SH
cd openwrt
$GITHUB_WORKSPACE/$DIY_P1_SH
- name: 更新 feeds
run: cd openwrt && ./scripts/feeds update -a
- name: 安装 feeds
run: cd openwrt && ./scripts/feeds install -a
- name: 加载自定义配置
env:
CONFIG_FILE_PATH: ${{ matrix.ARCHITECTURE }}/${{ env.CONFIG_FILE }}
run: |
[ -e files ] && mv files openwrt/files
[ -e $CONFIG_FILE_PATH ] && mv $CONFIG_FILE_PATH openwrt/$CONFIG_FILE
chmod +x $DIY_P2_SH
cd openwrt
$GITHUB_WORKSPACE/$DIY_P2_SH ${{ matrix.ARCHITECTURE }}
- name: SSH 连接到 Actions
uses: P3TERX/[email protected]
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: 下载软件包
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: 编译固件
id: compile
run: |
cd openwrt
echo -e "$(nproc) thread compile"
make -j$(nproc) || make -j1 || make -j1 V=s
echo "FILE_DATE=_$(date +"%Y%m%d%H%M")" >> $GITHUB_ENV
echo "::set-output name=status::success"
- name: 检查磁盘空间
if: (!cancelled())
run: df -hT
- name: 上传 bin 文件夹
uses: actions/upload-artifact@main
if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true'
with:
name: OpenWrt_bin${{ env.FILE_DATE }}
path: openwrt/bin
- name: 整理固件文件
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: 上传固件目录
uses: actions/upload-artifact@main
if: steps.organize.outputs.status == 'success' && !cancelled()
with:
name: OpenWrt_firmware${{ env.FILE_DATE }}
path: ${{ env.FIRMWARE }}
- name: 生成发布标签
id: tag
if: steps.compile.outputs.status == 'success' && env.UPLOAD_RELEASE == 'true' && !cancelled()
run: |
echo "::set-output name=release_tag::${{ matrix.ARCHITECTURE }}"
touch release.txt
echo "
💻 架构: ${{ matrix.ARCHITECTURE }}
📂 源码: ${{ env.REPO_URL }}
🌳 分支: ${{ matrix.REPO_BRANCH }}
⏱️ 编译时间: $(date +"%Y年%m月%d日%H时%M分")
🌐 管理地址: 192.168.10.1
👤 用户名: root
🔒 密码: password " >> release.txt
echo "::set-output name=status::success"
- name: 自动发布固件到 Releases
uses: softprops/action-gh-release@v1
if: steps.tag.outputs.status == 'success' && !cancelled()
with:
tag_name: ${{ steps.tag.outputs.release_tag }}
body_path: release.txt
files: ${{ env.FIRMWARE }}/*
- name: 删除运行记录
uses: GitRML/delete-workflow-runs@main
with:
retain_days: 1
keep_minimum_runs: 3
token: ${{ env.GITHUB_TOKEN }}
- name: 删除自动发布的旧固件
uses: dev-drprasad/[email protected]
if: env.UPLOAD_RELEASE == 'true' && !cancelled()
with:
keep_latest: 6
delete_tags: true