2021-03-17 14:08:02 +08:00

217 lines
9.3 KiB
YAML

name: build
on:
repository_dispatch:
workflow_dispatch:
inputs:
device:
description: 'select device to build'
default: 'r2s'
required: false
jobs:
build:
name: ${{ github.event.client_payload.device || github.event.inputs.device }}
runs-on: ubuntu-18.04
env:
DEVICE: ${{ github.event.client_payload.device || github.event.inputs.device }}
TG: ${{ secrets.TELEGRAM_BOT_TOKEN }}
DEPLOY_SSHKEY: ${{ secrets.SSH_KEY }}
if: github.event.repository.owner.id == github.event.sender.id
steps:
- name: Space cleanup
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo sysctl vm.swappiness=0
nohup sudo rm -rf /usr/share/dotnet /usr/local/lib/android/sdk &
sudo -E apt update
nohup sudo -E apt -y --no-install-recommends install jq build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core gcc-multilib g++-multilib p7zip p7zip-full msmtp libssl-dev texinfo libreadline-dev libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint ccache curl wget vim nano python python3 python-pip python3-pip python-ply python3-ply haveged lrzsz device-tree-compiler scons antlr3 gperf intltool rsync swig &
- uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Checkout
run: |
cd
sudo curl -sL https://raw.githubusercontent.com/klever1988/nanopi-openwrt/zstd-bin/zstd | sudo tee /usr/bin/zstd > /dev/null
for i in {1..10}
do
curl -sL --fail https://github.com/klever1988/sshactions/releases/download/cache/lede.$DEVICE.img.zst.0$i || break
done | zstdmt -d -o lede.img || (truncate -s 10g lede.img && mkfs.btrfs -M lede.img)
LOOP_DEVICE=$(losetup -f) && echo "LOOP_DEVICE=$LOOP_DEVICE" >> $GITHUB_ENV
sudo losetup -P --direct-io $LOOP_DEVICE lede.img
mkdir lede && sudo mount -o nossd,compress=zstd $LOOP_DEVICE lede
if [ -d 'lede/.git' ]; then
cd lede && git config --local user.email "action@github.com" && git config --local user.name "GitHub Action"
git remote set-branches --add origin openwrt-18.06
git fetch && git reset --hard origin/openwrt-18.06-k5.4 && git merge --commit origin/openwrt-18.06
else
sudo chown $USER:$(id -gn) lede && (cd lede && git init && git remote add -t openwrt-18.06-k5.4 -f origin https://github.com/immortalwrt/immortalwrt && git checkout openwrt-18.06-k5.4)
fi
- name: Update feeds and packages
run: |
cd ~/lede
if [ -d 'feeds' ]; then
pushd feeds/packages; git restore .; popd
pushd feeds/luci; git restore .; popd
fi
./scripts/feeds update -a
./scripts/feeds install -a
. $GITHUB_WORKSPACE/patches.sh
. $GITHUB_WORKSPACE/merge_packages.sh
- name: Custom configure file
run: |
cd ~/lede
cat $GITHUB_WORKSPACE/$DEVICE.config.seed > .config
- name: Compile firmware
run: |
cd ~/lede
if [ ! -d build_dir ]; then
if [[ $DEVICE =~ ('r2s'|'r4s') ]]; then
sdk_src='https://downloads.openwrt.org/snapshots/targets/rockchip/armv8/openwrt-sdk-rockchip-armv8_gcc-8.4.0_musl.Linux-x86_64.tar.xz'
elif [[ $DEVICE == 'r1s' ]]; then
sdk_src='https://downloads.openwrt.org/snapshots/targets/sunxi/cortexa53/openwrt-sdk-sunxi-cortexa53_gcc-8.4.0_musl.Linux-x86_64.tar.xz'
fi
mkdir sdk && wget -qO- $sdk_src | tar -xJf - -C sdk
rm -rf build_dir staging_dir; mv sdk/*/build_dir ./ && rsync -a --ignore-existing sdk/*/staging_dir/ ./staging_dir/
rm -rf sdk
fi
sed -i '/\(tools\|toolchain\)\/Makefile/d' Makefile
echo -e '# CONFIG_SIGNED_PACKAGES is not set\n' >> .config
#grep -l -r --include=\Makefile '(STAGING_DIR_HOST)/bin/upx ' | xargs -n1 -i sed -i '/upx/d' {}
make defconfig
while true; do make download -j && break || true; done
while true; do make package/download -j && break || true; done
make package/feeds/packages/ttyd/clean
make -j$(($(nproc) + 1)) || make V=sc
echo "======================="
echo "Space usage:"
echo "======================="
df -h
echo "======================="
du -h --max-depth=1 ./ --exclude=build_dir --exclude=bin
du -h --max-depth=1 ./build_dir
du -h --max-depth=1 ./bin
- name: Prepare artifact
run: |
cd
mkdir -p ./artifact/firmware
mkdir -p ./artifact/package
mkdir -p ./artifact/buildinfo
mkdir -p ./release
cd lede
cp -a bin tmp ../
rm -rf $(find ./bin/targets/ -type d -name "packages")
cp -rf $(find ./bin/targets/ -type f) ../artifact/firmware/
cp -rf $(find ./bin/packages/ -type f -name "*.ipk") ../artifact/package/
cp -rf $(find ./bin/targets/ -type f -name "*.buildinfo" -o -name "*.manifest") ../artifact/buildinfo/
cp $(ls -1 ../artifact/firmware/*img*) ../release/$DEVICE.img.gz
pushd ../release/ && md5sum $DEVICE.img.gz > md5sum.txt && popd
echo "strDate=$(TZ=UTC-8 date +%Y-%m-%d)" >> $GITHUB_ENV
echo "strDevice=$(echo $DEVICE | awk '{print toupper($0)}')" >> $GITHUB_ENV
rm -rf bin tmp
cd ..
mv artifact release $GITHUB_WORKSPACE
- name: Deliver buildinfo
uses: actions/upload-artifact@v2
with:
name: OpenWrt_buildinfo
path: ./artifact/buildinfo/
- name: Deliver package
uses: actions/upload-artifact@v2
with:
name: OpenWrt_package
path: ./artifact/package/
- name: Deliver firmware
uses: actions/upload-artifact@v2
with:
name: OpenWrt_firmware
path: ./artifact/firmware/
- name: Upload release asset
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./release/*
tag: ${{env.DEVICE}}-${{env.strDate}}
file_glob: true
overwrite: true
release_name: ${{env.strDevice}} ${{env.strDate}} 自动发布
- name: Save cache state
if: env.TG
run: |
cd
sleep 120
sudo umount lede
sudo losetup -d $LOOP_DEVICE
export AUTH="Authorization: token ${{ secrets.SEC_TOKEN }}"
export cache_path='github.com/repos/klever1988/sshactions/releases'
export cache_repo_id='39020554'
ret=$(curl -sH "$AUTH" "https://api.$cache_path/tags/cache")
echo $ret | jq -r '.assets[] | select(.name | contains ("'$DEVICE'.img")).id' | \
xargs -n1 -i curl -X DELETE -H "$AUTH" "https://api.$cache_path/assets/{}"
zstdmt -c --adapt --long lede.img | parallel --wc --block 1.99G --pipe \
'curl -s --data-binary @- -H "$AUTH" -H "Content-Type: application/octet-stream" https://uploads.$cache_path/$cache_repo_id/assets?name=lede.'$DEVICE'.img.zst.0{#} > /dev/null'
- name: Debug via tmate
uses: P3TERX/ssh2actions@main
if: ${{ failure() && env.TG }}
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
- name: Send tg notification
uses: appleboy/telegram-action@master
if: env.TG
with:
to: ${{ secrets.TELEGRAM_CHAT_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
args: The ${{env.DEVICE}} build ran completed at ${{job.status}}.
- name: Build and deploy packages
if: env.DEPLOY_SSHKEY
run: |
cd
truncate -s +10G lede.img
sudo losetup -P --direct-io $LOOP_DEVICE lede.img
sudo mount -o nossd,compress=zstd $LOOP_DEVICE lede
sudo btrfs filesystem resize max lede/
mv bin tmp lede/
cd lede
find package/ -type d -name luci-app-* | rev | cut -d'/' -f1 | rev | sort | xargs -n1 -i echo CONFIG_PACKAGE_{}=y >> .config
make defconfig
make download -j
make target/linux/compile -j$(($(nproc) + 1))
make package/compile -j$(($(nproc) + 1)) IGNORE_ERRORS=y
make package/index
sed "s/\-[a-z0-9]\{32\})/)/" bin/targets/*/*/packages/Packages bin/targets/*/*/packages/Packages.manifest
gzip -f bin/targets/*/*/packages/Packages
mkdir -p ~/.ssh; echo ${{env.DEPLOY_SSHKEY}} | base64 -d > ~/.ssh/id_ed25519; chmod 600 ~/.ssh/id_ed25519
rsync -ach --progress -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" \
bin/packages/*/* root@direct.imgxxx.net:/usr/share/caddy/$DEVICE/
rsync -ach --progress -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" \
bin/targets/*/*/packages/ root@direct.imgxxx.net:/usr/share/caddy/$DEVICE/core/
- name: Debug via tmate
uses: P3TERX/ssh2actions@main
if: ${{ failure() && env.TG }}
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}