├── .github └── workflows │ ├── build-openwrt-mac.yml │ └── build-openwrt.yml ├── LICENSE.md ├── README.md ├── _config.yml └── diy.sh /.github/workflows/build-openwrt-mac.yml: -------------------------------------------------------------------------------- 1 | #================================================= 2 | # https://github.com/P3TERX/Actions-OpenWrt 3 | # Description: Build OpenWrt using GitHub Actions(macOS) 4 | # Lisence: MIT 5 | # Author: P3TERX 6 | # Blog: https://p3terx.com 7 | #================================================= 8 | 9 | name: Build OpenWrt (macOS) 10 | 11 | on: 12 | public 13 | # release: 14 | # types: [published] 15 | # push: 16 | # branches: 17 | # - master 18 | # paths: 19 | # - '.config' 20 | # schedule: 21 | # - cron: 0 8 * * 5 22 | # watch: 23 | # types: [started] 24 | 25 | jobs: 26 | build: 27 | runs-on: macos-latest 28 | 29 | steps: 30 | - name: Checkout 31 | uses: actions/checkout@master 32 | 33 | - name: Initialization environment 34 | run: | 35 | brew install coreutils diffutils findutils gawk gnu-getopt gnu-tar grep wget quilt xz gnu-sed 36 | echo "::add-path::/usr/local/opt/gnu-getopt/bin" 37 | echo "::add-path::/usr/local/opt/coreutils/libexec/gnubin" 38 | echo "::add-path::/usr/local/opt/gnu-sed/libexec/gnubin" 39 | hdiutil create -size 60g -type SPARSE -fs "Case-sensitive HFS+" -volname OpenWrt OpenWrt.sparseimage 40 | hdiutil attach OpenWrt.sparseimage 41 | curl -fsSL https://raw.githubusercontent.com/P3TERX/dotfiles/master/.bashrc >> ~/.bashrc 42 | sudo systemsetup -settimezone "Asia/Shanghai" 43 | 44 | - name: Clone source code 45 | working-directory: /Volumes/OpenWrt 46 | env: 47 | REPO_URL: https://github.com/openwrt/openwrt 48 | REPO_BRANCH: openwrt-18.06 49 | run: | 50 | git clone --depth 1 $REPO_URL -b $REPO_BRANCH openwrt 51 | ln -sf /Volumes/OpenWrt/openwrt $GITHUB_WORKSPACE/openwrt 52 | sed -i "s/grep Apple.LLVM/grep -E 'Apple.(LLVM|clang)'/g" openwrt/include/prereq-build.mk 53 | 54 | - name: Update feeds 55 | run: cd openwrt && ./scripts/feeds update -a 56 | 57 | - name: Install feeds 58 | run: cd openwrt && ./scripts/feeds install -a 59 | 60 | - name: Load custom configuration 61 | env: 62 | CONFIG_FILE: '.config' 63 | DIY_SH: 'diy.sh' 64 | run: | 65 | [ -e files ] && mv files openwrt/files 66 | [ -e $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config 67 | chmod +x $DIY_SH 68 | mv $DIY_SH openwrt 69 | cd openwrt 70 | ./$DIY_SH 71 | make defconfig 72 | 73 | # - name: SSH connection to Actions 74 | # uses: P3TERX/debugger-action@master 75 | 76 | - name: Download package 77 | run: | 78 | cd openwrt && make download -j8 79 | find dl -size -1024c -exec ls -l {} \; 80 | find dl -size -1024c -exec rm -f {} \; 81 | 82 | - name: Multi-thread compile 83 | run: | 84 | cd openwrt 85 | echo -e "$(nproc) thread compile" 86 | make -j$(nproc) 87 | 88 | - name: Single-thread compile 89 | if: failure() 90 | run: | 91 | cd openwrt 92 | make -j1 V=s 93 | 94 | - name: Upload bin directory 95 | uses: actions/upload-artifact@master 96 | if: always() 97 | with: 98 | name: OpenWrt_bin 99 | path: openwrt/bin 100 | 101 | - name: Organize files 102 | if: always() 103 | run: | 104 | cd openwrt/bin/targets/*/* 105 | rm -rf packages 106 | echo "::set-env name=FIRMWARE::$(pwd)" 107 | 108 | - name: Upload firmware 109 | uses: actions/upload-artifact@master 110 | if: always() 111 | with: 112 | name: OpenWrt_firmware 113 | path: ${{ env.FIRMWARE }} 114 | -------------------------------------------------------------------------------- /.github/workflows/build-openwrt.yml: -------------------------------------------------------------------------------- 1 | #================================================= 2 | # https://github.com/P3TERX/Actions-OpenWrt 3 | # Description: Build OpenWrt using GitHub Actions 4 | # Lisence: MIT 5 | # Author: P3TERX 6 | # Modify: Gary 7 | # Blog: https://p3terx.com 8 | #================================================= 9 | 10 | name: Build OpenWrt 11 | 12 | on: 13 | release: 14 | types: [published] 15 | push: 16 | branches: 17 | - master 18 | paths: 19 | - '.config' 20 | # schedule: 21 | # - cron: 0 8 * * 5 22 | watch: 23 | types: [started] 24 | 25 | env: 26 | REPO_URL: https://github.com/coolsnowwolf/lede 27 | #REPO_URL: https://github.com/openwrt/openwrt 28 | REPO_BRANCH: master 29 | CONFIG_FILE: .config 30 | DIY_SH: diy.sh 31 | FREE_UP_DISK: false 32 | SSH_ACTIONS: false 33 | UPLOAD_BIN_DIR: false 34 | UPLOAD_FIRMWARE: true 35 | TZ: Asia/Shanghai 36 | 37 | jobs: 38 | build: 39 | runs-on: ubuntu-latest 40 | 41 | steps: 42 | - name: Checkout 43 | uses: actions/checkout@master 44 | 45 | - name: Initialization environment 46 | env: 47 | DEBIAN_FRONTEND: noninteractive 48 | run: | 49 | sudo swapoff /swapfile 50 | sudo rm -rf /swapfile /etc/apt/sources.list.d/* 51 | sudo -E apt-get -qq update 52 | 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 git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler 53 | curl -fsSL https://raw.githubusercontent.com/P3TERX/dotfiles/master/.bashrc >> ~/.bashrc 54 | 55 | - name: Free up disk space 56 | if: env.FREE_UP_DISK == 'true' 57 | env: 58 | DEBIAN_FRONTEND: noninteractive 59 | run: | 60 | sudo rm -rf /usr/share/dotnet 61 | docker rmi `docker images -q` 62 | sudo -E apt-get -q purge azure-cli ghc* zulu* hhvm llvm* firefox google* dotnet* powershell openjdk* mysql* php* 63 | sudo -E apt-get -qq autoremove --purge 64 | sudo -E apt-get -qq clean 65 | 66 | - name: Clone source code 67 | run: git clone --depth 1 $REPO_URL -b $REPO_BRANCH openwrt 68 | 69 | - name: Update feeds 70 | run: cd openwrt && ./scripts/feeds update -a 71 | 72 | - name: Install feeds 73 | run: cd openwrt && ./scripts/feeds install -a 74 | 75 | - name: Load custom configuration 76 | run: | 77 | [ -e files ] && mv files openwrt/files 78 | [ -e $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config 79 | chmod +x $DIY_SH 80 | cd openwrt 81 | ../$DIY_SH 82 | make defconfig 83 | 84 | - name: SSH connection to Actions 85 | uses: P3TERX/debugger-action@master 86 | if: env.SSH_ACTIONS == 'true' 87 | 88 | - name: Download package 89 | id: package 90 | run: | 91 | cd openwrt 92 | make download -j8 93 | find dl -size -1024c -exec ls -l {} \; 94 | find dl -size -1024c -exec rm -f {} \; 95 | 96 | - name: Compile the firmware 97 | id: compile 98 | run: | 99 | cd openwrt 100 | echo -e "$(nproc) thread compile" 101 | make -j$(nproc) || make -j1 V=s 102 | echo "::set-output name=status::success" 103 | 104 | - name: Upload bin directory 105 | uses: actions/upload-artifact@master 106 | if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true' 107 | with: 108 | name: OpenWrt_directory 109 | path: openwrt/bin 110 | 111 | - name: Organize files 112 | id: organize 113 | if: env.UPLOAD_FIRMWARE == 'true' && !cancelled() 114 | run: | 115 | cd openwrt/bin/targets/*/* 116 | rm -rf packages 117 | echo "::set-env name=FIRMWARE::$(pwd)" 118 | echo "::set-output name=status::success" 119 | 120 | - name: Upload firmware directory 121 | uses: actions/upload-artifact@master 122 | if: steps.organize.outputs.status == 'success' && !cancelled() 123 | with: 124 | name: OpenWrt_firmware 125 | path: ${{ env.FIRMWARE }} 126 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Gary 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Actions-OpenWrt 2 | 3 | [![LICENSE](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square&label=LICENSE)](https://github.com/P3TERX/Actions-OpenWrt/blob/master/LICENSE) 4 | [![GitHub Stars](https://img.shields.io/github/stars/cuiqingwei/Actions-OpenWrt.svg?style=flat-square&label=Stars)](https://github.com/cuiqingwei/Actions-OpenWrt/stargazers) 5 | [![GitHub Forks](https://img.shields.io/github/forks/cuiqingwei/Actions-OpenWrt.svg?style=flat-square&label=Forks)](https://github.com/cuiqingwei/Actions-OpenWrt/fork) 6 | 7 | ## Method 8 | ### 一键编译 9 | 10 | 点击自己仓库页面上的 **Star** 开始编译,为了防止被滥用,这个功能默认未开启。 11 | 12 | 编辑 work­flow 文件(`.github/workflows/build-openwrt.yml`)取消注释下面两行,后续点击自己仓库上的 star 即可开始编译。 13 | 14 | ```none 15 | # watch: 16 | # types: [started] 17 | ``` 18 | 19 | > **TIPS:** 字段`started`并不是“开始了”的意思,而是“已经点击 Star”。 20 | > **吐槽:** 官方并没有提供一个开始按钮,通过搜索找到过很多奇怪的一键触发方式,但都是通过 Web­hook 来实现的。通过点击 Star 来触发,这样就相当于把 Star 当成开始按钮。这个`started`有种一句双关的意思。 21 | 22 | 可以在 **Actions** 页面进行查看编译进度。 23 | 24 | #### 云 menuconfig(SSH 连接到 Actions) 25 | 26 | 通过 tmate 连接到 GitHub Ac­tions 虚拟服务器环境,可直接进行 `make menuconfig` 操作生成编译配置,或者任意的客制化操作。也就是说,你不需要再自己搭建编译环境了。这可能改变之前所有使用 GitHub Ac­tions 的编译 Open­Wrt 方式。 27 | 28 | - 编辑 workflow 文件(`.github/workflows/build-openwrt.yml`),修改`SSH_ACTIONS`环境变量的值为`true`: 29 | 30 | ```none 31 | SSH_ACTIONS: true 32 | ``` 33 | 34 | - 在触发工作流程后,在 Actions 页面等待执行到`SSH connection to Actions`步骤,会出现下面的信息。 35 | 36 | ```none 37 | To connect to this session copy-n-paste the following into a terminal or browser: 38 | 39 | ssh Y26QeagDtsPXp2mT6me5cnMRd@nyc1.tmate.io 40 | 41 | https://tmate.io/t/Y26QeagDtsPXp2mT6me5cnMRd 42 | ``` 43 | 44 | - 复制 SSH 连接命令粘贴到终端内执行,或者复制链接在浏览器中打开使用网页终端。 45 | - `cd openwrt && make menuconfig` 46 | - 完成后按快捷键`Ctrl+D`或执行`exit`命令退出,后续编译工作将自动进行。 47 | 48 | > **TIPS:** 默认连接30分钟后会断开并终止编译工作流程,防止资源浪费与封号风险。如果你想解除这个限制,可以根据提示操作,后果自负。 49 | 50 | #### 添加软件包 51 | 52 | 在 DIY 脚本中加入对指定软件包的远程仓库的克隆指令。就像下面这样: 53 | 54 | ```none 55 | git clone https://github.com/P3TERX/xxx package/xxx 56 | ``` 57 | 58 | 这样做的好处是每一次编译都会拉取最新的源码。 59 | 60 | > **TIPS:** 生成`.config`文件时记得选中相应的软件。如果添加的软件包与 Open­Wrt 中已有的软件包同名的情况,则需要把源码中的同名软件包删除,否则会优先编译 Open­Wrt 中的软件包。这同样可以利用到的 DIY 脚本。 61 | 62 | 最后不要忘了添加更新 feeds 的命令 63 | 64 | ```none 65 | ./scripts/feeds update -a 66 | ./scripts/feeds install -a 67 | ``` 68 | 69 | #### Custom files(自定义文件) 70 | 71 | 俗称 “files大法”,在仓库根目录下新建 `files` 目录,把文件放入即可。 72 | 73 | ### 定时编译 74 | 75 | 编辑 work­flow 文件(`.github/workflows/build-openwrt.yml`)取消注释下面两行。 76 | 77 | ```none 78 | # schedule: 79 | # - cron: 0 8 * * 5 80 | ``` 81 | 82 | 例子是北京时间每周五下午 4 点钟开始编译。如需自定义则按照 cron 格式修改即可,Ac­tions 虚拟环境中的时区是 UTC ,注意按照自己所在地时区进行转换。 83 | 84 | ### DIY 脚本 85 | 86 | 仓库内有一个 `diy.sh` 文件,你可以把对源码修改的指令写到这个文件中,比如修改默认 IP、主机名、主题、添加 / 删除软件包等操作。但不仅限于这些操作,发挥你强大的想象力,可做出更强大的功能。 87 | 88 | > **TIPS:** 脚本工作目录在源码目录,内附一个修改默认 IP 的例子供参考使用。 89 | 90 | ### 自定义环境变量与功能 91 | 92 |

