├── diy-part2.sh ├── feeds.conf.default ├── diy-part1.sh ├── LICENSE ├── .github └── workflows │ ├── update-checker.yml │ └── build-openwrt.yml └── README.md /diy-part2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2019-2020 P3TERX 4 | # 5 | # This is free software, licensed under the MIT License. 6 | # See /LICENSE for more information. 7 | # 8 | # https://github.com/P3TERX/Actions-OpenWrt 9 | # File name: diy-part2.sh 10 | # Description: OpenWrt DIY script part 2 (After Update feeds) 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 | -------------------------------------------------------------------------------- /feeds.conf.default: -------------------------------------------------------------------------------- 1 | src-git packages https://github.com/coolsnowwolf/packages 2 | src-git luci https://github.com/coolsnowwolf/luci 3 | src-git routing https://github.com/coolsnowwolf/routing 4 | src-git telephony https://git.openwrt.org/feed/telephony.git 5 | src-git helloworld https://github.com/fw876/helloworld.git 6 | src-git istore https://github.com/linkease/istore.git 7 | #src-git oui https://github.com/zhaojh329/oui.git 8 | #src-git video https://github.com/openwrt/video.git 9 | #src-git targets https://github.com/openwrt/targets.git 10 | #src-git oldpackages http://git.openwrt.org/packages.git 11 | #src-link custom /usr/src/openwrt/custom-feed 12 | -------------------------------------------------------------------------------- /diy-part1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright (c) 2019-2020 P3TERX 4 | # 5 | # This is free software, licensed under the MIT License. 6 | # See /LICENSE for more information. 7 | # 8 | # https://github.com/P3TERX/Actions-OpenWrt 9 | # File name: diy-part1.sh 10 | # Description: OpenWrt DIY script part 1 (Before Update feeds) 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 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019-2020 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 | # Copyright (c) 2019-2021 P3TERX 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 | # File: .github/workflows/update-checker.yml 9 | # Description: Source code update checker 10 | # 11 | 12 | name: Update Checker 13 | 14 | env: 15 | REPO_URL: https://github.com/coolsnowwolf/lede 16 | REPO_BRANCH: master 17 | 18 | on: 19 | workflow_dispatch: 20 | # schedule: 21 | # - cron: 0 */18 * * * 22 | 23 | jobs: 24 | check: 25 | runs-on: ubuntu-latest 26 | 27 | steps: 28 | 29 | - name: Get Commit Hash 30 | id: getHash 31 | run: | 32 | git clone --depth 1 $REPO_URL -b $REPO_BRANCH . 33 | echo "::set-output name=commitHash::$(git rev-parse HEAD)" 34 | 35 | - name: Compare Commit Hash 36 | id: cacheHash 37 | uses: actions/cache@v2 38 | with: 39 | path: .commitHash 40 | key: HEAD-${{ steps.getHash.outputs.commitHash }} 41 | 42 | - name: Save New Commit Hash 43 | if: steps.cacheHash.outputs.cache-hit != 'true' 44 | run: | 45 | echo ${{ steps.getHash.outputs.commitHash }} | tee .commitHash 46 | 47 | - name: Trigger build 48 | if: steps.cacheHash.outputs.cache-hit != 'true' 49 | uses: peter-evans/repository-dispatch@v1 50 | with: 51 | token: ${{ secrets.ACTIONS_TRIGGER_PAT }} 52 | event-type: Source Code Update 53 | 54 | - name: Delete workflow runs 55 | uses: GitRML/delete-workflow-runs@main 56 | with: 57 | retain_days: 1 58 | keep_minimum_runs: 1 59 | -------------------------------------------------------------------------------- /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/P3TERX/Actions-OpenWrt.svg?style=flat-square&label=Stars&logo=github) 5 | ![GitHub Forks](https://img.shields.io/github/forks/P3TERX/Actions-OpenWrt.svg?style=flat-square&label=Forks&logo=github) 6 | 7 | Build OpenWrt using GitHub Actions 8 | 9 | [Read the details in my blog (in Chinese) | 中文教程](https://p3terx.com/archives/build-openwrt-with-github-actions.html) 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 | ## Acknowledgments 26 | 27 | - [Microsoft Azure](https://azure.microsoft.com) 28 | - [GitHub Actions](https://github.com/features/actions) 29 | - [OpenWrt](https://github.com/openwrt/openwrt) 30 | - [Lean's OpenWrt](https://github.com/coolsnowwolf/lede) 31 | - [tmate](https://github.com/tmate-io/tmate) 32 | - [mxschmitt/action-tmate](https://github.com/mxschmitt/action-tmate) 33 | - [csexton/debugger-action](https://github.com/csexton/debugger-action) 34 | - [Cowtransfer](https://cowtransfer.com) 35 | - [WeTransfer](https://wetransfer.com/) 36 | - [Mikubill/transfer](https://github.com/Mikubill/transfer) 37 | - [softprops/action-gh-release](https://github.com/softprops/action-gh-release) 38 | - [ActionsRML/delete-workflow-runs](https://github.com/ActionsRML/delete-workflow-runs) 39 | - [dev-drprasad/delete-older-releases](https://github.com/dev-drprasad/delete-older-releases) 40 | - [peter-evans/repository-dispatch](https://github.com/peter-evans/repository-dispatch) 41 | 42 | ## License 43 | 44 | [MIT](https://github.com/P3TERX/Actions-OpenWrt/blob/main/LICENSE) © P3TERX 45 | -------------------------------------------------------------------------------- /.github/workflows/build-openwrt.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2019-2020 P3TERX 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: true 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 | 44 | - name: Initialization environment 45 | env: 46 | DEBIAN_FRONTEND: noninteractive 47 | run: | 48 | sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc 49 | sudo -E apt-get -qq update 50 | sudo -E apt-get -qq install $(curl -fsSL git.io/depends-ubuntu-2004) 51 | sudo -E apt-get -qq autoremove --purge 52 | sudo -E apt-get -qq clean 53 | sudo timedatectl set-timezone "$TZ" 54 | sudo mkdir -p /workdir 55 | sudo chown $USER:$GROUPS /workdir 56 | 57 | - name: Clone source code 58 | working-directory: /workdir 59 | run: | 60 | df -hT $PWD 61 | git clone $REPO_URL -b $REPO_BRANCH openwrt 62 | ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt 63 | 64 | - name: Load custom feeds 65 | run: | 66 | [ -e $FEEDS_CONF ] && mv $FEEDS_CONF openwrt/feeds.conf.default 67 | chmod +x $DIY_P1_SH 68 | cd openwrt 69 | $GITHUB_WORKSPACE/$DIY_P1_SH 70 | 71 | - name: Update feeds 72 | run: cd openwrt && ./scripts/feeds update -a 73 | 74 | - name: Install feeds 75 | run: cd openwrt && ./scripts/feeds install -a 76 | 77 | - name: Load custom configuration 78 | run: | 79 | [ -e files ] && mv files openwrt/files 80 | [ -e $CONFIG_FILE ] && mv $CONFIG_FILE openwrt/.config 81 | chmod +x $DIY_P2_SH 82 | cd openwrt 83 | $GITHUB_WORKSPACE/$DIY_P2_SH 84 | 85 | - name: SSH connection to Actions 86 | uses: P3TERX/ssh2actions@v1.0.0 87 | if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh') 88 | env: 89 | TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} 90 | TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} 91 | 92 | - name: Download package 93 | id: package 94 | run: | 95 | cd openwrt 96 | make defconfig 97 | make download -j8 98 | find dl -size -1024c -exec ls -l {} \; 99 | find dl -size -1024c -exec rm -f {} \; 100 | 101 | - name: Compile the firmware 102 | id: compile 103 | run: | 104 | cd openwrt 105 | echo -e "$(nproc) thread compile" 106 | make -j$(nproc) || make -j1 || make -j1 V=s 107 | echo "::set-output name=status::success" 108 | grep '^CONFIG_TARGET.*DEVICE.*=y' .config | sed -r 's/.*DEVICE_(.*)=y/\1/' > DEVICE_NAME 109 | [ -s DEVICE_NAME ] && echo "DEVICE_NAME=_$(cat DEVICE_NAME)" >> $GITHUB_ENV 110 | echo "FILE_DATE=_$(date +"%Y%m%d%H%M")" >> $GITHUB_ENV 111 | 112 | - name: Check space usage 113 | if: (!cancelled()) 114 | run: df -hT 115 | 116 | - name: Upload bin directory 117 | uses: actions/upload-artifact@main 118 | if: steps.compile.outputs.status == 'success' && env.UPLOAD_BIN_DIR == 'true' 119 | with: 120 | name: OpenWrt_bin${{ env.DEVICE_NAME }}${{ env.FILE_DATE }} 121 | path: openwrt/bin 122 | 123 | - name: Organize files 124 | id: organize 125 | if: env.UPLOAD_FIRMWARE == 'true' && !cancelled() 126 | run: | 127 | cd openwrt/bin/targets/*/* 128 | rm -rf packages 129 | echo "FIRMWARE=$PWD" >> $GITHUB_ENV 130 | echo "::set-output name=status::success" 131 | 132 | - name: Upload firmware directory 133 | uses: actions/upload-artifact@main 134 | if: steps.organize.outputs.status == 'success' && !cancelled() 135 | with: 136 | name: OpenWrt_firmware${{ env.DEVICE_NAME }}${{ env.FILE_DATE }} 137 | path: ${{ env.FIRMWARE }} 138 | 139 | - name: Upload firmware to cowtransfer 140 | id: cowtransfer 141 | if: steps.organize.outputs.status == 'success' && env.UPLOAD_COWTRANSFER == 'true' && !cancelled() 142 | run: | 143 | curl -fsSL git.io/file-transfer | sh 144 | ./transfer cow --block 2621440 -s -p 64 --no-progress ${FIRMWARE} 2>&1 | tee cowtransfer.log 145 | echo "::warning file=cowtransfer.com::$(cat cowtransfer.log | grep https)" 146 | echo "::set-output name=url::$(cat cowtransfer.log | grep https | cut -f3 -d" ")" 147 | 148 | - name: Upload firmware to WeTransfer 149 | id: wetransfer 150 | if: steps.organize.outputs.status == 'success' && env.UPLOAD_WETRANSFER == 'true' && !cancelled() 151 | run: | 152 | curl -fsSL git.io/file-transfer | sh 153 | ./transfer wet -s -p 16 --no-progress ${FIRMWARE} 2>&1 | tee wetransfer.log 154 | echo "::warning file=wetransfer.com::$(cat wetransfer.log | grep https)" 155 | echo "::set-output name=url::$(cat wetransfer.log | grep https | cut -f3 -d" ")" 156 | 157 | - name: Generate release tag 158 | id: tag 159 | if: env.UPLOAD_RELEASE == 'true' && !cancelled() 160 | run: | 161 | echo "::set-output name=release_tag::$(date +"%Y.%m.%d-%H%M")" 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 "::set-output name=status::success" 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 }}/* 176 | 177 | - name: Delete workflow runs 178 | uses: GitRML/delete-workflow-runs@main 179 | with: 180 | retain_days: 1 181 | keep_minimum_runs: 3 182 | 183 | - name: Remove old Releases 184 | uses: dev-drprasad/delete-older-releases@v0.1.0 185 | if: env.UPLOAD_RELEASE == 'true' && !cancelled() 186 | with: 187 | keep_latest: 9 188 | delete_tags: true 189 | env: 190 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 191 | --------------------------------------------------------------------------------