Skip to content

Build SSR

Build SSR #538

Workflow file for this run

name: Build SSR
on:
schedule:
- cron: 0 17 * * *
repository_dispatch:
workflow_dispatch:
inputs:
ssh:
description: 'SSH connection to Actions'
required: false
default: false
type: boolean
env:
UPLOAD_FIRMWARE: false
UPLOAD_RELEASE: true
TZ: Asia/Shanghai
jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@main
- name: Initialization environment
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get update -y
sudo apt-get full-upgrade -y
sudo apt-get install -y expect ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential bzip2 ccache cmake cpio curl device-tree-compiler ecj fastjar flex gawk gettext gcc-multilib g++-multilib git git-core gperf haveged help2man intltool lib32gcc1 libc6-dev-i386 libelf-dev libglib2.0-dev libgmp3-dev libltdl-dev libmpc-dev libmpfr-dev libncurses5-dev libncurses5-dev libreadline-dev libssl-dev libtool libz-dev lrzsz mkisofs msmtp nano ninja-build p7zip p7zip-full patch pkgconf python2.7 python3 python3-pip python3-ply python-docutils qemu-utils re2c rsync scons squashfs-tools subversion swig texinfo uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev
echo "update完成"
- name: Rclone-Install
run: wget 'https://raw.githubusercontent.com/wekingchen/my-file/master/rclone/rclone.zip' --no-check-certificate && sudo unzip rclone.zip && sudo chmod a+x rclone && sudo rm -f rclone.zip
- name: Rclone-Config
env:
RCLONE_CONFIG: ${{ secrets.RCLONE_CONFIG }}
run: |
# 写配置文件
mkdir -p ~/.config/rclone/
cat << EOF > ~/.config/rclone/rclone.conf
$RCLONE_CONFIG
EOF
- name: Create new user
run: |
sudo adduser "builder" <<EOF
12345
12345
EOF
echo "新建用户完成"
expect -c "
spawn su - builder
expect \":\"
send \"12345\r\"
interact
"
echo "用户切换成功"
- name: Clone source code
run: |
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git clone https://github.com/wekingchen/gl-infra-builder.git
echo "源码抓取完毕"
cd gl-infra-builder
python3 setup.py -c config-siflower-18.x.yml
echo "config-siflower-18.x.yml完毕"
cd openwrt-18.06/siflower/openwrt-18.06
./scripts/gen_config.py target_siflower_gl-sft1200
echo "target_siflower_gl-sft1200完毕"
# 使用旧版1.80.0的boost
rm -rf feeds/packages/libs/boost
wget 'https://github.com/${{ GITHUB.REPOSITORY }}/raw/main/myfiles/package.zip' --no-check-certificate && unzip -o package.zip && rm -f package.zip
sed -i "/helloworld/d" "feeds.conf.default"
echo "src-git helloworld https://github.com/fw876/helloworld.git" >> "feeds.conf.default"
echo "helloworld完毕"
./scripts/feeds update helloworld
./scripts/feeds install -a -f -p helloworld
echo "feeds更新完毕"
rm -rf .config
echo "删除配置完毕"
wget https://github.com/${{ GITHUB.REPOSITORY }}/raw/main/ssr/.config
echo "配置抓取完毕"
- name: Setup Debug Session
if: ${{ inputs.ssh }}
uses: csexton/debugger-action@master
- name: Build source code
run: |
cd gl-infra-builder/openwrt-18.06/siflower/openwrt-18.06
make -j8 download V=s
echo "下载完毕"
make -j1 V=s
echo "::set-output name=status::success"
grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/' > DEVICE_NAME
[ -s DEVICE_NAME ] && echo "DEVICE_NAME=_$(cat DEVICE_NAME)" >> $GITHUB_ENV
echo "FILE_DATE=_$(date +"%Y%m%d%H%M")" >> $GITHUB_ENV
- name: Rclone-Run
run: |
# Rclone-Run
# 延迟函数
delay()
{
random_time=$(($RANDOM % $1))
echo "等待 ${random_time} 分钟后开始同步"
for((i=1;i<=${random_time};i++));
do
echo "倒计时 $[${random_time}-$i] 分钟"
sleep 1m
done
}
# 随机延迟0~15分钟后再进行操作,可自行设置时间
delay 1
pwd
Date=$(date +"%Y%m%d")
./rclone sync -v /home/runner/work/Actions-SFT1200-OpenWrt/Actions-SFT1200-OpenWrt/gl-infra-builder/openwrt-18.06/siflower/openwrt-18.06/bin/ seafile:/ssr/$Date/
echo "SeaFile已上传 $Date 文件夹完毕"
DELTIME=`date -d "7 days ago" +%Y%m%d`
./rclone purge seafile:/ssr/$DELTIME
echo "SeaFile已删除旧文件夹 $DELTIME"
- name: Check space usage
if: (!cancelled())
run: df -hT
- name: Upload bin directory
uses: actions/upload-artifact@main
if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true'
with:
name: OpenWrt_bin${{ env.DEVICE_NAME }}${{ env.FILE_DATE }}
path: gl-infra-builder/openwrt-18.06/siflower/openwrt-18.06/bin
- name: Organize files
id: organize
if: env.UPLOAD_FIRMWARE == 'true' && !cancelled()
run: |
cd "/home/runner/work/Actions-SFT1200-OpenWrt/Actions-SFT1200-OpenWrt/gl-infra-builder/openwrt-18.06/siflower/openwrt-18.06/bin/"
echo "FIRMWARE=$PWD" >> $GITHUB_ENV
echo "::set-output name=status::success"
- name: Upload firmware directory
uses: actions/upload-artifact@main
if: steps.organize.outputs.status == 'success' && !cancelled()
with:
name: OpenWrt_firmware${{ env.DEVICE_NAME }}${{ env.FILE_DATE }}
path: ${{ env.FIRMWARE }}
- name: Generate release tag
id: tag
if: env.UPLOAD_RELEASE == 'true' && !cancelled()
run: |
echo "::set-output name=release_tag::$(date +"%Y.%m.%d-%H%M"-ssr)"
touch release.txt
echo "::set-output name=status::success"
- name: Upload firmware to release
uses: softprops/action-gh-release@v1
if: steps.tag.outputs.status == 'success' && !cancelled()
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}
with:
tag_name: ${{ steps.tag.outputs.release_tag }}
body_path: release.txt
files: /home/runner/work/Actions-SFT1200-OpenWrt/Actions-SFT1200-OpenWrt/gl-infra-builder/openwrt-18.06/siflower/openwrt-18.06/bin/targets/siflower/openwrt-*squashfs*
- name: Delete workflow runs
uses: GitRML/delete-workflow-runs@main
with:
retain_days: 1
keep_minimum_runs: 10
- name: Remove old Releases
uses: dev-drprasad/[email protected]
if: env.UPLOAD_RELEASE == 'true' && !cancelled()
with:
keep_latest: 3
delete_tags: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}