Skip to content

Commit

Permalink
refactor(build): 重构构建发布流 (#18)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
DuckDuckStudio and fjwxzde authored Jan 22, 2025
1 parent dfd6966 commit c282927
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 146 deletions.
104 changes: 61 additions & 43 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,92 +11,110 @@ jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, windows-latest]
arch: [x86, x64, arm, arm64, amd64]

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

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

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

- name: 更新版本号
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
env:
PYTHONIOENCODING: utf-8
run: |
python "auto-scripts/Change-Version.py" "${{ github.event.inputs.version }}"
python "自动化脚本/修改版本号.py" "${{ github.event.inputs.version }}"
- name: 还原依赖
run: dotnet restore ghv/ghv.csproj
- name: 更新架构信息
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
env:
PYTHONIOENCODING: utf-8
run: |
python "自动化脚本/修改架构.py" "${{ matrix.arch }}"
- name: 构建
run: dotnet build ghv/ghv.csproj --configuration Release --no-restore
- name: 发布 - Windows - x64/x86/arm64/amd64
if: ${{ runner.os == 'Windows' && matrix.arch != 'arm' }}
run: |
dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r win-${{ matrix.arch }}
dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r win-${{ matrix.arch }} /p:PublishSingleFile=true /p:PublishTrimmed=true
- name: 发布
run: dotnet publish ghv/ghv.csproj --configuration Release --no-build --output ./output
- name: 发布 - linux - x64/arm/arm64/amd64
if: ${{ runner.os == 'Linux' && matrix.arch != 'x86' }}
run: |
dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r linux-${{ matrix.arch }}
dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r linux-${{ matrix.arch }} /p:PublishSingleFile=true /p:PublishTrimmed=true
- name: 创建发行文件 - Windows
if: runner.os == 'Windows'
if: ${{ runner.os == 'Windows' && matrix.arch != 'arm' }}
shell: pwsh
run: |
# 创建Release目录
mkdir -p Release
# 使用7z压缩为zip格式
7z a -tzip Release/GitHubView-${{ github.event.inputs.version }}-windows.zip output/*
7z a -tzip Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.zip output/*
# 创建安装包
curl -o "C:\Program Files (x86)\Inno Setup 6\Languages\ChineseSimplified.isl" "https://raw.githubusercontent.com/jrsoftware/issrc/main/Files/Languages/Unofficial/ChineseSimplified.isl"
iscc installer/Windows.iss
move installer/GitHubView-installer.exe Release/GitHubView-${{ github.event.inputs.version }}-Setup-windows.exe
iscc installer/SingleFile/Windows.iss
move installer/GitHubView-installer.exe Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}-Setup.exe
move installer/SingleFile/GitHubView-installer.exe Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}-Setup-SingleFile.exe
# 单独处理单文件
move output_SingleFile/ghv.exe Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}-SingleFile.exe
- name: 创建发行文件 - Linux
if: runner.os == 'Linux'
env:
MAINTAINER_EMAIL: ${{ secrets.Maintainer_Email }}
if: ${{ runner.os == 'Linux' && matrix.arch != 'x86' }}
shell: bash
run: |
# 创建Release目录
mkdir -p Release
mkdir -pv Release
echo "构建tar包..."
# 使用tar压缩
tar -czvf Release/GitHubView-${{ github.event.inputs.version }}-linux.tar.gz -C output .
# 安装 dpkg
sudo apt-get update
sudo apt-get install -y dpkg
# 创建 DEBIAN 目录和控制文件
mkdir -p output/DEBIAN
echo 'Package: GitHubView' > output/DEBIAN/control
echo 'Version: ${{ github.event.inputs.version }}' >> output/DEBIAN/control
echo 'Section: base' >> output/DEBIAN/control
echo 'Priority: optional' >> output/DEBIAN/control
echo 'Architecture: all' >> output/DEBIAN/control
echo "Maintainer: 鸭鸭「カモ」 <${MAINTAINER_EMAIL}>" >> output/DEBIAN/control
echo 'Description: GHV Application' >> output/DEBIAN/control
# 生成安装包
dpkg --build output ghv.deb
mv ghv.deb Release/GitHubView-${{ github.event.inputs.version }}-linux.deb
tar -czvf Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz -C output .
- name: 创建发行文件 - macOS
if: runner.os == 'macOS'
run: |
# 创建Release目录
mkdir -p Release
# =======================================================
echo "构建DEB包..."
mkdir -pv output_SingleFile/usr/local/bin/
cp -pv output_SingleFile/ghv output_SingleFile/usr/local/bin/
# 使用tar压缩
tar -czvf Release/GitHubView-${{ github.event.inputs.version }}-macos.tar.gz -C output .
# 复制 DEBIAN 控制文件
cp -rpv installer/SingleFile/DEBIAN output_SingleFile
# 创建安装包
pkgbuild --root ./output --identifier DuckStudio.GitHubView --version ${{ github.event.inputs.version }} --install-location /Applications --scripts ./output GitHubView.pkg
mv GitHubView.pkg Release/GitHubView-${{ github.event.inputs.version }}-macos.pkg
# 生成安装包
dpkg --build output_SingleFile ghv.deb
mv -v ghv.deb Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.deb
# 验证安装包
dpkg --info Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.deb
dpkg --contents Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.deb
# =======================================================
echo "发布单文件..."
# 单独处理单文件
mv -v output_SingleFile/ghv Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}-SingleFile
- name: 上传发行文件
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
uses: actions/upload-artifact@v4
with:
name: ghv-${{ matrix.os }}
name: ghv-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}
path: ./Release
118 changes: 64 additions & 54 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,109 +9,119 @@ on:
workflow_dispatch:

jobs:
build:
build-nightly:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, windows-latest]
arch: [x86, x64, arm, arm64, amd64]

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

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

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

- name: 生成版本号 - Unix
if: runner.os == 'Linux' || runner.os == 'macOS'
- name: 生成版本号
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
shell: bash
run: |
echo "NIGHTLY_VERSION=$(date +'%Y.%m.%d').${{ github.run_id }}" >> $GITHUB_ENV
echo "Generated version: $NIGHTLY_VERSION"
- name: 生成版本号 - Windows
if: runner.os == 'Windows'
run: |
$date = Get-Date -Format "yyyy.MM.dd"
$version = "$date.${{ github.run_id }}"
echo "NIGHTLY_VERSION=$version" >> $env:GITHUB_ENV
echo "Generated version: ${{ env.NIGHTLY_VERSION }}"
- name: 更新版本号
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
env:
PYTHONIOENCODING: utf-8
run: |
python "auto-scripts/Change-Version.py" "${{ env.NIGHTLY_VERSION }}"
python "自动化脚本/修改版本号.py" "${{ env.NIGHTLY_VERSION }}"
- name: 还原依赖
run: dotnet restore ghv/ghv.csproj
- name: 更新架构信息
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
env:
PYTHONIOENCODING: utf-8
run: |
python "自动化脚本/修改架构.py" "${{ matrix.arch }}"
- name: 构建
run: dotnet build ghv/ghv.csproj --configuration Release --no-restore
- name: 发布 - Windows - x64/x86/arm64/amd64
if: ${{ runner.os == 'Windows' && matrix.arch != 'arm' }}
run: |
dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r win-${{ matrix.arch }}
dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r win-${{ matrix.arch }} /p:PublishSingleFile=true /p:PublishTrimmed=true
- name: 发布
run: dotnet publish ghv/ghv.csproj --configuration Release --no-build --output ./output
- name: 发布 - linux - x64/arm/arm64/amd64
if: ${{ runner.os == 'Linux' && matrix.arch != 'x86' }}
run: |
dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r linux-${{ matrix.arch }}
dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r linux-${{ matrix.arch }} /p:PublishSingleFile=true /p:PublishTrimmed=true
- name: 创建发行文件 - Windows
if: runner.os == 'Windows'
if: ${{ runner.os == 'Windows' && matrix.arch != 'arm' }}
shell: pwsh
run: |
# 创建Release目录
mkdir -p Release
# 使用7z压缩为zip格式
7z a -tzip Release/GitHubView-${{ env.NIGHTLY_VERSION }}-windows.zip output/*
7z a -tzip Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.zip output/*
# 创建安装包
curl -o "C:\Program Files (x86)\Inno Setup 6\Languages\ChineseSimplified.isl" "https://raw.githubusercontent.com/jrsoftware/issrc/main/Files/Languages/Unofficial/ChineseSimplified.isl"
iscc installer/Windows.iss
move installer/GitHubView-installer.exe Release/GitHubView-${{ env.NIGHTLY_VERSION }}-Setup-windows.exe
iscc installer/SingleFile/Windows.iss
move installer/GitHubView-installer.exe Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}-Setup.exe
move installer/SingleFile/GitHubView-installer.exe Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}-Setup-SingleFile.exe
# 单独处理单文件
move output_SingleFile/ghv.exe Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}-SingleFile.exe
- name: 创建发行文件 - Linux
if: runner.os == 'Linux'
env:
MAINTAINER_EMAIL: ${{ secrets.Maintainer_Email }}
if: ${{ runner.os == 'Linux' && matrix.arch != 'x86' }}
shell: bash
run: |
# 创建Release目录
mkdir -p Release
mkdir -pv Release
echo "构建tar包..."
# 使用tar压缩
tar -czvf Release/GitHubView-${{ env.NIGHTLY_VERSION }}-linux.tar.gz -C output .
# 安装 dpkg
sudo apt-get update
sudo apt-get install -y dpkg
# 创建 DEBIAN 目录和控制文件
mkdir -p output/DEBIAN
echo 'Package: GitHubView' > output/DEBIAN/control
echo 'Version: ${{ env.NIGHTLY_VERSION }}' >> output/DEBIAN/control
echo 'Section: base' >> output/DEBIAN/control
echo 'Priority: optional' >> output/DEBIAN/control
echo 'Architecture: all' >> output/DEBIAN/control
echo "Maintainer: 鸭鸭「カモ」 <${MAINTAINER_EMAIL}>" >> output/DEBIAN/control
echo 'Description: GHV Application' >> output/DEBIAN/control
# 生成安装包
dpkg --build output ghv.deb
mv ghv.deb Release/GitHubView-${{ env.NIGHTLY_VERSION }}-linux.deb
tar -czvf Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz -C output .
- name: 创建发行文件 - macOS
if: runner.os == 'macOS'
run: |
# 创建Release目录
mkdir -p Release
# =======================================================
echo "构建DEB包..."
mkdir -pv output_SingleFile/usr/local/bin/
cp -pv output_SingleFile/ghv output_SingleFile/usr/local/bin/
# 使用tar压缩
tar -czvf Release/GitHubView-${{ env.NIGHTLY_VERSION }}-macos.tar.gz -C output .
# 复制 DEBIAN 控制文件
cp -rpv installer/SingleFile/DEBIAN output_SingleFile
# 创建安装包
pkgbuild --root ./output --identifier DuckStudio.GitHubView --version ${{ env.NIGHTLY_VERSION }} --install-location /Applications --scripts ./output GitHubView.pkg
mv GitHubView.pkg Release/GitHubView-${{ env.NIGHTLY_VERSION }}-macos.pkg
# 生成安装包
dpkg --build output_SingleFile ghv.deb
mv -v ghv.deb Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.deb
# 验证安装包
dpkg --info Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.deb
dpkg --contents Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.deb
# =======================================================
echo "发布单文件..."
# 单独处理单文件
mv -v output_SingleFile/ghv Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}-SingleFile
- name: 发布 Nightly 版本
uses: softprops/action-gh-release@v2
if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }}
with:
name: GitHubView Nightly Release (${{ env.NIGHTLY_VERSION }})
tag_name: ${{ env.NIGHTLY_VERSION }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,7 @@ FodyWeavers.xsd
# Debug Config
launchSettings.json
.editorconfig

# TEST
test.yml
test.py
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
dotnet run --project ghv <命令或参数>
```

### 构建发布
> 只是 .NET 把这个步骤叫做发布,不是 LICENSE 的例外。

```bash
dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r 系统-架构
dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r 系统-架构 /p:PublishSingleFile=true /p:PublishTrimmed=true # 单文件
# 有关架构信息,请查看: https://aka.ms/netsdk1083
```

## 报告问题

如果您发现了一个问题,请通过 GitHub Issues 报告。请提供尽可能详细的信息,以帮助我们重现和解决问题。
Expand Down
45 changes: 0 additions & 45 deletions auto-scripts/Change-Version.py

This file was deleted.

Loading

0 comments on commit c282927

Please sign in to comment.