Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Forgot-Dream committed Feb 29, 2024
2 parents 029fa8b + 75aadad commit 172a3c5
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 122 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.

44 changes: 17 additions & 27 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
appPackagesExecutable: SduNetCheckTool-build.${{github.run_number}}-${{ github.sha }}.zip

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
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 }}
# - name: Rename file
# run: |
# mkdir build
# Compress-Archive -Path ${{ env.guiProjectDirectory }}\${{ env.appPackagesDirectory }}\ -DestinationPath build\${{ env.appPackagesExecutable }}

- name: 'Upload Artifact'
uses: actions/upload-artifact@v4
with:
name: ${{ env.artifactName }}
path: |
build/${{ env.appPackagesArchive }}
build/${{ env.appPackagesExecutable }}
SduNetCheckTool.GUI\bin\x64\Release\SduNetCheckTool.GUI.exe
retention-days: 15
12 changes: 4 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
build:
uses: ./.github/workflows/build.yml

relase:
release:
needs: build
runs-on: ubuntu-latest

Expand All @@ -24,21 +24,17 @@ jobs:
uses: actions/checkout@v2

- name: Download Artifact
uses: actions/download-artifact@v2
with:
name: ${{ env.artifact_name }}

uses: actions/download-artifact@v4

- 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
mv ${{env.artifact_name }}/SduNetCheckTool.GUI.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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
|CommunityToolkit.Mvvm|MIT|
|Microsoft.Extensions.DependencyInjection|MIT|
|ModernWpfUI|MIT|
|Costura.Fody|MIT|

## CI/CD

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>

0 comments on commit 172a3c5

Please sign in to comment.