|
| 1 | +# |
| 2 | +# Copyright (c) 2019-2020 P3TERX <https://p3terx.com> |
| 3 | +# |
| 4 | +# This is free software, licensed under the MIT License. |
| 5 | +# See /LICENSE for more information. |
| 6 | +# |
| 7 | +# https://github.com/P3TERX/Actions-OpenWrt |
| 8 | +# Description: Build OpenWrt using GitHub Actions |
| 9 | +# |
| 10 | + |
| 11 | +name: Build OpenWrt |
| 12 | + |
| 13 | +on: |
| 14 | + repository_dispatch: |
| 15 | + workflow_dispatch: |
| 16 | + inputs: |
| 17 | + ssh: |
| 18 | + description: 'SSH connection to Actions' |
| 19 | + required: false |
| 20 | + default: 'false' |
| 21 | + |
| 22 | +env: |
| 23 | + REPO_URL: https://github.com/coolsnowwolf/lede |
| 24 | + REPO_BRANCH: master |
| 25 | + FEEDS_CONF: feeds.conf.default |
| 26 | + CONFIG_FILE: .config |
| 27 | + DIY_P1_SH: diy-part1.sh |
| 28 | + DIY_P2_SH: diy-part2.sh |
| 29 | + UPLOAD_BIN_DIR: false |
| 30 | + UPLOAD_FIRMWARE: true |
| 31 | + UPLOAD_COWTRANSFER: false |
| 32 | + UPLOAD_WETRANSFER: false |
| 33 | + UPLOAD_RELEASE: true |
| 34 | + TZ: Asia/Shanghai |
| 35 | + |
| 36 | +jobs: |
| 37 | + build: |
| 38 | + runs-on: ubuntu-20.04 |
| 39 | + |
| 40 | + steps: |
| 41 | + - name: Checkout |
| 42 | + uses: actions/checkout@main |
| 43 | + with: |
| 44 | + fetch-depth: 0 |
| 45 | + |
| 46 | + - name: Initialization environment |
| 47 | + env: |
| 48 | + DEBIAN_FRONTEND: noninteractive |
| 49 | + run: | |
| 50 | + sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc |
| 51 | + sudo -E apt-get -qq update |
| 52 | + sudo -E apt-get -qq install $(curl -fsSL git.io/depends-ubuntu-2004) |
| 53 | + sudo -E apt-get -qq autoremove --purge |
| 54 | + sudo -E apt-get -qq clean |
| 55 | + sudo timedatectl set-timezone "$TZ" |
| 56 | + sudo mkdir -p /workdir |
| 57 | + sudo chown $USER:$GROUPS /workdir |
| 58 | + - name: Clone source code |
| 59 | + working-directory: /workdir |
| 60 | + run: | |
| 61 | + df -hT $PWD |
| 62 | + git clone $REPO_URL -b $REPO_BRANCH openwrt |
| 63 | + ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt |
| 64 | + - name: cache |
| 65 | + uses: klever1988/cachewrtbuild@main |
| 66 | + with: |
| 67 | + ccache: 'true' |
| 68 | + prefix: ${{ github.workspace }}/openwrt |
| 69 | + |
| 70 | + - name: Load custom feeds |
| 71 | + run: | |
| 72 | + [ -e $FEEDS_CONF ] && mv $FEEDS_CONF openwrt/feeds.conf.default |
| 73 | + chmod +x $DIY_P1_SH |
| 74 | + cd openwrt |
| 75 | + $GITHUB_WORKSPACE/$DIY_P1_SH |
| 76 | + - name: Update feeds |
| 77 | + run: cd openwrt && ./scripts/feeds update -a |
| 78 | + |
| 79 | + - name: Install feeds |
| 80 | + run: cd openwrt && ./scripts/feeds install -a |
| 81 | + |
| 82 | + - name: Load custom configuration |
| 83 | + run: | |
| 84 | + [ -e files ] && mv files openwrt/files |
| 85 | + [ -e $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config |
| 86 | + chmod +x $DIY_P2_SH |
| 87 | + cd openwrt |
| 88 | + $GITHUB_WORKSPACE/$DIY_P2_SH |
| 89 | + - name: SSH connection to Actions |
| 90 | + |
| 91 | + if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh') |
| 92 | + env: |
| 93 | + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} |
| 94 | + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} |
| 95 | + |
| 96 | + - name: Download package |
| 97 | + id: package |
| 98 | + run: | |
| 99 | + cd openwrt |
| 100 | + echo -e 'CONFIG_DEVEL=y\nCONFIG_CCACHE=y' >> .config |
| 101 | + make defconfig |
| 102 | + make download -j8 |
| 103 | + find dl -size -1024c -exec ls -l {} \; |
| 104 | + find dl -size -1024c -exec rm -f {} \; |
| 105 | + - name: Compile the firmware |
| 106 | + id: compile |
| 107 | + run: | |
| 108 | + cd openwrt |
| 109 | + echo -e "$(nproc) thread compile" |
| 110 | + make -j$(nproc) || make -j1 || make -j1 V=s |
| 111 | + echo "status=success" >> $GITHUB_OUTPUT |
| 112 | + grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/' > DEVICE_NAME |
| 113 | + [ -s DEVICE_NAME ] && echo "DEVICE_NAME=_$(cat DEVICE_NAME)" >> $GITHUB_ENV |
| 114 | + echo "FILE_DATE=_$(date +"%Y%m%d%H%M")" >> $GITHUB_ENV |
| 115 | + - name: Check space usage |
| 116 | + if: (!cancelled()) |
| 117 | + run: df -hT |
| 118 | + |
| 119 | + - name: Upload bin directory |
| 120 | + uses: actions/upload-artifact@main |
| 121 | + if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true' |
| 122 | + with: |
| 123 | + name: OpenWrt_bin${{ env.DEVICE_NAME }}${{ env.FILE_DATE }} |
| 124 | + path: openwrt/bin |
| 125 | + |
| 126 | + - name: Organize files |
| 127 | + id: organize |
| 128 | + if: env.UPLOAD_FIRMWARE == 'true' && !cancelled() |
| 129 | + run: | |
| 130 | + cd openwrt/bin/targets/*/* |
| 131 | + rm -rf packages |
| 132 | + echo "FIRMWARE=$PWD" >> $GITHUB_ENV |
| 133 | + echo "status=success" >> $GITHUB_OUTPUT |
| 134 | + - name: Upload firmware directory |
| 135 | + uses: actions/upload-artifact@main |
| 136 | + if: steps.organize.outputs.status == 'success' && !cancelled() |
| 137 | + with: |
| 138 | + name: OpenWrt_firmware${{ env.DEVICE_NAME }}${{ env.FILE_DATE }} |
| 139 | + path: ${{ env.FIRMWARE }} |
| 140 | + |
| 141 | + - name: Upload firmware to cowtransfer |
| 142 | + id: cowtransfer |
| 143 | + if: steps.organize.outputs.status == 'success' && env.UPLOAD_COWTRANSFER == 'true' && !cancelled() |
| 144 | + run: | |
| 145 | + curl -fsSL git.io/file-transfer | sh |
| 146 | + ./transfer cow --block 2621440 -s -p 64 --no-progress ${FIRMWARE} 2>&1 | tee cowtransfer.log |
| 147 | + echo "::warning file=cowtransfer.com::$(cat cowtransfer.log | grep https)" |
| 148 | + echo "url=$(cat cowtransfer.log | grep https | cut -f3 -d" ")" >> $GITHUB_OUTPUT |
| 149 | + - name: Upload firmware to WeTransfer |
| 150 | + id: wetransfer |
| 151 | + if: steps.organize.outputs.status == 'success' && env.UPLOAD_WETRANSFER == 'true' && !cancelled() |
| 152 | + run: | |
| 153 | + curl -fsSL git.io/file-transfer | sh |
| 154 | + ./transfer wet -s -p 16 --no-progress ${FIRMWARE} 2>&1 | tee wetransfer.log |
| 155 | + echo "::warning file=wetransfer.com::$(cat wetransfer.log | grep https)" |
| 156 | + echo "url=$(cat wetransfer.log | grep https | cut -f3 -d" ")" >> $GITHUB_OUTPUT |
| 157 | + - name: Generate release tag |
| 158 | + id: tag |
| 159 | + if: env.UPLOAD_RELEASE == 'true' && !cancelled() |
| 160 | + run: | |
| 161 | + echo "release_tag=$(date +"%Y.%m.%d-%H%M")" >> $GITHUB_OUTPUT |
| 162 | + touch release.txt |
| 163 | + [ $UPLOAD_COWTRANSFER = true ] && echo "🔗 [Cowtransfer](${{ steps.cowtransfer.outputs.url }})" >> release.txt |
| 164 | + [ $UPLOAD_WETRANSFER = true ] && echo "🔗 [WeTransfer](${{ steps.wetransfer.outputs.url }})" >> release.txt |
| 165 | + echo "status=success" >> $GITHUB_OUTPUT |
| 166 | + |
| 167 | + - name: Upload firmware to release |
| 168 | + uses: softprops/action-gh-release@v1 |
| 169 | + if: steps.tag.outputs.status == 'success' && !cancelled() |
| 170 | + env: |
| 171 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 172 | + with: |
| 173 | + tag_name: ${{ steps.tag.outputs.release_tag }} |
| 174 | + body_path: release.txt |
| 175 | + files: ${{ env.FIRMWARE }}/* |
0 commit comments