浏览代码

Update automated build for both x64 and arm64 platforms

Ruben 1 年之前
父节点
当前提交
b9f57ed70a
共有 4 个文件被更改,包括 256 次插入114 次删除
  1. 114 0
      .github/workflows/BuildWin32.yml
  2. 0 114
      .github/workflows/WinX64.yml
  3. 70 0
      Build/Build Avalonia.Win32 arm64.ps1
  4. 72 0
      Build/Build Avalonia.Win32.ps1

+ 114 - 0
.github/workflows/BuildWin32.yml

@@ -0,0 +1,114 @@
+name: Build and Publish PicView Avalonia
+
+on:
+  push:
+    branches:
+      - dev
+  pull_request:
+    branches:
+      - dev
+
+jobs:
+  build:
+    runs-on: windows-latest
+
+    steps:
+      # Step 1: Checkout the code
+      - name: Checkout repository
+        uses: actions/checkout@v4
+
+      # Step 2: Setup .NET 9 SDK
+      - name: Setup .NET 9 SDK
+        uses: actions/setup-dotnet@v4
+        with:
+          dotnet-version: '9.x'
+
+      # Step 3 (x64): Publish x64 version
+      - name: Publish x64 version
+        run: |
+          # Call the PowerShell script with x64 as the platform argument
+          pwsh -File "${{ github.workspace }}\Build Avalonia.Win32.ps1" -Platform "x64"
+        shell: pwsh
+
+      # Step 4 (x64): Upload the x64 zip file as an artifact
+      - name: Upload the x64 artifact
+        uses: actions/upload-artifact@v4
+        with:
+          name: PicView-v${{steps.get-version.outputs.file-version}}-win-x64
+          path: ${{ steps.paths.outputs.output_dir }}
+          retention-days: 14
+
+      # Step 5 (x64): Generate the Inno Setup Installer and copy x64 files to the build directory
+      - name: Generate Inno Setup variables and copy x64 files to Build directory
+        run: |
+          # Create the directory inside 'Build'
+          $buildDir = Join-Path -Path "${{ github.workspace }}" -ChildPath "Build\install"
+          if (Test-Path $buildDir) {
+            Remove-Item -Path $buildDir -Recurse -Force
+          }
+          New-Item -Path $buildDir -ItemType Directory | Out-Null
+
+          # Copy the portable build output to this new directory
+          $outputPath = "${{ steps.paths.outputs.output_dir }}"
+          Copy-Item -Path "$outputPath\*" -Destination $buildDir -Recurse -Force
+        shell: pwsh
+
+       # Step 6 (x64): Compile .ISS to .EXE Installer for x64
+      - name: Compile .ISS to .EXE Installer (x64)
+        uses: Minionguyjpro/[email protected]
+        with:
+          path: .\Build\install.iss
+          options: /O+ /DMyAppVersion=${{steps.get-version.outputs.file-version}} /DMyAppOutputDir=${{ github.workspace }}\Build\install /DMyFileSource=${{ github.workspace }}\Build\install /DAppIcon=${{ github.workspace }}\src\PicView.Avalonia.Win32\icon.ico /DLicenseFile=${{ github.workspace }}\src\PicView.Core\Licenses\LICENSE.txt
+
+      # Step 7 (x64): Upload the Inno Setup Installer for x64 as an artifact
+      - name: Upload Inno Setup Installer (x64)
+        uses: actions/upload-artifact@v4
+        with:
+          name: PicView-${{steps.get-version.outputs.file-version}}-installer-x64
+          path: ${{ github.workspace }}\Build\install\PicView-${{steps.get-version.outputs.file-version}}.exe
+          retention-days: 14
+
+      # Step 3 (arm64): Publish arm64 version
+      - name: Publish arm64 version
+        run: |
+          # Call the PowerShell script with arm64 as the platform argument
+          pwsh -File "${{ github.workspace }}\Build Avalonia.Win32.ps1" -Platform "arm64"
+        shell: pwsh
+
+      # Step 4 (arm64): Upload the arm64 zip file as an artifact
+      - name: Upload the arm64 artifact
+        uses: actions/upload-artifact@v4
+        with:
+          name: PicView-v${{steps.get-version.outputs.file-version}}-win-arm64
+          path: ${{ steps.paths.outputs.output_dir }}
+          retention-days: 14
+
+      # Step 5 (arm64): Generate the Inno Setup Installer and copy arm64 files to the build directory
+      - name: Generate Inno Setup variables and copy arm64 files to Build directory
+        run: |
+          # Create the directory inside 'Build'
+          $buildDir = Join-Path -Path "${{ github.workspace }}" -ChildPath "Build\install_arm64"
+          if (Test-Path $buildDir) {
+            Remove-Item -Path $buildDir -Recurse -Force
+          }
+          New-Item -Path $buildDir -ItemType Directory | Out-Null
+
+          # Copy the portable build output to this new directory
+          $outputPath = "${{ steps.paths.outputs.output_dir }}"
+          Copy-Item -Path "$outputPath\*" -Destination $buildDir -Recurse -Force
+        shell: pwsh
+
+       # Step 6 (arm64): Compile .ISS to .EXE Installer for arm64
+      - name: Compile .ISS to .EXE Installer (arm64)
+        uses: Minionguyjpro/[email protected]
+        with:
+          path: .\Build\install_arm64.iss
+          options: /O+ /DMyAppVersion=${{steps.get-version.outputs.file-version}} /DMyAppOutputDir=${{ github.workspace }}\Build\install_arm64 /DMyFileSource=${{ github.workspace }}\Build\install_arm64 /DAppIcon=${{ github.workspace }}\src\PicView.Avalonia.Win32\icon.ico /DLicenseFile=${{ github.workspace }}\src\PicView.Core\Licenses\LICENSE.txt
+
+      # Step 7 (arm64): Upload the Inno Setup Installer for arm64 as an artifact
+      - name: Upload Inno Setup Installer (arm64)
+        uses: actions/upload-artifact@v4
+        with:
+          name: PicView-${{steps.get-version.outputs.file-version}}-installer-arm64
+          path: ${{ github.workspace }}\Build\install_arm64\PicView-${{steps.get-version.outputs.file-version}}.exe
+          retention-days: 14

