-
-
Notifications
You must be signed in to change notification settings - Fork 271
179 lines (141 loc) · 4.87 KB
/
pkg-deb.yml
File metadata and controls
179 lines (141 loc) · 4.87 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
# ---------------------------------------------------------------
# Workflow File : pkg-deb.yml
# File Authors : sanchuanhehe <wyihe5520@gmail.com>
# Contributors : 曾奥然 <ccmywish@qq.com>
# |
# Created On : <2025-06-10>
# Last Modified : <2025-10-29>
#
# Build and publish deb packages
# ---------------------------------------------------------------
name: 构建发布deb包
on:
release:
types: [ released ]
push:
branches: [ "gh-build" ]
workflow_dispatch:
inputs:
version:
description: 'Version to build'
required: true
default: '0.3.0' # 短暂时间内不可达到的最新版本号
jobs:
Build-deb:
name: 构建deb包
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v6
with:
ref: gh-build
- name: 获取版本号
id: get_version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
version="${{ github.event.release.tag_name }}"
# 删除前缀 'v' if present
version=${version#v}
elif [ "${{ github.event_name }}" = "push" ];then
# 从源代码中提取版本号
version=$(sed -E -n 's/^#define Chsrc_Version +"([0-9]+\.[0-9]+\.[0-9]+).*"/\1/p' ./src/framework/version.h)
else
version="${{ github.event.inputs.version }}"
fi
echo "version=$version" >> $GITHUB_OUTPUT
echo "Version: $version"
- name: 验证版本号
run: |
version="${{ steps.get_version.outputs.version }}"
if [[ ! $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format: $version"
exit 1
fi
- name: 更新 debian/changelog
run: |
version="${{ steps.get_version.outputs.version }}"
cd ./pkg/deb
(cat << EOF; cat ./debian/changelog) > new_changelog
chsrc ($version-1) unstable; urgency=medium
* Release version $version
-- 曾奥然 <ccmywish@qq.com> $(date -R)
EOF
mv -f new_changelog ./debian/changelog
- name: 安装构建依赖
run: |
sudo apt-get update
sudo apt-get install -y debhelper devscripts build-essential fakeroot
- name: 构建
run: |
make build-deb
- name: 移动构建产物到./dist和./dist-for-pre
run: |
version="${{ steps.get_version.outputs.version }}"
# 创建两个目录来存放构建产物(产物内容一样,只是文件名不一样)
mkdir dist dist-for-pre
find ./pkg -name "chsrc_${version}*.deb" -exec mv {} dist/ \;
cp -r dist/* dist-for-pre/
# 上传至 'pre' release 的文件名需要设置为 'latest', 从而稳定下载URL
cd ./dist-for-pre
for old_name in ./chsrc_${version}*.deb; do
new_name="${old_name/${version}-1/latest-1}"
mv "$old_name" "$new_name"
done
- name: 验证生成的deb包
run: |
version="${{ steps.get_version.outputs.version }}"
ls -la dist/
dpkg-deb --info dist/chsrc_${version}-1_amd64.deb
dpkg-deb --contents dist/chsrc_${version}-1_amd64.deb
- name: 测试deb包能否正常安装
run: |
version="${{ steps.get_version.outputs.version }}"
sudo dpkg -i dist/chsrc_${version}-1_amd64.deb || true
sudo apt-get install -f -y || true
bash pkg/deb/deb-installation-test.sh
- name: 上传deb包到artifacts
uses: actions/upload-artifact@v6
with:
name: chsrc-deb-files
path: dist/chsrc_*.deb
retention-days: 30
- name: 上传附件到GitHub Releases(the newly created release)
if: github.event_name == 'release'
uses: softprops/action-gh-release@v2
with:
# 用 * 省略版本号,以及指代各种架构
files: dist/chsrc_*.deb
- name: 上传附件到GitHub Releases(the 'pre' release)
if: github.event_name == 'push'
uses: softprops/action-gh-release@v2
with:
tag_name: pre
# 用 * 指代各种架构
files: dist-for-pre/chsrc_latest-1_*.deb
Create-APT-repository:
name: 创建APT仓库
needs: Build-deb
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- name: Download all artifacts
uses: actions/download-artifact@v7
with:
pattern: chsrc-deb-files
merge-multiple: true
path: ./debs
- name: Install repository tools
run: |
sudo apt-get update
sudo apt-get install -y dpkg-dev
- name: Create Packages file
run: |
cd debs
dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
dpkg-scanpackages . /dev/null > Packages
- name: Upload repository metadata
uses: actions/upload-artifact@v6
with:
name: debian-repository-metadata
path: debs/Packages*
retention-days: 30