forked from Hyy2001X/AutoBuild-Actions-BETA
-
Notifications
You must be signed in to change notification settings - Fork 0
261 lines (239 loc) · 8.89 KB
/
AutoBuild-x86_64.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
###########################################################
# Description: Compile OpenWrt by GitHub Actions #
# Based on: https://github.com/P3TERX/Actions-OpenWrt #
# Author: Hyy2001X #
###########################################################
name: x86_64
on:
repository_dispatch:
#push:
# branches:
# - master
#schedule:
# - cron: 0 8 * * 5
#watch:
# types: [started]
workflow_dispatch:
inputs:
Tempoary_CONFIG:
description: '配置文件'
default: 'x86_64'
type: choice
options:
- 'x86_64'
- 'x86_64-AP'
Tempoary_FLAG:
description: '固件标签'
default: 'AUTO'
type: choice
options:
- 'AUTO'
- 'Full'
- 'AP'
Tempoary_IP:
description: '固件 IP 地址 [可选]'
default: ''
UPLOAD_RELEASES:
description: '上传固件到 Releases'
default: 'false'
type: boolean
UPLOAD_ARTIFACTS:
description: '上传固件到 Artifacts'
default: 'true'
type: boolean
UPLOAD_BIN_ARTIFACTS:
description: '上传 bin 文件夹到 Artifacts'
default: 'true'
type: boolean
### 环境变量设置
env:
# 编译时调用的 [.config] 文件名称
CONFIG_FILE: x86_64
# 源码仓库:分支
DEFAULT_SOURCE: Lienol/openwrt:21.02
# 删除无用文件以增加编译空间
DELETE_USELESS_FILES: true
# 删除早期的 workflow 任务
DELETE_OLD_WORKFLOW: false
# Cache 加速编译
CACHE_ACCELERATE: false
### 结束
jobs:
Compile:
runs-on: ubuntu-20.04
permissions:
issues: write
pull-requests: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@main
with:
fetch-depth: 0
- name: Load Custom Variables
run: |
if [ -n "${{ github.event.inputs.Tempoary_CONFIG }}" ]
then
if [ -f "$GITHUB_WORKSPACE/Configs/${{ github.event.inputs.Tempoary_CONFIG }}" ]
then
CONFIG_FILE=${{ github.event.inputs.Tempoary_CONFIG }}
else
CONFIG_FILE=${{ env.CONFIG_FILE }}
fi
else
CONFIG_FILE=${{ env.CONFIG_FILE }}
fi
if [ ! -f "$GITHUB_WORKSPACE/Configs/$CONFIG_FILE" ]
then
echo "CONFIG_FILE: [/Config/$CONFIG_FILE] is not detected ..."
exit 1
else
echo "CONFIG_FILE: [/Config/$CONFIG_FILE]"
echo "CONFIG_FILE=$CONFIG_FILE" >> $GITHUB_ENV
fi
if [ -n "${{ github.event.inputs.Tempoary_IP }}" ]
then
echo "IP: [${{ github.event.inputs.Tempoary_IP }}]"
echo "Tempoary_IP=${{ github.event.inputs.Tempoary_IP }}" >> $GITHUB_ENV
fi
if [ -n "${{ github.event.inputs.Tempoary_FLAG }}" ]
then
echo "FLAG: [${{ github.event.inputs.Tempoary_FLAG }}]"
echo "Tempoary_FLAG=${{ github.event.inputs.Tempoary_FLAG }}" >> $GITHUB_ENV
fi
REPO_URL="https://github.com/$(cut -d \: -f 1 <<< ${{ env.DEFAULT_SOURCE }})"
REPO_BRANCH=$(cut -d \: -f 2 <<< ${{ env.DEFAULT_SOURCE }})
echo "REPO_URL=$REPO_URL" >> $GITHUB_ENV
echo "REPO_BRANCH=$REPO_BRANCH" >> $GITHUB_ENV
echo "Compile_Date=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV
echo "Display_Date=$(date +%Y/%m/%d)" >> $GITHUB_ENV
if [[ -z "${{ github.event.inputs.Tempoary_CONFIG }}" ]]; then
echo "TIMED_TRIGGER=true" >> $GITHUB_ENV
else
echo "UPLOAD_RELEASES=${{ github.event.inputs.UPLOAD_RELEASES }}" >> $GITHUB_ENV
echo "UPLOAD_ARTIFACTS=${{ github.event.inputs.UPLOAD_ARTIFACTS }}" >> $GITHUB_ENV
echo "UPLOAD_BIN_ARTIFACTS=${{ github.event.inputs.UPLOAD_BIN_ARTIFACTS }}" >> $GITHUB_ENV
fi
- name: TIMED_TRIGGER
if: env.TIMED_TRIGGER == 'true'
env:
UPLOAD_RELEASES: true
UPLOAD_ARTIFACTS: false
UPLOAD_BIN_ARTIFACTS: false
run: |
echo "UPLOAD_RELEASES=${UPLOAD_RELEASES}" >> $GITHUB_ENV
echo "UPLOAD_ARTIFACTS=${UPLOAD_ARTIFACTS}" >> $GITHUB_ENV
echo "UPLOAD_BIN_ARTIFACTS=${UPLOAD_BIN_ARTIFACTS}" >> $GITHUB_ENV
- name: Initialize Environment
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo -E apt-get update
sudo -E apt-get -y install busybox build-essential cmake 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 g++-multilib p7zip p7zip-full msmtp libssl-dev texinfo libreadline-dev libglib2.0-dev xmlto qemu-utils upx libelf-dev autoconf automake libtool autopoint ccache curl wget vim nano python2.7 python3 python3-pip python3-ply haveged lrzsz device-tree-compiler scons antlr3 gperf intltool mkisofs rsync
sudo timedatectl set-timezone "Asia/Shanghai"
sudo mkdir -p /workdir
sudo chown $USER:$GROUPS /workdir
if [ "${{ env.DELETE_USELESS_FILES }}" == true ]
then
docker rmi $(docker images -q)
sudo rm -rf /usr/share/dotnet /etc/mysql /etc/php
sudo -E apt-get -y autoremove --purge
sudo -E apt-get clean
sudo rm -rf /etc/apt/sources.list.d/* /usr/local/lib/android /usr/lib/jvm /opt/ghc /swapfile
fi
- name: Clone Openwrt Source Code
run: |
git clone -b $REPO_BRANCH $REPO_URL openwrt
ln -sf /workdir/openwrt $GITHUB_WORKSPACE/openwrt
cd openwrt
./scripts/feeds update -a
./scripts/feeds install -a
- name: Accelerate
if: env.CACHE_ACCELERATE == 'true'
uses: klever1988/cachewrtbuild@main
with:
ccache: false
toolchain: true
skip: true
clean: true
prefix: ${{ github.workspace }}/openwrt
- name: Run Diy Scripts
run: |
echo "Free space:"
df -h
chmod +x Scripts/AutoBuild_*.sh
cd openwrt
if [ "${{ env.CACHE_ACCELERATE }}" == true ]
then
echo -e "\nCONFIG_DEVEL=y\nCONFIG_CCACHE=y\n" >> $GITHUB_WORKSPACE/Configs/$CONFIG_FILE
fi
cp $GITHUB_WORKSPACE/Configs/$CONFIG_FILE .config
source $GITHUB_WORKSPACE/Scripts/AutoBuild_DiyScript.sh
source $GITHUB_WORKSPACE/Scripts/AutoBuild_Function.sh
make defconfig
Firmware_Diy_Before
rm -f .config && cp $GITHUB_WORKSPACE/Configs/$CONFIG_FILE .config
Firmware_Diy_Main
Firmware_Diy
Firmware_Diy_Other
- name: Pre-download Libraries
run: |
cd openwrt
./scripts/feeds install -a
make defconfig
make download -j8
- name: Build OpenWrt
id: compile
run: |
cd openwrt
make -j4 || make -j1 V=s
[ "$?" == 0 ] && echo "Compile_Result=true" >> $GITHUB_ENV || echo "Compile_Result=false" >> $GITHUB_ENV
- name: Checkout Firmware
if: steps.compile.outcome == 'success' && !cancelled()
run: |
cd openwrt
source $GITHUB_WORKSPACE/Scripts/AutoBuild_Function.sh
Firmware_Diy_End
- name: Upload Firmware to Artifacts
uses: actions/upload-artifact@main
if: env.UPLOAD_ARTIFACTS == 'true' && steps.compile.outcome == 'success' && !cancelled()
with:
name: ${{ env.CONFIG_FILE }}_firmware_${{ env.Compile_Date }}
path: openwrt/bin/Firmware
- name: Upload bin to Artifacts
uses: actions/upload-artifact@main
if: env.UPLOAD_BIN_ARTIFACTS == 'true' && steps.compile.outcome == 'success' && !cancelled()
with:
name: ${{ env.CONFIG_FILE }}_bin_${{ env.Compile_Date }}
path: openwrt/bin
- name: Upload Firmware to Release
uses: svenstaro/upload-release-action@v2
if: env.UPLOAD_RELEASES == 'true' && steps.compile.outcome == 'success' && !cancelled()
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: openwrt/bin/Firmware/*
file_glob: true
tag: AutoUpdate
overwrite: true
- name: Refresh API (1/2)
if: env.UPLOAD_RELEASES == 'true' && steps.compile.outcome == 'success' && !cancelled()
run: |
wget https://api.github.com/repos/${{github.repository}}/releases/tags/AutoUpdate -O API
- name: Refresh API (2/2)
if: env.UPLOAD_RELEASES == 'true' && steps.compile.outcome == 'success' && !cancelled()
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./API
file_glob: true
tag: AutoUpdate
overwrite: true
- name: Delete old Workflow Runs
continue-on-error: true
if: env.DELETE_OLD_WORKFLOW == 'true' && !cancelled()
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
retain_days: 3
keep_minimum_runs: 0