+ 0 - 114
.github/workflows/WinX64.yml

@@ -1,114 +0,0 @@
-name: Build and Publish PicView Avalonia WinX64
-
-on:
-  push:
-    branches:
-      - dev
-  pull_request:
-    branches:
-      - dev
-
-jobs:
-  build:
-    runs-on: windows-latest
-
-    steps:
-      # Step 1: Checkout the code
-      - name: Checkout repository
-        uses: actions/checkout@v4
-
-      # Step 2: Setup .NET 9 SDK
-      - name: Setup .NET 9 SDK
-        uses: actions/setup-dotnet@v4
-        with:
-          dotnet-version: '9.x'
-
-      # Step 3: Get version from the project file
-      - name: Get version from the project file
-        uses: kzrnm/get-net-sdk-project-versions-action@v2
-        id: get-version
-        with:
-          proj-path: .\src\PicView.Avalonia.Win32\PicView.Avalonia.Win32.csproj
-
-      # Step 4: Define paths
-      - name: Define paths
-        id: paths
-        run: |
-          $outputDir = "PicView-v.${{steps.get-version.outputs.file-version}}-win-x64"
-          echo "##[set-output name=output_dir;]$outputDir"
-        shell: pwsh
-
-      # Step 5: Run dotnet publish
-      - name: Publish the project
-        run: |
-          $projectPath = ".\src\PicView.Avalonia.Win32\PicView.Avalonia.Win32.csproj"
-          $tempPath = [System.IO.Path]::GetTempPath() + "PicView"
-          dotnet publish $projectPath --runtime win-x64 --self-contained true --configuration Release --output $tempPath /p:PublishReadyToRun=true
-        shell: pwsh
-
-      # Step 6: Copy output to final directory
-      - name: Copy build to final output directory
-        run: |
-          $tempPath = [System.IO.Path]::GetTempPath() + "PicView"
-          $outputPath = "${{ steps.paths.outputs.output_dir }}"
-          
-          if (Test-Path $outputPath) {
-            Remove-Item -Path $outputPath -Recurse -Force
-          }
-          New-Item -Path $outputPath -ItemType Directory | Out-Null
-          
-          Copy-Item -Path "$tempPath\*" -Destination $outputPath -Recurse -Force
-        shell: pwsh
-
-      # Step 7: Remove unnecessary files
-      - name: Clean up unnecessary files
-        run: |
-          $outputPath = "${{ steps.paths.outputs.output_dir }}"
-          
-          $pdbPath = Join-Path -Path $outputPath -ChildPath "PicView.Avalonia.pdb"
-          if (Test-Path $pdbPath) {
-            Remove-Item -Path $pdbPath -Force
-          }
-          if ($outputPath -match " ") {
-            $newOutputPath = $outputPath.Replace(" ","")
-            Rename-Item -Path $outputPath -NewName $newOutputPath
-          }
-        shell: pwsh
-        
-      # Step 8: Upload the zip file as an artifact
-      - name: Upload the artifact
-        uses: actions/upload-artifact@v4
-        with:
-          name: PicView-v${{steps.get-version.outputs.file-version}}-win-x64
-          path: ${{ steps.paths.outputs.output_dir }}
-          retention-days: 14
-          
-      # Step 9: Generate the Inno Setup Installer and copy files to the build directory
-      - name: Generate Inno Setup variables and copy files to Build directory
-        run: |
-          # Create the directory inside 'Build'
-          $buildDir = Join-Path -Path "${{ github.workspace }}" -ChildPath "Build\install"
-          if (Test-Path $buildDir) {
-            Remove-Item -Path $buildDir -Recurse -Force
-          }
-          New-Item -Path $buildDir -ItemType Directory | Out-Null
-
-          # Copy the portable build output to this new directory
-          $outputPath = "${{ steps.paths.outputs.output_dir }}"
-          Copy-Item -Path "$outputPath\*" -Destination $buildDir -Recurse -Force
-        shell: pwsh
-
-       # Step 10: Compile .ISS to .EXE Installer
-      - name: Compile .ISS to .EXE Installer
-        uses: Minionguyjpro/[email protected]
-        with:
-          path: .\Build\install.iss
-          options: /O+ /DMyAppVersion=${{steps.get-version.outputs.file-version}} /DMyAppOutputDir=${{ github.workspace }}\Build\install /DMyFileSource=${{ github.workspace }}\Build\install /DAppIcon=${{ github.workspace }}\src\PicView.Avalonia.Win32\icon.ico /DLicenseFile=${{ github.workspace }}\src\PicView.Core\Licenses\LICENSE.txt
-  
-      # Step 11: Upload the Inno Setup Installer as an artifact
-      - name: Upload Inno Setup Installer
-        uses: actions/upload-artifact@v4
-        with:
-          name: PicView-${{steps.get-version.outputs.file-version}}-installer
-          path: ${{ github.workspace }}\Build\install\PicView-${{steps.get-version.outputs.file-version}}.exe
-          retention-days: 14

