Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
修改了 CI
Browse files Browse the repository at this point in the history
- 增引入了 Costura.fody 来实现单文件
- 将 build 逻辑单独放到了 ps 脚本里
  • Loading branch information
Jenway committed Feb 27, 2024
1 parent 65f0dca commit 0c0aa26
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 112 deletions.
50 changes: 50 additions & 0 deletions .github/utils/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
param(
[string]$SolutionPath = "SduNetCheckTool.sln",
[string]$Configuration = "Debug",
[string]$Platform = "x64",
[string]$RuntimeIdentifier = "win-x64"
)

# 函数用于检测是否安装了需要的工具和依赖
function CheckPrerequisites {
Write-Host "Checking prerequisites for build..."

# 检测 MSBuild
if (-not (Get-Command -Name "msbuild" -ErrorAction SilentlyContinue)) {
Write-Host "MSBuild is not installed or not in PATH. Please install MSBuild." -ForegroundColor Red
exit 1
}

Write-Host "Prerequisites check passed for build."
}

# 函数用于构建项目
function BuildProject {
# 使用 MSBuild 进行 WPF 应用程序的恢复
$restoreArgs = "/t:Restore /p:Configuration=$Configuration /p:Platform=$Platform /p:RuntimeIdentifier=$RuntimeIdentifier"
$restoreCommand = "msbuild $SolutionPath $restoreArgs"

Write-Host "`n Restoring WPF project... `n" -ForegroundColor Cyan
Write-Host "$ $restoreCommand `n"
Invoke-Expression $restoreCommand


# 构建 wapproj 项目
$buildArgs = "/p:Configuration=$Configuration /p:Platform=$Platform /p:RuntimIdentifier=$RuntimeIdentifier /p:UapAppxPackageBuildMode=StoreUpload /p:AppxBundle=Never /p:GenerateAppInstallerFile=False /p:AppxPackageSigningEnabled=False"
$buildCommand = "msbuild $SolutionPath $buildArgs"
Write-Host "`n Building WPF project... `n" -ForegroundColor Cyan
Write-Host "$ $buildCommand `n"
Invoke-Expression $buildCommand

}


# 检查先决条件
CheckPrerequisites

# 构建项目
BuildProject

Write-Host "Build completed."

Write-Host "Build result: SDUNetCheckTool.GUI\bin\$Platform\$Configuration\SDUNetCheckTool.GUI.exe"
Binary file removed .github/utils/enigmavbconsole.exe
Binary file not shown.
30 changes: 0 additions & 30 deletions .github/utils/pack.js

This file was deleted.

52 changes: 0 additions & 52 deletions .github/utils/package-lock.json

This file was deleted.

5 changes: 0 additions & 5 deletions .github/utils/package.json

This file was deleted.

36 changes: 13 additions & 23 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,41 @@ jobs:
env:
# artifacts 命名 [名字]-[build-number]-[commit-hash]
artifactName: SduNetCheckTool-build.${{github.run_number}}-${{ github.sha }}
appPackagesArchive: SduNetCheckTool-build.${{github.run_number}}-${{ github.sha }}.zip
appPackagesExecutable: SduNetCheckTool-build.${{github.run_number}}-${{ github.sha }}.exe

solutionPath: SduNetCheckTool.sln
coreProjectDirectory: SduNetCheckTool.Core
guiProjectDirectory: SduNetCheckTool.GUI
coreProjectPath: SduNetCheckTool.Core\SduNetCheckTool.Core.csproj
guiProjectPath: SduNetCheckTool.GUI\SduNetCheckTool.GUI.csproj
Platform: x64
Configuration: Release
appPackagesDirectory: bin\x64\Release
RuntimeIdentifier: win-x64
# appPackagesDirectory: bin\x64\Release
appPackagesDirectory: bin\$env:Platform\$env:Configuration


steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/setup-dotnet@v4
with:
node-version: 18
dotnet-version: '3.1.x'

- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2

# - name: Add Costura.Fody
# run: dotnet add .\SduNetCheckTool.GUI\SduNetCheckTool.GUI.csproj package Costura.Fody

- name: Restore the Wpf application
run: msbuild ${{ env.solutionPath }} /t:Restore /p:Configuration=Release /p:Platform=x64 /p:RuntimeIdentifier=win-x64

- name: Build wapproj
run: msbuild ${{ env.solutionPath }} /p:Configuration=${{env.Configuration}} /p:Platform=x64 /p:RuntimIdentifier=win /p:UapAppxPackageBuildMode=StoreUpload /p:AppxBundle=Never /p:GenerateAppInstallerFile=False /p:AppxPackageSigningEnabled=False
- name: Restore and build the Wpf application
run: ./.github/utils/build.ps1 -SolutionPath ${{ env.solutionPath }} -Configuration ${{ env.Configuration }} -Platform ${{ env.Platform }} -RuntimeIdentifier ${{ env.RuntimeIdentifier }}

- name: Create archive
- name: Rename file
run: |
mkdir build
Compress-Archive -Path ${{ env.guiProjectDirectory }}\${{ env.appPackagesDirectory }}\* -DestinationPath build\${{ env.appPackagesArchive }}
- name: Pack into single file executable
run: |
cd .\.github\utils\
npm install
node pack.js
cd -
Move-Item build\SduNetCheckTool.GUI_boxed.exe build\${{ env.appPackagesExecutable }}
Compress-Archive -Path ${{ env.guiProjectDirectory }}\${{ env.appPackagesDirectory }}\app.publish\SduNetCheckTool.GUI.exe -DestinationPath build\${{ env.appPackagesExecutable }}
- name: 'Upload Artifact'
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifactName }}
path: |
build/${{ env.appPackagesArchive }}
build/${{ env.appPackagesExecutable }}
retention-days: 15
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ jobs:
- name: Display Artifact
run: |
ls -l
mv ${{ env.artifact_name }}.zip SduNetCheckTool-${{ github.ref_name }}.zip
mv ${{ env.artifact_name }}.exe SduNetCheckTool-${{ github.ref_name }}.exe
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
SduNetCheckTool-${{ github.ref_name }}.zip
SduNetCheckTool-${{ github.ref_name }}.exe
LICENSE.txt
tag_name: ${{ github.ref_name }}
Expand Down
1 change: 1 addition & 0 deletions SduNetCheckTool.Core/SduNetCheckTool.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<PlatformTarget>x64</PlatformTarget>
<LangVersion>preview</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ConcurrencyRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
Expand Down
3 changes: 3 additions & 0 deletions SduNetCheckTool.GUI/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura />
</Weavers>
5 changes: 5 additions & 0 deletions SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Costura.Fody">
<Version>5.7.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
<Version>8.0.0</Version>
</PackageReference>
Expand Down

0 comments on commit 0c0aa26

Please sign in to comment.