diff --git a/.github/utils/build.ps1 b/.github/utils/build.ps1 new file mode 100644 index 0000000..07c0d97 --- /dev/null +++ b/.github/utils/build.ps1 @@ -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" diff --git a/.github/utils/pack.js b/.github/utils/pack.js index 5512815..4283cb3 100644 --- a/.github/utils/pack.js +++ b/.github/utils/pack.js @@ -1,30 +1,62 @@ -var fs = require('fs'); -var child_process = require('child_process'); -var generateEvb = require('generate-evb'); +import { existsSync, statSync } from 'fs'; +import { execFile } from 'child_process'; +import generateEvb from 'generate-evb'; -// Change the following paths to the actual paths used in your project -var evbCliPath = 'enigmavbconsole.exe'; -var projectName = 'SDUNetCheckTool.evb'; -var inputExe = '../../SduNetCheckTool.GUI/bin/x64/Release/SduNetCheckTool.GUI.exe'; -var outputExe = '../../build/SduNetCheckTool.GUI_boxed.exe'; -var path2Pack = '../../SduNetCheckTool.GUI/bin/x64/Release'; +// Function to parse command line arguments +function parseArgs() { + const args = process.argv.slice(2); + const options = { + evbCliPath: 'enigmavbconsole.exe', + projectName: 'SDUNetCheckTool.evb', + inputExe: 'SduNetCheckTool.GUI/bin/x64/Release/SduNetCheckTool.GUI.exe', + outputExe: 'build/SduNetCheckTool.GUI_boxed.exe', + path2Pack: 'SduNetCheckTool.GUI/bin/x64/Release' + }; -generateEvb(projectName, inputExe, outputExe, path2Pack); + args.forEach((arg, index) => { + switch (arg) { + case '-evbCliPath': + options.evbCliPath = args[index + 1]; + break; + case '-projectName': + options.projectName = args[index + 1]; + break; + case '-inputExe': + options.inputExe = args[index + 1]; + break; + case '-outputExe': + options.outputExe = args[index + 1]; + break; + case '-path2Pack': + options.path2Pack = args[index + 1]; + break; + default: + break; + } + }); + + return options; +} + +// Parse command line arguments +const options = parseArgs(); -child_process.execFile(evbCliPath, [projectName], function (err, stdout, stderr) { - var success = false; +// Generate EVB +generateEvb(options.projectName, options.inputExe, options.outputExe, options.path2Pack); + +// Execute EVB CLI +execFile(options.evbCliPath, [options.projectName], function (err, stdout, stderr) { + let success = false; if (!err) { - // Sanity check (change this to what works for you): - // Check if the output file exists and if it's bigger than the input file - if (fs.existsSync(outputExe)) { - success = fs.statSync(outputExe).size > fs.statSync(inputExe).size; + // Sanity check: Check if the output file exists and if it's bigger than the input file + if (existsSync(options.outputExe)) { + success = statSync(options.outputExe).size > statSync(options.inputExe).size; } - if (!success) { - err = new Error('Failed to pack EVB project!\nEVB stdout:\n' + stdout + '\nEVB stderr:\n' + stderr); + err = new Error(`Failed to pack EVB project!\nEVB stdout:\n${stdout}\nEVB stderr:\n${stderr}`); } } if (err) { - throw err; + throw err; } }); diff --git a/.github/utils/package.json b/.github/utils/package.json index c2c186c..e6623f0 100644 --- a/.github/utils/package.json +++ b/.github/utils/package.json @@ -1,4 +1,5 @@ { + "type": "module", "devDependencies": { "generate-evb": "git+ssh://git@github.com:Jenway/generate-evb" } diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4e262ce..cee476b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,8 +30,11 @@ jobs: 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: @@ -43,11 +46,8 @@ jobs: - name: Setup MSBuild.exe uses: microsoft/setup-msbuild@v2 - - 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: | @@ -56,10 +56,8 @@ jobs: - name: Pack into single file executable run: | - cd .\.github\utils\ - npm install - node pack.js - cd - + npm install .\.github\utils\ + node .\.github\utils\pack.js Move-Item build\SduNetCheckTool.GUI_boxed.exe build\${{ env.appPackagesExecutable }} - name: 'Upload Artifact'