+ 70 - 0
Build/Build Avalonia.Win32 arm64.ps1

@@ -0,0 +1,70 @@
+# Define the core project path relative to the script's location
+$coreProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "..\src\PicView.Core\PicView.Core.csproj"
+
+# Load the .csproj file as XML
+[xml]$coreCsproj = Get-Content $coreProjectPath
+
+# Define the package reference to replace
+$packageRefX64 = "Magick.NET-Q8-OpenMP-x64"
+$packageRefArm64 = "Magick.NET-Q8-OpenMP-arm64"
+
+# Define the platform target (change this to 'x64' if building for x64)
+$platform = "arm64"
+
+# Find the Magick.NET package reference and update it based on the platform
+$packageNodes = $coreCsproj.Project.ItemGroup.PackageReference | Where-Object { $_.Include -eq $packageRefX64 -or $_.Include -eq $packageRefArm64 }
+if ($packageNodes) {
+    foreach ($packageNode in $packageNodes) {
+        if ($platform -eq "arm64") {
+            $packageNode.Include = $packageRefArm64
+        } else {
+            $packageNode.Include = $packageRefX64
+        }
+    }
+}
+
+# Save the updated .csproj file
+$coreCsproj.Save($coreProjectPath)
+
+# Define the project path for the actual build target
+$avaloniaProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "..\src\PicView.Avalonia.Win32\PicView.Avalonia.Win32.csproj"
+
+# Load the .csproj file as XML to extract the AssemblyVersion
+$avaloniaProjectFile = [xml](Get-Content $avaloniaProjectPath)
+$assemblyVersion = $avaloniaProjectFile.Project.PropertyGroup.AssemblyVersion
+
+# Define the temporary output path using the system's temp folder
+$tempPath = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath "PicView"
+
+# Define the final output path relative to the script's location
+$outputPath = Join-Path -Path $PSScriptRoot -ChildPath "PicView-v.$assemblyVersion-win-$platform"
+
+# Ensure the temp directory exists
+if (-Not (Test-Path $tempPath)) {
+    New-Item -Path $tempPath -ItemType Directory | Out-Null
+}
+
+# Run dotnet publish for the Avalonia project
+dotnet publish $avaloniaProjectPath --runtime "win-$platform" --self-contained true --configuration Release --output $tempPath /p:PublishReadyToRun=true
+
+# Ensure the output directory exists and is empty
+if (Test-Path $outputPath) {
+    Remove-Item -Path $outputPath -Recurse -Force
+}
+New-Item -Path $outputPath -ItemType Directory | Out-Null
+
+# Copy the build output to the final destination
+Copy-Item -Path "$tempPath\*" -Destination $outputPath -Recurse -Force
+
+# Remove the PDB file
+$pdbPath = Join-Path -Path $outputPath -ChildPath "PicView.Avalonia.pdb"
+if (Test-Path $pdbPath) {
+    Remove-Item -Path $pdbPath -Force
+}
+
+#Remove uninstended space
+Rename-Item -path $outputPath -NewName $outputPath.Replace(" ","")
+
+# Clean up the temporary directory
+Start-Sleep -Seconds 2
+Remove-Item -Path $tempPath -Recurse -Force

