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

Commit

Permalink
Merge pull request #2 from Jenway/dev
Browse files Browse the repository at this point in the history
修改了 CI
  • Loading branch information
Jenway authored Feb 26, 2024
2 parents 886b8f8 + b246d37 commit 03284f5
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 29 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"
70 changes: 51 additions & 19 deletions .github/utils/pack.js
Original file line number Diff line number Diff line change
@@ -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;
}
});
1 change: 1 addition & 0 deletions .github/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "module",
"devDependencies": {
"generate-evb": "git+ssh://[email protected]:Jenway/generate-evb"
}
Expand Down
18 changes: 8 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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: |
Expand All @@ -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'
Expand Down

0 comments on commit 03284f5

Please sign in to comment.