Skip to content

Commit

Permalink
github action support
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed May 2, 2022
1 parent 3307115 commit 7cc4a9b
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 2 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: WinMenuCI
on:
push:
paths-ignore:
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
- "docs/**"
- "**.md"
- "**.txt"
- "!CMakeLists.txt"
- "LICENSE"
pull_request:
paths-ignore:
- "docs/**"
- "**.md"
- "**.txt"
- "!CMakeLists.txt"
- "LICENSE"
jobs:
build:
name: Build
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
target: [winmenu-win64,winmenu-arm64]
include:
- target: winmenu-win64
short_target: win64
- target: winmenu-arm64
short_target: arm64
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: compile-winmenu
run: pwsh -NoProfile -NoLogo -ExecutionPolicy unrestricted -File "./script/build.ps1" -Target "${{ matrix.short_target }}"
- name: Load PFX File from GitHub Secrets
if: startsWith(github.ref, 'refs/tags/')
id: savepfx
shell: pwsh
env:
BAULK_APPX_SIGNATURE_PFX: ${{ secrets.BAULK_APPX_SIGNATURE_PFX }}
run: |
$pfx_cert_byte = [System.Convert]::FromBase64String("$env:BAULK_APPX_SIGNATURE_PFX")
$currentDirectory = Get-Location
$certificatePath = Join-Path -Path $currentDirectory -ChildPath "build\Key.pfx"
[IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte)
Write-Host "Write $certificatePath success"
Get-Item $certificatePath
- name: Make Appx
if: startsWith(github.ref, 'refs/tags/')
run: pwsh -NoProfile -NoLogo -ExecutionPolicy unrestricted -File "./msix/makeAppx.ps1" -Target "${{ matrix.short_target }}"
- name: Publish Artifacts
uses: svenstaro/upload-release-action@v2
if: startsWith(github.ref, 'refs/tags/')
with:
file_glob: true
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: build/destination/*
tag: ${{ github.ref }}
overwrite: true
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.9
1.0.0
4 changes: 3 additions & 1 deletion msix/makeAppx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ if (Test-Path $BaulkAppxPfx) {
}

$Destination = Join-Path -Path $SourceRoot -ChildPath "build/destination"
Copy-Item -Force $MyAppxName -Destination $Destination
New-Item -ItemType Directory -Force -Path $Destination -ErrorAction Stop
Copy-Item -Force $MyAppxName -Destination $Destination
Get-ChildItem -Path $Destination
106 changes: 106 additions & 0 deletions script/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env pwsh
param(
[ValidateSet("win64", "arm64")]
[string]$Target = "win64"
)

$TargetWithHost64s = @{
"win64" = "amd64";
"arm64" = "amd64_arm64";
}

$TargetWithHost = $TargetWithHost64s[$Target]

Function Invoke-BatchFile {
param(
[Parameter(Mandatory = $true)]
[string] $Path,
[string] $Arguments
)
Set-StrictMode -Version Latest
$tempFile = [IO.Path]::GetTempFileName()

cmd.exe /c " `"$Path`" $Arguments && set > `"$tempFile`" " | Out-Host
## Go through the environment variables in the temp file.
## For each of them, set the variable in our local environment.
Get-Content $tempFile | ForEach-Object {
if ($_ -match "^(.*?)=(.*)$") {
Set-Content "env:\$($matches[1])" $matches[2]
}
}
Remove-Item $tempFile
}

Function Execute {
param(
[string]$FilePath,
[string]$Arguments,
[string]$WD
)
$ProcessInfo = New-Object System.Diagnostics.ProcessStartInfo
$ProcessInfo.FileName = $FilePath
if ([String]::IsNullOrEmpty($WD)) {
$ProcessInfo.WorkingDirectory = $PWD
}
else {
$ProcessInfo.WorkingDirectory = $WD
}
Write-Host "$FilePath $Arguments [$($ProcessInfo.WorkingDirectory)]"
#0x00000000 WindowStyle
$ProcessInfo.Arguments = $Arguments
$ProcessInfo.UseShellExecute = $false ## use createprocess not shellexecute
$Process = New-Object System.Diagnostics.Process
$Process.StartInfo = $ProcessInfo
try {
if ($Process.Start() -eq $false) {
return -1
}
$Process.WaitForExit()
}
catch {
return 127
}
return $Process.ExitCode
}


$VisualCxxBatchFiles = $(
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat",
"C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Auxiliary\Build\vcvarsall.bat",
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat"
)

$VisualCxxBatchFile = $null
foreach ($file in $VisualCxxBatchFiles) {
if (Test-Path $file) {
$VisualCxxBatchFile = $file
break
}
}
if ($null -eq $VisualCxxBatchFile) {
Write-Host -ForegroundColor Red "visual c++ vcvarsall.bat not found"
exit 1
}


Write-Host "call `"$VisualCxxBatchFile`" $TargetWithHost"

Invoke-BatchFile -Path $VisualCxxBatchFile -Arguments $TargetWithHost
$WD = Join-Path -Path $PWD -ChildPath "build"
try {
New-Item -ItemType Directory -Force -Path $WD
}
catch {
Write-Host -ForegroundColor Red "mkdir error $_"
exit 1
}
$env:CC = "cl"
$env:CXX = "cl"
$ExitCode = Execute -FilePath "cmake" -WD $WD -Arguments "-GNinja -DCMAKE_BUILD_TYPE=Release .."
if ($ExitCode -ne 0) {
exit $ExitCode
}
$ExitCode = Execute -FilePath "ninja" -WD $WD -Arguments "all"
if ($ExitCode -ne 0) {
exit $ExitCode
}

0 comments on commit 7cc4a9b

Please sign in to comment.