+ 72 - 0
Build/Build Avalonia.Win32.ps1

@@ -0,0 +1,72 @@
+param (
+    [string]$Platform = "x64"  # Default to x64 if no parameter is passed
+)
+
+# Define the core project path relative to the script's location
+$coreProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "..\src\PicView.Core\PicView.Core.csproj"
+
+# Load the .csproj file as XML
+[xml]$coreCsproj = Get-Content $coreProjectPath
+
+# Define the package reference to replace
+$packageRefX64 = "Magick.NET-Q8-OpenMP-x64"
+$packageRefArm64 = "Magick.NET-Q8-OpenMP-arm64"
+
+# Find the Magick.NET package reference and update it based on the platform
+$packageNodes = $coreCsproj.Project.ItemGroup.PackageReference | Where-Object { $_.Include -eq $packageRefX64 -or $_.Include -eq $packageRefArm64 }
+if ($packageNodes) {
+    foreach ($packageNode in $packageNodes) {
+        if ($Platform -eq "arm64") {
+            $packageNode.Include = $packageRefArm64
+        } else {
+            $packageNode.Include = $packageRefX64
+        }
+    }
+}
+
+# Save the updated .csproj file
+$coreCsproj.Save($coreProjectPath)
+
+# Define the project path for the actual build target
+$avaloniaProjectPath = Join-Path -Path $PSScriptRoot -ChildPath "..\src\PicView.Avalonia.Win32\PicView.Avalonia.Win32.csproj"
+
+# Load the .csproj file as XML to extract the AssemblyVersion
+$avaloniaProjectFile = [xml](Get-Content $avaloniaProjectPath)
+$assemblyVersion = $avaloniaProjectFile.Project.PropertyGroup.AssemblyVersion
+
+# Define the temporary output path using the system's temp folder
+$tempPath = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath "PicView"
+
+# Define the final output path relative to the script's location
+$outputPath = Join-Path -Path $PSScriptRoot -ChildPath "PicView-v.$assemblyVersion-win-$Platform"
+
+# Ensure the temp directory exists
+if (-Not (Test-Path $tempPath)) {
+    New-Item -Path $tempPath -ItemType Directory | Out-Null
+}
+
+# Run dotnet publish for the Avalonia project
+dotnet publish $avaloniaProjectPath --runtime "win-$Platform" --self-contained true --configuration Release --output $tempPath /p:PublishReadyToRun=true
+
+
+# Ensure the output directory exists and is empty
+if (Test-Path $outputPath) {
+    Remove-Item -Path $outputPath -Recurse -Force
+}
+New-Item -Path $outputPath -ItemType Directory | Out-Null
+
+# Copy the build output to the final destination
+Copy-Item -Path "$tempPath\*" -Destination $outputPath -Recurse -Force
+
+# Remove the PDB file
+$pdbPath = Join-Path -Path $outputPath -ChildPath "PicView.Avalonia.pdb"
+if (Test-Path $pdbPath) {
+    Remove-Item -Path $pdbPath -Force
+}
+
+#Remove uninstended space
+Rename-Item -path $outputPath -NewName $outputPath.Replace(" ","")
+
+# Clean up the temporary directory
+Start-Sleep -Seconds 2
+Remove-Item -Path $tempPath -Recurse -Force