GitHub Actions云编译OpenWrt固件

GitHub Actions是个很牛逼的集成功能,可以在GitHub 官方市场 或者 awesome actions的仓库搜索你想要的 action。具体介绍网上很多.

* 首先在GitHub注册账户才能使用Actions,登陆[GitHub] (https://github.com/) 注册很简单。

* 以openwrt x86固件编译为例:懒得配图了

* 登陆你的GitHub 账号,搜索coolsnowwolf/lede,然后fork到你账号。

* 打开的你lede库,进入.github/workflows目录,打开openwrt-ci.yml,可以修改后复制本脚本代码替换。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

// This is free software, lisence use MIT.
// Copyright (C) 2019 P3TERX
// Copyright (C) 2019 KFERMercer


name: OpenWrt-CI

on:
push:
branches:
- master
# schedule:

# - cron: 0 20 \* \* \*

# release:

# types: [published]

jobs:

build:

runs-on: ubuntu-latest

steps:

- name: Checkout
uses: actions/checkout@master
with:
ref: master

- name: Space cleanup
env:
DEBIAN\_FRONTEND: noninteractive
run: |
docker rmi `docker images -q`
sudo rm -rf /usr/share/dotnet /etc/mysql /etc/php /etc/apt/sources.list.d
sudo -E apt-get -y purge azure-cli ghc\* zulu\* hhvm llvm\* firefox google\* dotnet\* powershell openjdk\* mysql\* php\*
sudo -E apt-get update
sudo -E apt-get -y 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
sudo -E apt-get -y autoremove --purge
sudo -E apt-get clean

# sudo mkdir -p -m 777 /mnt/openwrt/bin /mnt/openwrt/build\_dir/host /mnt/openwrt/build\_dir/hostpkg /mnt/openwrt/dl /mnt/openwrt/feeds /mnt/openwrt/staging\_dir

# ln -s /mnt/openwrt/bin ./bin

# mkdir -p ./build\_dir/host && ln -s /mnt/openwrt/build\_dir/host ./build\_dir/host

# mkdir -p ./build\_dir/host && ln -s /mnt/openwrt/build\_dir/hostpkg ./build\_dir/hostpkg

# ln -s /mnt/openwrt/dl ./dl

# ln -s /mnt/openwrt/feeds ./feeds

# ln -s /mnt/openwrt/staging\_dir ./staging\_dir

df -h

- name: Update feeds
run: |
./scripts/feeds update -a
./scripts/feeds install -a

- name: Generate configuration file
run: |
rm -f ./.config\*
touch ./.config

#
# ========================固件定制部分========================

#

#
# 如果不对本区块做出任何编辑, 则生成默认配置固件.

#

# 以下为定制化固件选项和说明:

#

#
# 有些插件/选项是默认开启的, 如果想要关闭, 请参照以下示例进行编写:

#
# =========================================

# | # 取消编译VMware镜像: |

# | cat >> .config <> .config <> .config <> .config <> .config <> .config <> .config <> .config <> .config <> .config <> .config <<EOF

# # CONFIG\_TARGET\_IMAGES\_PAD is not set

# # CONFIG\_VMDK\_IMAGES is not set

# EOF

#
# ========================固件定制部分结束========================

#

sed -i 's/^[ \t]\*//g' ./.config
make defconfig

- name: Make download
run: |
make download -j8
find ./dl/ -size -1024c -exec rm -f {} \;
df -h

- name: Compile firmware
run: |
make -j$(nproc) || make -j1 V=s

echo "======================="
echo "Space usage:"
echo "======================="
df -h
echo "======================="
du -h --max-depth=1 ./ --exclude=build\_dir --exclude=bin
du -h --max-depth=1 ./build\_dir
du -h --max-depth=1 ./bin

- name: Prepare artifact
run: find ./bin/targets/ -type d -name "packages" | xargs rm -rf {}

- name: Upload artifact
uses: actions/upload-artifact@master
with:
name: OpenWrt firmware
path: ./bin/targets/

按固件定制说明去除#符号,实现你的选择。

修改结束点击Commit changes保存更改,同时Actions编译动作就开始了。可以点击Actions进入查看编译进度,编译时间大约2小时左右,没有提示错误你就不用管了,编译结束点击“*右侧带数字Actions*”下拉选择固件开始下载。

你可以在本地编写不同硬件型号路由器固件编译脚本,想要编译是upload file到workflows目录替换原有脚本。

为了和源库同步你可以新建个同步Action,定时启动同步库。

怎么用全靠你想像力,都能实现。