|
| 1 | +#================================================= |
| 2 | +# https://github.com/P3TERX/Actions-OpenWrt |
| 3 | +# Description: Build OpenWrt using GitHub Actions |
| 4 | +# Lisence: MIT |
| 5 | +# Author: P3TERX |
| 6 | +# Blog: https://p3terx.com |
| 7 | +#================================================= |
| 8 | + |
| 9 | +name: Build OpenWrt |
| 10 | + |
| 11 | +on: |
| 12 | + # push: |
| 13 | + # branches: |
| 14 | + # - master |
| 15 | + schedule: |
| 16 | + - cron: 0 16 * * 6 |
| 17 | + watch: |
| 18 | + types: started |
| 19 | + |
| 20 | +env: |
| 21 | + REPO_URL: https://github.com/openwrt/openwrt |
| 22 | + REPO_BRANCH: master |
| 23 | + CONFIG_FILE: X86_64.config |
| 24 | + DIY_SH: diy.sh |
| 25 | + FREE_UP_DISK: true |
| 26 | + SSH_ACTIONS: false |
| 27 | + UPLOAD_BIN_DIR: false |
| 28 | + UPLOAD_FIRMWARE: true |
| 29 | + UPLOAD_COWTRANSFER: false |
| 30 | + TZ: Asia/Shanghai |
| 31 | + |
| 32 | +jobs: |
| 33 | + build: |
| 34 | + if: github.event.repository.owner.id == github.event.sender.id |
| 35 | + runs-on: ubuntu-latest |
| 36 | + steps: |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@master |
| 39 | + |
| 40 | + - name: Initialization environment |
| 41 | + env: |
| 42 | + DEBIAN_FRONTEND: noninteractive |
| 43 | + run: | |
| 44 | + sudo swapoff /swapfile |
| 45 | + sudo rm -rf /swapfile /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc |
| 46 | + sudo -E apt-get -qq update |
| 47 | + sudo -E apt-get -qq install build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev libz-dev patch unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs gcc-multilib g++-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler ccache xsltproc rename |
| 48 | + sudo -E apt-get -qq autoremove --purge |
| 49 | + sudo -E apt-get -qq clean |
| 50 | + curl -fsSL https://raw.githubusercontent.com/P3TERX/dotfiles/master/.bashrc >> ~/.bashrc |
| 51 | +
|
| 52 | + - name: Clone source code |
| 53 | + run: git clone --depth 1 $REPO_URL -b $REPO_BRANCH openwrt |
| 54 | + |
| 55 | + - name: Free up disk space |
| 56 | + if: env.FREE_UP_DISK == 'true' |
| 57 | + env: |
| 58 | + DEBIAN_FRONTEND: noninteractive |
| 59 | + run: | |
| 60 | + sudo mkdir -p -m 777 /mnt/openwrt/build_dir/hostpkg /mnt/openwrt/build_dir/host openwrt/build_dir /mnt/openwrt/dl /mnt/openwrt/feeds /mnt/openwrt/staging_dir |
| 61 | + ln -s /mnt/openwrt/build_dir/hostpkg openwrt/build_dir/hostpkg |
| 62 | + ln -s /mnt/openwrt/build_dir/host openwrt/build_dir/host |
| 63 | + ln -s /mnt/openwrt/dl openwrt/dl |
| 64 | + ln -s /mnt/openwrt/staging_dir openwrt/staging_dir |
| 65 | +
|
| 66 | + - name: Update feeds |
| 67 | + run: cd openwrt && ./scripts/feeds update -a |
| 68 | + |
| 69 | + - name: Install feeds |
| 70 | + run: cd openwrt && ./scripts/feeds install -a |
| 71 | + |
| 72 | + - name: Load custom configuration |
| 73 | + run: | |
| 74 | + [ -e files ] && mv files openwrt/files |
| 75 | + [ -e $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config |
| 76 | + chmod +x $DIY_SH |
| 77 | + cd openwrt |
| 78 | + ../$DIY_SH |
| 79 | + make defconfig |
| 80 | +
|
| 81 | + - name: SSH connection to Actions |
| 82 | + uses: P3TERX/debugger-action@master |
| 83 | + if: env.SSH_ACTIONS == 'true' |
| 84 | + |
| 85 | + - name: Download package |
| 86 | + id: package |
| 87 | + run: | |
| 88 | + cd openwrt |
| 89 | + make download -j8 |
| 90 | + find dl -size -1024c -exec ls -l {} \; |
| 91 | + find dl -size -1024c -exec rm -f {} \; |
| 92 | +
|
| 93 | + - name: Compile the firmware |
| 94 | + id: compile |
| 95 | + run: | |
| 96 | + cd openwrt |
| 97 | + echo -e "$(($(nproc)+1)) thread compile" |
| 98 | + make -j$(($(nproc)+1)) || make -j1 V=s |
| 99 | + echo "::set-output name=status::success" |
| 100 | +
|
| 101 | + - name: Upload bin directory |
| 102 | + uses: actions/upload-artifact@master |
| 103 | + if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true' |
| 104 | + with: |
| 105 | + name: OpenWrt_bin |
| 106 | + path: openwrt/bin |
| 107 | + |
| 108 | + - name: Organize files |
| 109 | + id: organize |
| 110 | + if: env.UPLOAD_FIRMWARE == 'true' && !cancelled() |
| 111 | + run: | |
| 112 | + mkdir firmware && find openwrt/bin/targets/*/*/* -maxdepth 0 -name "*uefi-gpt*" -or -name "*combined*" -or -name "*.vmdk" -or -name "sha256sums" | xargs -i mv -f {} ./firmware/ |
| 113 | + cp openwrt/.config ./firmware/config.txt |
| 114 | + cd firmware |
| 115 | + echo "::set-env name=FIRMWARE::$PWD" |
| 116 | + echo "::set-output name=status::success" |
| 117 | + |
| 118 | + - name: Upload firmware directory |
| 119 | + uses: actions/upload-artifact@master |
| 120 | + if: steps.organize.outputs.status == 'success' && !cancelled() |
| 121 | + with: |
| 122 | + name: OpenWrt_firmware |
| 123 | + path: ${{ env.FIRMWARE }} |
| 124 | + |
| 125 | + - name: Get current date |
| 126 | + id: date |
| 127 | + run: echo "::set-output name=date::$(date +'%m/%d,%Y')" |
| 128 | + |
| 129 | + - name: Upload binaries to release |
| 130 | + uses: svenstaro/upload-release-action@v1-release |
| 131 | + if: steps.compile.outputs.status == 'success' && !cancelled() |
| 132 | + with: |
| 133 | + repo_token: ${{ secrets.REPO_TOKEN }} |
| 134 | + file: ${{ env.FIRMWARE }}/* |
| 135 | + tag: ${{steps.date.outputs.date}} |
| 136 | + overwrite: true |
| 137 | + file_glob: true |
| 138 | + |
| 139 | + - name: Upload firmware to cowtransfer |
| 140 | + if: env.UPLOAD_COWTRANSFER == 'true' && !cancelled() |
| 141 | + run: | |
| 142 | + curl -sL https://git.io/cowtransfer | sh |
| 143 | + ./cowtransfer-uploader -s -p 8 ${{ env.FIRMWARE }}/* |
0 commit comments