├── .config ├── diy-part1.sh ├── diy-part2.sh ├── LICENSE ├── .github └── workflows │ ├── update-checker.yml │ └── openwrt-builder.yml └── README.md /.config: -------------------------------------------------------------------------------- 1 | # This is an empty file, please overwrite it after generating the .config file with the source code -------------------------------------------------------------------------------- /diy-part1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # https://github.com/P3TERX/Actions-OpenWrt 4 | # File name: diy-part1.sh 5 | # Description: OpenWrt DIY script part 1 (Before Update feeds) 6 | # 7 | # Copyright (c) 2019-2024 P3TERX 8 | # 9 | # This is free software, licensed under the MIT License. 10 | # See /LICENSE for more information. 11 | # 12 | 13 | # Uncomment a feed source 14 | #sed -i 's/^#\(.*helloworld\)/\1/' feeds.conf.default 15 | 16 | # Add a feed source 17 | echo 'src-git helloworld https://github.com/fw876/helloworld' >>feeds.conf.default 18 | #echo 'src-git passwall https://github.com/xiaorouji/openwrt-passwall' >>feeds.conf.default 19 | -------------------------------------------------------------------------------- /diy-part2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # https://github.com/P3TERX/Actions-OpenWrt 4 | # File name: diy-part2.sh 5 | # Description: OpenWrt DIY script part 2 (After Update feeds) 6 | # 7 | # Copyright (c) 2019-2024 P3TERX 8 | # 9 | # This is free software, licensed under the MIT License. 10 | # See /LICENSE for more information. 11 | # 12 | 13 | # Modify default IP 14 | #sed -i 's/192.168.1.1/192.168.50.5/g' package/base-files/files/bin/config_generate 15 | 16 | # Modify default theme 17 | #sed -i 's/luci-theme-bootstrap/luci-theme-argon/g' feeds/luci/collections/luci/Makefile 18 | 19 | # Modify hostname 20 | #sed -i 's/OpenWrt/P3TERX-Router/g' package/base-files/files/bin/config_generate 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019-2024 P3TERX 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. 22 | -------------------------------------------------------------------------------- /.github/workflows/update-checker.yml: -------------------------------------------------------------------------------- 1 | # 2 | # https://github.com/P3TERX/Actions-OpenWrt 3 | # 4 | # File: .github/workflows/update-checker.yml 5 | # Description: Source code update checker 6 | # 7 | # Copyright (c) 2019-2024 P3TERX 8 | # 9 | # This is free software, licensed under the MIT License. 10 | # See /LICENSE for more information. 11 | # 12 | 13 | name: Update Checker 14 | 15 | env: 16 | REPO_URL: https://github.com/coolsnowwolf/lede 17 | REPO_BRANCH: master 18 | 19 | on: 20 | workflow_dispatch: 21 | # schedule: 22 | # - cron: 0 */18 * * * 23 | 24 | jobs: 25 | check: 26 | runs-on: ubuntu-latest 27 | 28 | steps: 29 | 30 | - name: Get Commit Hash 31 | id: getHash 32 | run: | 33 | git clone --depth 1 $REPO_URL -b $REPO_BRANCH . 34 | echo "commitHash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT 35 | 36 | - name: Compare Commit Hash 37 | id: cacheHash 38 | uses: actions/cache@v3 39 | with: 40 | path: .commitHash 41 | key: commitHash_${{ steps.getHash.outputs.commitHash }} 42 | 43 | - name: Save New Commit Hash 44 | if: steps.cacheHash.outputs.cache-hit != 'true' 45 | run: | 46 | echo ${{ steps.getHash.outputs.commitHash }} | tee .commitHash 47 | 48 | - name: Trigger build 49 | if: steps.cacheHash.outputs.cache-hit != 'true' 50 | uses: peter-evans/repository-dispatch@v2 51 | with: 52 | token: ${{ github.token }} 53 | event-type: Source Code Update 54 | 55 | - name: Delete workflow runs 56 | uses: Mattraks/delete-workflow-runs@v2 57 | with: 58 | retain_days: 0 59 | keep_minimum_runs: 2 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **English** | [中文](https://p3terx.com/archives/build-openwrt-with-github-actions.html) 2 | 3 | # Actions-OpenWrt 4 | 5 | [![LICENSE](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square&label=LICENSE)](https://github.com/P3TERX/Actions-OpenWrt/blob/master/LICENSE) 6 | ![GitHub Stars](https://img.shields.io/github/stars/P3TERX/Actions-OpenWrt.svg?style=flat-square&label=Stars&logo=github) 7 | ![GitHub Forks](https://img.shields.io/github/forks/P3TERX/Actions-OpenWrt.svg?style=flat-square&label=Forks&logo=github) 8 | 9 | A template for building OpenWrt with GitHub Actions 10 | 11 | ## Usage 12 | 13 | - Click the [Use this template](https://github.com/P3TERX/Actions-OpenWrt/generate) button to create a new repository. 14 | - Generate `.config` files using [Lean's OpenWrt](https://github.com/coolsnowwolf/lede) source code. ( You can change it through environment variables in the workflow file. ) 15 | - Push `.config` file to the GitHub repository. 16 | - Select `Build OpenWrt` on the Actions page. 17 | - Click the `Run workflow` button. 18 | - When the build is complete, click the `Artifacts` button in the upper right corner of the Actions page to download the binaries. 19 | 20 | ## Tips 21 | 22 | - It may take a long time to create a `.config` file and build the OpenWrt firmware. Thus, before create repository to build your own firmware, you may check out if others have already built it which meet your needs by simply [search `Actions-Openwrt` in GitHub](https://github.com/search?q=Actions-openwrt). 23 | - Add some meta info of your built firmware (such as firmware architecture and installed packages) to your repository introduction, this will save others' time. 24 | 25 | ## Credits 26 | 27 | - [Microsoft Azure](https://azure.microsoft.com) 28 | - [GitHub Actions](https://github.com/features/actions) 29 | - [OpenWrt](https://github.com/openwrt/openwrt) 30 | - [coolsnowwolf/lede](https://github.com/coolsnowwolf/lede) 31 | - [Mikubill/transfer](https://github.com/Mikubill/transfer) 32 | - [softprops/action-gh-release](https://github.com/softprops/action-gh-release) 33 | - [Mattraks/delete-workflow-runs](https://github.com/Mattraks/delete-workflow-runs) 34 | - [dev-drprasad/delete-older-releases](https://github.com/dev-drprasad/delete-older-releases) 35 | - [peter-evans/repository-dispatch](https://github.com/peter-evans/repository-dispatch) 36 | 37 | ## License 38 | 39 | [MIT](https://github.com/P3TERX/Actions-OpenWrt/blob/main/LICENSE) © [**P3TERX**](https://p3terx.com) 40 | -------------------------------------------------------------------------------- /.github/workflows/openwrt-builder.yml: -------------------------------------------------------------------------------- 1 | # 2 | # https://github.com/P3TERX/Actions-OpenWrt 3 | # 4 | # File: .github/workflows/openwrt-bulder.yml 5 | # Description: Build OpenWrt using GitHub Actions 6 | # 7 | # Copyright (c) 2019-2024 P3TERX 8 | # 9 | # This is free software, licensed under the MIT License. 10 | # See /LICENSE for more information. 11 | # 12 | 13 | name: OpenWrt Builder 14 | 15 | on: 16 | repository_dispatch: 17 | workflow_dispatch: 18 | 19 | env: 20 | REPO_URL: https://github.com/coolsnowwolf/lede 21 | REPO_BRANCH: master 22 | FEEDS_CONF: feeds.conf.default 23 | CONFIG_FILE: .config 24 | DIY_P1_SH: diy-part1.sh 25 | DIY_P2_SH: diy-part2.sh 26 | UPLOAD_BIN_DIR: false 27 | UPLOAD_FIRMWARE: true 28 | UPLOAD_RELEASE: true 29 | TZ: Asia/Shanghai 30 | 31 | jobs: 32 | build: 33 | runs-on: ubuntu-22.04 34 | 35 | steps: 36 | - name: Checkout 37 | uses: actions/checkout@main 38 | 39 | - name: Initialization environment 40 | env: 41 | DEBIAN_FRONTEND: noninteractive 42 | run: | 43 | sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL 44 | sudo docker image prune --all --force 45 | sudo -E apt-get -qq update 46 | sudo -E apt-get -qq install ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential bzip2 ccache cmake cpio curl device-tree-compiler fastjar flex gawk gettext gcc-multilib g++-multilib git gperf haveged help2man intltool libc6-dev-i386 libelf-dev libfuse-dev libglib2.0-dev libgmp3-dev libltdl-dev libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev libpython3-dev libreadline-dev libssl-dev libtool lrzsz mkisofs msmtp ninja-build p7zip p7zip-full patch pkgconf python2.7 python3 python3-pyelftools python3-setuptools qemu-utils rsync scons squashfs-tools subversion swig texinfo uglifyjs upx-ucl unzip vim wget xmlto xxd zlib1g-dev 47 | sudo -E apt-get -qq autoremove --purge 48 | sudo -E apt-get -qq clean 49 | sudo timedatectl set-timezone "$TZ" 50 | sudo mkdir -p /workdir 51 | sudo chown $USER:$GROUPS /workdir 52 | 53 | - name: Clone source code 54 | working-directory: /workdir 55 | run: | 56 | df -hT $PWD 57 | git clone $REPO_URL -b $REPO_BRANCH openwrt 58 | ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt 59 | 60 | - name: Load custom feeds 61 | run: | 62 | [ -e $FEEDS_CONF ] && mv $FEEDS_CONF openwrt/feeds.conf.default 63 | chmod +x $DIY_P1_SH 64 | cd openwrt 65 | $GITHUB_WORKSPACE/$DIY_P1_SH 66 | 67 | - name: Update feeds 68 | run: cd openwrt && ./scripts/feeds update -a 69 | 70 | - name: Install feeds 71 | run: cd openwrt && ./scripts/feeds install -a 72 | 73 | - name: Load custom configuration 74 | run: | 75 | [ -e files ] && mv files openwrt/files 76 | [ -e $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config 77 | chmod +x $DIY_P2_SH 78 | cd openwrt 79 | $GITHUB_WORKSPACE/$DIY_P2_SH 80 | 81 | - name: Download package 82 | id: package 83 | run: | 84 | cd openwrt 85 | make defconfig 86 | make download -j8 87 | find dl -size -1024c -exec ls -l {} \; 88 | find dl -size -1024c -exec rm -f {} \; 89 | 90 | - name: Compile the firmware 91 | id: compile 92 | run: | 93 | cd openwrt 94 | echo -e "$(nproc) thread compile" 95 | make -j$(nproc) || make -j1 || make -j1 V=s 96 | echo "status=success" >> $GITHUB_OUTPUT 97 | grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/' > DEVICE_NAME 98 | [ -s DEVICE_NAME ] && echo "DEVICE_NAME=_$(cat DEVICE_NAME)" >> $GITHUB_ENV 99 | echo "FILE_DATE=_$(date +"%Y%m%d%H%M")" >> $GITHUB_ENV 100 | 101 | - name: Check space usage 102 | if: (!cancelled()) 103 | run: df -hT 104 | 105 | - name: Upload bin directory 106 | uses: actions/upload-artifact@main 107 | if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true' 108 | with: 109 | name: OpenWrt_bin${{ env.DEVICE_NAME }}${{ env.FILE_DATE }} 110 | path: openwrt/bin 111 | 112 | - name: Organize files 113 | id: organize 114 | if: env.UPLOAD_FIRMWARE == 'true' && !cancelled() 115 | run: | 116 | cd openwrt/bin/targets/*/* 117 | rm -rf packages 118 | echo "FIRMWARE=$PWD" >> $GITHUB_ENV 119 | echo "status=success" >> $GITHUB_OUTPUT 120 | 121 | - name: Upload firmware directory 122 | uses: actions/upload-artifact@main 123 | if: steps.organize.outputs.status == 'success' && !cancelled() 124 | with: 125 | name: OpenWrt_firmware${{ env.DEVICE_NAME }}${{ env.FILE_DATE }} 126 | path: ${{ env.FIRMWARE }} 127 | 128 | - name: Generate release tag 129 | id: tag 130 | if: env.UPLOAD_RELEASE == 'true' && !cancelled() 131 | run: | 132 | echo "release_tag=$(date +"%Y.%m.%d-%H%M")" >> $GITHUB_OUTPUT 133 | touch release.txt 134 | [ ${UPLOAD_GOFILE} = true && ${{ steps.gofile.outputs.url }} ] && echo "🔗 [GoFile](${{ steps.gofile.outputs.url }})" >> release.txt 135 | echo "status=success" >> $GITHUB_OUTPUT 136 | 137 | - name: Upload firmware to release 138 | uses: softprops/action-gh-release@master 139 | if: steps.tag.outputs.status == 'success' && !cancelled() 140 | env: 141 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 142 | with: 143 | tag_name: ${{ steps.tag.outputs.release_tag }} 144 | body_path: release.txt 145 | files: ${{ env.FIRMWARE }}/* 146 | 147 | - name: Delete workflow runs 148 | uses: Mattraks/delete-workflow-runs@main 149 | with: 150 | retain_days: 0 151 | keep_minimum_runs: 2 152 | 153 | - name: Remove old Releases 154 | uses: dev-drprasad/delete-older-releases@master 155 | if: env.UPLOAD_RELEASE == 'true' && !cancelled() 156 | with: 157 | keep_latest: 3 158 | delete_tags: true 159 | env: 160 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 161 | --------------------------------------------------------------------------------