-
Notifications
You must be signed in to change notification settings - Fork 170
292 lines (259 loc) · 10.4 KB
/
main.yml
File metadata and controls
292 lines (259 loc) · 10.4 KB
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
name: "Auto compile with OpenWrt SDK"
on:
workflow_dispatch:
push:
branches:
- '*'
tags:
- 'v*'
paths-ignore:
- "docs/**"
- "README.md"
- "README.en.md"
- ".github/workflows/**"
- ".github/**"
pull_request:
branches:
- main
paths-ignore:
- "docs/**"
- "README*.md"
- ".github/workflows/**"
- ".github/**"
env:
TZ: Asia/Shanghai
jobs:
job_auto_tag:
runs-on: ubuntu-latest
# 只在 main 分支推送且包含 version.mk 文件变更时运行
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
outputs:
new_tag: ${{ steps.create_tag.outputs.tag_name }}
tag_created: ${{ steps.create_tag.outputs.tag_created }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check if version.mk changed
id: check_version_change
run: |
# 检查version.mk是否在这次提交中被修改
if git diff --name-only HEAD~1 HEAD | grep -q "^version\.mk$"; then
echo "version.mk was modified in this commit"
echo "version_changed=true" >> $GITHUB_OUTPUT
else
echo "version.mk was not modified in this commit"
echo "version_changed=false" >> $GITHUB_OUTPUT
fi
- name: Extract version from version.mk
id: extract_version
if: steps.check_version_change.outputs.version_changed == 'true'
run: |
# 从version.mk文件中提取QMODEM_VERSION
version=$(grep "^QMODEM_VERSION" version.mk | sed 's/QMODEM_VERSION:=//' | xargs)
echo "Current QMODEM_VERSION: $version"
echo "version=$version" >> $GITHUB_OUTPUT
# 检查version是否为空
if [ -z "$version" ]; then
echo "Error: Could not extract version from version.mk"
exit 1
fi
# 生成tag名称
tag_name="v$version"
echo "tag_name=$tag_name" >> $GITHUB_OUTPUT
echo "Generated tag name: $tag_name"
- name: Check if tag already exists
id: check_tag
if: steps.check_version_change.outputs.version_changed == 'true'
run: |
tag_name="${{ steps.extract_version.outputs.tag_name }}"
# 检查tag是否已经存在
if git tag -l | grep -q "^${tag_name}$"; then
echo "Tag $tag_name already exists, skipping tag creation"
echo "tag_exists=true" >> $GITHUB_OUTPUT
else
echo "Tag $tag_name does not exist, will create it"
echo "tag_exists=false" >> $GITHUB_OUTPUT
fi
- name: Create and push tag
id: create_tag
if: steps.check_version_change.outputs.version_changed == 'true' && steps.check_tag.outputs.tag_exists == 'false'
run: |
tag_name="${{ steps.extract_version.outputs.tag_name }}"
version="${{ steps.extract_version.outputs.version }}"
# 配置git用户信息
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# 创建带注释的tag
git tag -a "$tag_name" -m "Release version $version - Auto-generated tag when QMODEM_VERSION was updated to $version"
# 推送tag到远程仓库
git push origin "$tag_name"
echo "✅ Successfully created and pushed tag: $tag_name"
echo "tag_name=$tag_name" >> $GITHUB_OUTPUT
echo "tag_created=true" >> $GITHUB_OUTPUT
job_prepare:
runs-on: ubuntu-latest
needs: [job_auto_tag]
if: always() # 总是运行,不管 auto_tag 是否运行或是否成功
outputs:
branch_name: ${{ steps.determine_push.outputs.branch_name }}
tag_name: ${{ steps.determine_push.outputs.tag_name }}
push_type: ${{ steps.determine_push.outputs.push_type }}
is_pr: ${{ steps.determine_push.outputs.is_pr }}
steps:
- name: Determine push type
id: determine_push
run: |
# 如果 auto_tag job 创建了新标签,使用新标签
if [[ "${{ needs.job_auto_tag.outputs.tag_created }}" == "true" ]]; then
echo "New tag created: ${{ needs.job_auto_tag.outputs.new_tag }}"
echo "tag_name=${{ needs.job_auto_tag.outputs.new_tag }}" >> $GITHUB_OUTPUT
echo "push_type=tag" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "This is a tag push."
echo "tag_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "push_type=tag" >> $GITHUB_OUTPUT
else
echo "This is a branch push."
echo "branch_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "push_type=branch" >> $GITHUB_OUTPUT
fi
is_pr=$([[ "${{ github.event_name }}" == "pull_request" ]] && echo 1 || echo 0)
echo "is_pr=${is_pr}" >> $GITHUB_OUTPUT
- name: Checkout
if:
uses: actions/checkout@v2
with:
path: 'qmodem'
- name: Generate Release Note
id: update_modem_support_list
run: |
cd qmodem
python3 ./scripts/update_support_list.py temp_support_list ./application/qmodem/files/usr/share/qmodem/modem_support.json
mv temp_support_list_release_notes.md ./release_note.md
- name: Upload Release Note
id: upload_release_note
uses: actions/upload-artifact@v4
with:
name: Release Note
path: ./qmodem/release_note.md
job_build_qmodem:
name: Build QModem
needs: [job_prepare]
continue-on-error: true
strategy:
matrix:
build_arch: ['arm64_ipk',"arm64_apk","x64_apk","x64_ipk","mmips_ipk","mmips_apk" ]
runs-on: ubuntu-latest
steps:
- name: Install packages
run: |
sudo -E apt-get -qq update
sudo -E apt-get -qq install zstd build-essential clang flex bison g++ gawk gcc-multilib g++-multilib gettext git libncurses5-dev libssl-dev python3-venv rsync unzip zlib1g-dev file wget
sudo -E apt-get -qq autoremove --purge
sudo -E apt-get -qq clean
- name: Checkout
uses: actions/checkout@v2
with:
path: 'qmodem'
- name: Import Env
run: cat qmodem/.github/workflows/${{ matrix.build_arch }}.env >> "$GITHUB_ENV"
- name: Cache openwrt SDK
id: cache-sdk
uses: actions/cache@v3
with:
path: sdk
key: openwrt-sdk-${{ matrix.build_arch }}
- name: Initialization environment
if: steps.cache-sdk.outputs.cache-hit != 'true'
env:
url_sdk: ${{ env.SDK_URL }}${{ env.SDK_NAME}}.${{ env.SDK_EXT }}
run: |
wget ${{ env.url_sdk }}
file_name=${{ env.SDK_NAME}}.${{ env.SDK_EXT }}
if [ "${{ env.SDK_EXT }}" == "tar.zst" ]; then
mkdir sdk && tar --zstd -xvf $file_name -C ./sdk --strip-components=1
elif [ "${{ env.SDK_EXT }}" == "tar.xz" ]; then
mkdir sdk && tar -xvf $file_name -C ./sdk --strip-components=1
fi
cd sdk
echo "src-git base https://github.com/openwrt/openwrt.git;main" > feeds.conf
echo "src-git packages https://github.com/openwrt/packages.git;master" >> feeds.conf
echo "src-git luci https://github.com/openwrt/luci.git;master" >> feeds.conf
echo "src-git routing https://git.openwrt.org/feed/routing.git;master" >> feeds.conf
./scripts/feeds update -a
./scripts/feeds install -a
cd ..
echo "src-link qmodem `pwd`/qmodem" >> sdk/feeds.conf
cd sdk
./scripts/feeds update qmodem
./scripts/feeds install -a -p qmodem
echo "CONFIG_ALL_NONSHARED=n" > .config
echo "CONFIG_ALL_KMODS=n" >> .config
echo "CONFIG_ALL=n" >> .config
echo "CONFIG_AUTOREMOVE=n" >> .config
echo "CONFIG_LUCI_LANG_zh_Hans=y" >> .config
cat ../qmodem/.github/workflows/openwrt_package.config >> .config
make defconfig
make clean
make download -j$(nproc) || true
- name: Compile QModem
id: compile
run: |
cd sdk
./scripts/feeds update qmodem
./scripts/feeds install -a -p qmodem
generic_package=$(cat ../qmodem/.github/workflows/qmodem_package_generic)
arch_package=$(cat ../qmodem/.github/workflows/qmodem_package_arch)
for package in $generic_package; do
make package/$package/compile -j$(nproc) || true
done
for package in $arch_package; do
make package/$package/compile -j$(nproc) || true
done
ls bin/packages/${{ env.SDK_ARCH }}/qmodem/
echo "status=success" >> $GITHUB_OUTPUT
echo "FIRMWARE=$(pwd)/bin/packages/${{ env.SDK_ARCH }}/qmodem/" >> $GITHUB_ENV
- name: Upload QModem
if: ${{ steps.compile.outputs.status == 'success' }}
uses: actions/upload-artifact@v4
with:
name: QModem-${{ matrix.build_arch }}
path: ${{ env.FIRMWARE }}*
retention-days: 7
job_release_artifacts:
name: Release Artifacts
needs: [job_build_qmodem, job_prepare]
runs-on: ubuntu-latest
if: ${{ needs.job_prepare.outputs.push_type == 'tag' }}
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Download Release Note
uses: actions/download-artifact@v4
with:
name: Release Note
path: release_note
- name: Create releases directory
run: mkdir -p releases
- name: Package artifacts into tar.gz
run: |
for dir in artifacts/*; do
if [ -d "$dir" ]; then
base_name=$(basename "$dir")
tar -czf "releases/${base_name}.tar.gz" -C "$dir" .
fi
done
- name: Create GitHub Release
uses: softprops/action-gh-release@v2.2.2
if: ${{ needs.job_prepare.outputs.push_type == 'tag' }}
with:
body_path: release_note/release_note.md
generate_release_notes: true
tag_name: ${{ needs.job_prepare.outputs.tag_name }}
prerelease: ${{ contains(needs.job_prepare.outputs.tag_name, '-beta') || contains(needs.job_prepare.outputs.tag_name, '-rc') }}
files: releases/*