打开 work­flow 文件(.github/workflows/build-openwrt.yml),你会看到有如下一些环境变量,可按照自己的需求对这些变量进行定义。

env:
 93 |   REPO_URL: https://github.com/coolsnowwolf/lede
 94 |   REPO_BRANCH: master
 95 |   CONFIG_FILE: .config
 96 |   DIY_SH: diy.sh
 97 |   FREE_UP_DISK: false
 98 |   SSH_ACTIONS: false
 99 |   UPLOAD_BIN_DIR: false
100 |   UPLOAD_FIRMWARE: true
101 |   TZ: Asia/Shanghai
TIPS: 修改时需要注意:(冒号)后面有空格。
环境变量功能
REPO_URL源码仓库地址
REPO_BRANCH源码分支
CONFIG_FILE.config文件名
DIY_SHDIY 脚本文件名
FREE_UP_DISK释放磁盘空间。编译磁盘空间不足报错时使用。默认false
SSH_ACTIONSSSH 连接 Actions 功能。默认false
UPLOAD_BIN_DIR上传 bin 目录。即包含所有 ipk 文件和固件的目录。默认false
UPLOAD_FIRMWARE上传固件目录。默认true
TZ时区设置

102 | 103 | ## Usage 104 | 105 | - Sign up for [GitHub Actions](https://github.com/features/actions/signup) 106 | - Fork [this GitHub repository](https://github.com/P3TERX/Actions-OpenWrt) 107 | - Generate `.config` files using [Lean's OpenWrt](https://github.com/coolsnowwolf/lede) source code. 108 | - Push `.config` file to the GitHub repository, and the build starts automatically.Progress can be viewed on the Actions page. 109 | - When the build is complete, click the `Artifacts` button in the upper right corner of the Actions page to download the binaries. 110 | 111 | ## Acknowledgments 112 | 113 | - [Microsoft](https://www.microsoft.com) 114 | - [Microsoft Azure](https://azure.microsoft.com) 115 | - [GitHub](https://github.com) 116 | - [GitHub Actions](https://github.com/features/actions) 117 | - [tmate](https://github.com/tmate-io/tmate) 118 | - [mxschmitt/action-tmate](https://github.com/mxschmitt/action-tmate) 119 | - [csexton/debugger-action](https://github.com/csexton/debugger-action) 120 | - [Cisco](https://www.cisco.com/) 121 | - [OpenWrt](https://github.com/openwrt/openwrt) 122 | - [Lean's OpenWrt](https://github.com/coolsnowwolf/lede) 123 | 124 | ## License 125 | 126 | [MIT](https://github.com/cuiqingwei/Actions-OpenWrt/blob/master/LICENSE) © GaryCUI -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-hacker -------------------------------------------------------------------------------- /diy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #================================================= 3 | # Description: DIY script 4 | # Lisence: MIT 5 | # Author: P3TERX 6 | # Blog: https://p3terx.com 7 | #================================================= 8 | # Modify default IP 9 | #sed -i 's/192.168.1.1/192.168.50.5/g' package/base-files/files/bin/config_generate 10 | --------------------------------------------------------------------------------