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-latest if: github.event.repository.owner.id == github.event.sender.id steps: - name: Space cleanup env: DEBIAN_FRONTEND: noninteractive run: | sudo sysctl vm.swappiness=0 sudo rm -rf /usr/share/dotnet #/usr/local/lib/android/sdk sudo -E apt update sudo -E apt -y --no-upgrade --no-install-recommends install jq zstd secure-delete 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: | sudo curl https://raw.githubusercontent.com/klever1988/nanopi-openwrt/zstd-bin/zstd | sudo tee /usr/bin/zstd > /dev/null for i in {1..6} do curl -s -L --fail https://github.com/klever1988/sshactions/releases/download/cache/lede.${{ github.event.client_payload.device || github.event.inputs.device }}.img.zst.0$i || break done | zstdmt -d -o lede.img || (truncate -s 40g lede.img && mkfs.xfs lede.img) LOOP_DEVICE=$(losetup -f) && echo $LOOP_DEVICE > LOOP_DEVICE sudo losetup -P --direct-io $LOOP_DEVICE lede.img mkdir lede && sudo mount $LOOP_DEVICE lede && sudo chown -R $USER:$USER lede [ ! -e lede/.git ] && (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) cd lede && git config --local user.email "action@github.com" && git config --local user.name "GitHub Action" && git pull --ff -X theirs - name: Update feeds and packages run: | cd lede/ git clone --depth=1 https://github.com/destan19/OpenAppFilter.git && rm -rf package/OpenAppFilter && mv OpenAppFilter package/ git clone --depth=1 -b 18.06 https://github.com/jerrykuku/luci-theme-argon.git && rm -rf package/lean/luci-theme-argon && mv luci-theme-argon package/lean/ ./scripts/feeds update -a ./scripts/feeds install -a - name: Custom configure file run: | cd lede rm -f .config* cat ../${{ github.event.client_payload.device || github.event.inputs.device }}.config.seed > .config sed -i 's/^[ \t]*//g' .config echo ' # CONFIG_v2ray-plugin_INCLUDE_GOPROXY is not set # CONFIG_XRAY_CORE_COMPRESS_GOPROXY is not set # CONFIG_UnblockNeteaseMusicGo_INCLUDE_GOPROXY is not set ' >> .config make defconfig && cat .config - name: Compile firmware run: | cd lede while true; do make download -j && break || true; done make -j$(($(nproc) + 1)) -s || (make clean && make -j1 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: | mkdir -p ./artifact/firmware mkdir -p ./artifact/package mkdir -p ./artifact/buildinfo mkdir -p ./release cd lede 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/${{ github.event.client_payload.device || github.event.inputs.device }}.img.gz pushd ../release/ && md5sum ${{ github.event.client_payload.device || github.event.inputs.device }}.img.gz > md5sum.txt && popd echo "strDate=$(date +%Y-%m-%d)" >> $GITHUB_ENV echo "strDevice=$(echo ${{ github.event.client_payload.device || github.event.inputs.device }} | awk '{print toupper($0)}')" >> $GITHUB_ENV rm -rf bin/ tmp/ cd .. rm -f *zst* sudo umount lede LOOP_DEVICE=$(cat LOOP_DEVICE) sudo losetup -d $LOOP_DEVICE #zstdmt -c lede.img | split -d -b 2000m - lede.${{ github.event.client_payload.device || github.event.inputs.device }}.img.zst. #ls -l *zst* - 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: ${{ github.event.client_payload.device || github.event.inputs.device }}-${{ env.strDate }} file_glob: true overwrite: true release_name: ${{ env.strDevice }} ${{ env.strDate }} 自动发布 - name: Save cache state run: | 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 ("'${{ github.event.client_payload.device || github.event.inputs.device }}'")).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.'${{ github.event.client_payload.device || github.event.inputs.device }}'.img.zst.0{#} > /dev/null' - name: Debug via tmate uses: P3TERX/ssh2actions@main if: ${{ failure() }} 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: always() with: to: ${{ secrets.TELEGRAM_CHAT_ID }} token: ${{ secrets.TELEGRAM_BOT_TOKEN }} args: The ${{ github.event.client_payload.device || github.event.inputs.device }} build ran completed at ${{ job.status }}.