From 47f6024305748be20f064e702e8124165b40a851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=8C=AF=E4=BC=9F?= Date: Mon, 26 Feb 2024 23:14:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 build 逻辑单独放到了 ps 脚本里 --- .github/utils/build.ps1 | 50 +++++++++++++++++++++++++++++++++ .github/utils/pack.js | 56 +++++++++++++++++++++++++++++-------- .github/workflows/build.yml | 18 ++++++------ 3 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 .github/utils/build.ps1 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..61e60cd 100644 --- a/.github/utils/pack.js +++ b/.github/utils/pack.js @@ -2,22 +2,56 @@ var fs = require('fs'); var child_process = require('child_process'); var generateEvb = require('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(); + +// Generate EVB +generateEvb(options.projectName, options.inputExe, options.outputExe, options.path2Pack); -child_process.execFile(evbCliPath, [projectName], function (err, stdout, stderr) { +// Execute EVB CLI +child_process.execFile(options.evbCliPath, [options.projectName], function (err, stdout, stderr) { var 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; + if (fs.existsSync(options.outputExe)) { + success = fs.statSync(options.outputExe).size > fs.statSync(options.inputExe).size; } if (!success) { @@ -25,6 +59,6 @@ child_process.execFile(evbCliPath, [projectName], function (err, stdout, stderr) } } if (err) { - throw err; + throw err; } }); 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'