Skip to content

Commit c282927

Browse files
refactor(build): 重构构建发布流 (#18)
* fix?(build): 修复 [BUG]: ghv被默认装到了根目录而不是一些常简的目录 #16 * Apply suggestions from code review Co-authored-by: 宁静致远 <[email protected]> * Apply suggestions from code review Co-authored-by: 宁静致远 <[email protected]> * Apply suggestions from code review Co-authored-by: 宁静致远 <[email protected]> * Apply suggestions from code review Co-authored-by: 宁静致远 <[email protected]> * pref(py): 优化版本替换脚本 * pref(deb-linux): 优化 DEB 包控制文件 * fix(build): 修复目录嵌套问题 * fix(deb): 修正 DEB 包控制文件错误 * fix(build): 移除多余的 mkdir * refactor(build): 重构构建发布流 * fix(py): 修正错误的路径 * fix(RID): 更正发布时的系统名 更多请见:https://learn.microsoft.com/zh-cn/dotnet/core/compatibility/sdk/8.0/rid-graph * fix(sync): 同步修改到 Nightly 构建流中 * fix(action): 排除 Linux x86 架构以避免错误 * fix(action): 对于上一个提交的更多处理 * fix(iss): 使用绝对路径来修复编译问题 * fix(dotnet): 排除 Windows arm * fix: 修正路径问题 * fix: 修复文件不存在的问题 * fix(mv): 修复找不到安装程序的问题 * fix(linux): 在 Linux 上仅打包单文件发布为deb * fix(py): 更正替换规则 * fix(dpkg): 移除多余的 dpkg 安装 * fix(arch): x64 ≠ amd64 * fix(py): 更正架构错误 * Apply suggestions from code review Co-authored-by: 宁静致远 <[email protected]> * docs: 更新贡献文档 --------- Co-authored-by: 宁静致远 <[email protected]>
1 parent dfd6966 commit c282927

File tree

10 files changed

+255
-146
lines changed

10 files changed

+255
-146
lines changed

.github/workflows/build.yml

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,92 +11,110 @@ jobs:
1111
build:
1212
runs-on: ${{ matrix.os }}
1313
strategy:
14+
fail-fast: false
1415
matrix:
15-
os: [ubuntu-latest, windows-latest, macos-latest]
16+
os: [ubuntu-latest, windows-latest]
17+
arch: [x86, x64, arm, arm64, amd64]
1618

1719
steps:
1820
- name: 检出代码
21+
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
1922
uses: actions/checkout@v4
2023

2124
- name: 设置 .NET 8.0.x
25+
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
2226
uses: actions/setup-dotnet@v4
2327
with:
2428
dotnet-version: '8.0.x'
2529

2630
- name: 设置 Python 3.x
31+
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
2732
uses: actions/setup-python@v5
2833
with:
2934
python-version: '3.x'
3035

3136
- name: 更新版本号
37+
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
38+
env:
39+
PYTHONIOENCODING: utf-8
3240
run: |
33-
python "auto-scripts/Change-Version.py" "${{ github.event.inputs.version }}"
41+
python "自动化脚本/修改版本号.py" "${{ github.event.inputs.version }}"
3442
35-
- name: 还原依赖
36-
run: dotnet restore ghv/ghv.csproj
43+
- name: 更新架构信息
44+
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
45+
env:
46+
PYTHONIOENCODING: utf-8
47+
run: |
48+
python "自动化脚本/修改架构.py" "${{ matrix.arch }}"
3749
38-
- name: 构建
39-
run: dotnet build ghv/ghv.csproj --configuration Release --no-restore
50+
- name: 发布 - Windows - x64/x86/arm64/amd64
51+
if: ${{ runner.os == 'Windows' && matrix.arch != 'arm' }}
52+
run: |
53+
dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r win-${{ matrix.arch }}
54+
dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r win-${{ matrix.arch }} /p:PublishSingleFile=true /p:PublishTrimmed=true
4055
41-
- name: 发布
42-
run: dotnet publish ghv/ghv.csproj --configuration Release --no-build --output ./output
56+
- name: 发布 - linux - x64/arm/arm64/amd64
57+
if: ${{ runner.os == 'Linux' && matrix.arch != 'x86' }}
58+
run: |
59+
dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r linux-${{ matrix.arch }}
60+
dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r linux-${{ matrix.arch }} /p:PublishSingleFile=true /p:PublishTrimmed=true
4361
4462
- name: 创建发行文件 - Windows
45-
if: runner.os == 'Windows'
63+
if: ${{ runner.os == 'Windows' && matrix.arch != 'arm' }}
64+
shell: pwsh
4665
run: |
4766
# 创建Release目录
4867
mkdir -p Release
4968
5069
# 使用7z压缩为zip格式
51-
7z a -tzip Release/GitHubView-${{ github.event.inputs.version }}-windows.zip output/*
70+
7z a -tzip Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.zip output/*
5271
5372
# 创建安装包
5473
curl -o "C:\Program Files (x86)\Inno Setup 6\Languages\ChineseSimplified.isl" "https://raw.githubusercontent.com/jrsoftware/issrc/main/Files/Languages/Unofficial/ChineseSimplified.isl"
5574
iscc installer/Windows.iss
56-
move installer/GitHubView-installer.exe Release/GitHubView-${{ github.event.inputs.version }}-Setup-windows.exe
75+
iscc installer/SingleFile/Windows.iss
76+
move installer/GitHubView-installer.exe Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}-Setup.exe
77+
move installer/SingleFile/GitHubView-installer.exe Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}-Setup-SingleFile.exe
78+
79+
# 单独处理单文件
80+
move output_SingleFile/ghv.exe Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}-SingleFile.exe
5781
5882
- name: 创建发行文件 - Linux
59-
if: runner.os == 'Linux'
60-
env:
61-
MAINTAINER_EMAIL: ${{ secrets.Maintainer_Email }}
83+
if: ${{ runner.os == 'Linux' && matrix.arch != 'x86' }}
84+
shell: bash
6285
run: |
6386
# 创建Release目录
64-
mkdir -p Release
87+
mkdir -pv Release
88+
89+
echo "构建tar包..."
6590
6691
# 使用tar压缩
67-
tar -czvf Release/GitHubView-${{ github.event.inputs.version }}-linux.tar.gz -C output .
68-
69-
# 安装 dpkg
70-
sudo apt-get update
71-
sudo apt-get install -y dpkg
72-
# 创建 DEBIAN 目录和控制文件
73-
mkdir -p output/DEBIAN
74-
echo 'Package: GitHubView' > output/DEBIAN/control
75-
echo 'Version: ${{ github.event.inputs.version }}' >> output/DEBIAN/control
76-
echo 'Section: base' >> output/DEBIAN/control
77-
echo 'Priority: optional' >> output/DEBIAN/control
78-
echo 'Architecture: all' >> output/DEBIAN/control
79-
echo "Maintainer: 鸭鸭「カモ」 <${MAINTAINER_EMAIL}>" >> output/DEBIAN/control
80-
echo 'Description: GHV Application' >> output/DEBIAN/control
81-
# 生成安装包
82-
dpkg --build output ghv.deb
83-
mv ghv.deb Release/GitHubView-${{ github.event.inputs.version }}-linux.deb
92+
tar -czvf Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz -C output .
8493
85-
- name: 创建发行文件 - macOS
86-
if: runner.os == 'macOS'
87-
run: |
88-
# 创建Release目录
89-
mkdir -p Release
94+
# =======================================================
95+
echo "构建DEB包..."
96+
mkdir -pv output_SingleFile/usr/local/bin/
97+
cp -pv output_SingleFile/ghv output_SingleFile/usr/local/bin/
9098
91-
# 使用tar压缩
92-
tar -czvf Release/GitHubView-${{ github.event.inputs.version }}-macos.tar.gz -C output .
99+
# 复制 DEBIAN 控制文件
100+
cp -rpv installer/SingleFile/DEBIAN output_SingleFile
93101
94-
# 创建安装包
95-
pkgbuild --root ./output --identifier DuckStudio.GitHubView --version ${{ github.event.inputs.version }} --install-location /Applications --scripts ./output GitHubView.pkg
96-
mv GitHubView.pkg Release/GitHubView-${{ github.event.inputs.version }}-macos.pkg
102+
# 生成安装包
103+
dpkg --build output_SingleFile ghv.deb
104+
mv -v ghv.deb Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.deb
105+
106+
# 验证安装包
107+
dpkg --info Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.deb
108+
dpkg --contents Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.deb
109+
110+
# =======================================================
111+
echo "发布单文件..."
112+
# 单独处理单文件
113+
mv -v output_SingleFile/ghv Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}-SingleFile
97114
98115
- name: 上传发行文件
116+
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
99117
uses: actions/upload-artifact@v4
100118
with:
101-
name: ghv-${{ matrix.os }}
119+
name: ghv-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}
102120
path: ./Release

.github/workflows/nightly.yml

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,109 +9,119 @@ on:
99
workflow_dispatch:
1010

1111
jobs:
12-
build:
12+
build-nightly:
1313
runs-on: ${{ matrix.os }}
1414
strategy:
15+
fail-fast: false
1516
matrix:
16-
os: [ubuntu-latest, windows-latest, macos-latest]
17+
os: [ubuntu-latest, windows-latest]
18+
arch: [x86, x64, arm, arm64, amd64]
1719

1820
steps:
1921
- name: 检出代码
22+
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
2023
uses: actions/checkout@v4
2124

2225
- name: 设置 .NET 8.0.x
26+
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
2327
uses: actions/setup-dotnet@v4
2428
with:
2529
dotnet-version: '8.0.x'
2630

2731
- name: 设置 Python 3.x
32+
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
2833
uses: actions/setup-python@v5
2934
with:
3035
python-version: '3.x'
3136

32-
- name: 生成版本号 - Unix
33-
if: runner.os == 'Linux' || runner.os == 'macOS'
37+
- name: 生成版本号
38+
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
39+
shell: bash
3440
run: |
3541
echo "NIGHTLY_VERSION=$(date +'%Y.%m.%d').${{ github.run_id }}" >> $GITHUB_ENV
36-
echo "Generated version: $NIGHTLY_VERSION"
37-
38-
- name: 生成版本号 - Windows
39-
if: runner.os == 'Windows'
40-
run: |
41-
$date = Get-Date -Format "yyyy.MM.dd"
42-
$version = "$date.${{ github.run_id }}"
43-
echo "NIGHTLY_VERSION=$version" >> $env:GITHUB_ENV
44-
echo "Generated version: ${{ env.NIGHTLY_VERSION }}"
4542
4643
- name: 更新版本号
44+
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
45+
env:
46+
PYTHONIOENCODING: utf-8
4747
run: |
48-
python "auto-scripts/Change-Version.py" "${{ env.NIGHTLY_VERSION }}"
48+
python "自动化脚本/修改版本号.py" "${{ env.NIGHTLY_VERSION }}"
4949
50-
- name: 还原依赖
51-
run: dotnet restore ghv/ghv.csproj
50+
- name: 更新架构信息
51+
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
52+
env:
53+
PYTHONIOENCODING: utf-8
54+
run: |
55+
python "自动化脚本/修改架构.py" "${{ matrix.arch }}"
5256
53-
- name: 构建
54-
run: dotnet build ghv/ghv.csproj --configuration Release --no-restore
57+
- name: 发布 - Windows - x64/x86/arm64/amd64
58+
if: ${{ runner.os == 'Windows' && matrix.arch != 'arm' }}
59+
run: |
60+
dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r win-${{ matrix.arch }}
61+
dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r win-${{ matrix.arch }} /p:PublishSingleFile=true /p:PublishTrimmed=true
5562
56-
- name: 发布
57-
run: dotnet publish ghv/ghv.csproj --configuration Release --no-build --output ./output
63+
- name: 发布 - linux - x64/arm/arm64/amd64
64+
if: ${{ runner.os == 'Linux' && matrix.arch != 'x86' }}
65+
run: |
66+
dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r linux-${{ matrix.arch }}
67+
dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r linux-${{ matrix.arch }} /p:PublishSingleFile=true /p:PublishTrimmed=true
5868
5969
- name: 创建发行文件 - Windows
60-
if: runner.os == 'Windows'
70+
if: ${{ runner.os == 'Windows' && matrix.arch != 'arm' }}
71+
shell: pwsh
6172
run: |
6273
# 创建Release目录
6374
mkdir -p Release
6475
6576
# 使用7z压缩为zip格式
66-
7z a -tzip Release/GitHubView-${{ env.NIGHTLY_VERSION }}-windows.zip output/*
77+
7z a -tzip Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.zip output/*
6778
6879
# 创建安装包
6980
curl -o "C:\Program Files (x86)\Inno Setup 6\Languages\ChineseSimplified.isl" "https://raw.githubusercontent.com/jrsoftware/issrc/main/Files/Languages/Unofficial/ChineseSimplified.isl"
7081
iscc installer/Windows.iss
71-
move installer/GitHubView-installer.exe Release/GitHubView-${{ env.NIGHTLY_VERSION }}-Setup-windows.exe
82+
iscc installer/SingleFile/Windows.iss
83+
move installer/GitHubView-installer.exe Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}-Setup.exe
84+
move installer/SingleFile/GitHubView-installer.exe Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}-Setup-SingleFile.exe
85+
86+
# 单独处理单文件
87+
move output_SingleFile/ghv.exe Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}-SingleFile.exe
7288
7389
- name: 创建发行文件 - Linux
74-
if: runner.os == 'Linux'
75-
env:
76-
MAINTAINER_EMAIL: ${{ secrets.Maintainer_Email }}
90+
if: ${{ runner.os == 'Linux' && matrix.arch != 'x86' }}
91+
shell: bash
7792
run: |
7893
# 创建Release目录
79-
mkdir -p Release
94+
mkdir -pv Release
95+
96+
echo "构建tar包..."
8097
8198
# 使用tar压缩
82-
tar -czvf Release/GitHubView-${{ env.NIGHTLY_VERSION }}-linux.tar.gz -C output .
83-
84-
# 安装 dpkg
85-
sudo apt-get update
86-
sudo apt-get install -y dpkg
87-
# 创建 DEBIAN 目录和控制文件
88-
mkdir -p output/DEBIAN
89-
echo 'Package: GitHubView' > output/DEBIAN/control
90-
echo 'Version: ${{ env.NIGHTLY_VERSION }}' >> output/DEBIAN/control
91-
echo 'Section: base' >> output/DEBIAN/control
92-
echo 'Priority: optional' >> output/DEBIAN/control
93-
echo 'Architecture: all' >> output/DEBIAN/control
94-
echo "Maintainer: 鸭鸭「カモ」 <${MAINTAINER_EMAIL}>" >> output/DEBIAN/control
95-
echo 'Description: GHV Application' >> output/DEBIAN/control
96-
# 生成安装包
97-
dpkg --build output ghv.deb
98-
mv ghv.deb Release/GitHubView-${{ env.NIGHTLY_VERSION }}-linux.deb
99+
tar -czvf Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz -C output .
99100
100-
- name: 创建发行文件 - macOS
101-
if: runner.os == 'macOS'
102-
run: |
103-
# 创建Release目录
104-
mkdir -p Release
101+
# =======================================================
102+
echo "构建DEB包..."
103+
mkdir -pv output_SingleFile/usr/local/bin/
104+
cp -pv output_SingleFile/ghv output_SingleFile/usr/local/bin/
105105
106-
# 使用tar压缩
107-
tar -czvf Release/GitHubView-${{ env.NIGHTLY_VERSION }}-macos.tar.gz -C output .
106+
# 复制 DEBIAN 控制文件
107+
cp -rpv installer/SingleFile/DEBIAN output_SingleFile
108108
109-
# 创建安装包
110-
pkgbuild --root ./output --identifier DuckStudio.GitHubView --version ${{ env.NIGHTLY_VERSION }} --install-location /Applications --scripts ./output GitHubView.pkg
111-
mv GitHubView.pkg Release/GitHubView-${{ env.NIGHTLY_VERSION }}-macos.pkg
109+
# 生成安装包
110+
dpkg --build output_SingleFile ghv.deb
111+
mv -v ghv.deb Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.deb
112+
113+
# 验证安装包
114+
dpkg --info Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.deb
115+
dpkg --contents Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.deb
116+
117+
# =======================================================
118+
echo "发布单文件..."
119+
# 单独处理单文件
120+
mv -v output_SingleFile/ghv Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}-SingleFile
112121
113122
- name: 发布 Nightly 版本
114123
uses: softprops/action-gh-release@v2
124+
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
115125
with:
116126
name: GitHubView Nightly Release (${{ env.NIGHTLY_VERSION }})
117127
tag_name: ${{ env.NIGHTLY_VERSION }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,7 @@ FodyWeavers.xsd
365365
# Debug Config
366366
launchSettings.json
367367
.editorconfig
368+
369+
# TEST
370+
test.yml
371+
test.py

CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@
4444
dotnet run --project ghv <命令或参数>
4545
```
4646

47+
### 构建发布
48+
> 只是 .NET 把这个步骤叫做发布,不是 LICENSE 的例外。
49+
50+
```bash
51+
dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r 系统-架构
52+
dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r 系统-架构 /p:PublishSingleFile=true /p:PublishTrimmed=true # 单文件
53+
# 有关架构信息,请查看: https://aka.ms/netsdk1083
54+
```
55+
4756
## 报告问题
4857

4958
如果您发现了一个问题,请通过 GitHub Issues 报告。请提供尽可能详细的信息,以帮助我们重现和解决问题。

auto-scripts/Change-Version.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)