BuildMacOS.yml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. name: Build PicView Avalonia on macOS
  2. on:
  3. push:
  4. branches:
  5. - dev
  6. pull_request:
  7. branches:
  8. - dev
  9. jobs:
  10. build:
  11. runs-on: macos-latest
  12. steps:
  13. # Step 1: Checkout the code
  14. - name: Checkout repository
  15. uses: actions/checkout@v4
  16. # Step 2: Setup .NET 9 SDK
  17. - name: Setup .NET 9 SDK
  18. uses: actions/setup-dotnet@v4
  19. with:
  20. dotnet-version: '9.x'
  21. # Step 3: Get version from Directory.Build.props using PowerShell
  22. - name: Get version from Directory.Build.props
  23. id: get-version
  24. run: pwsh -File "${{ github.workspace }}/Build/Get-VersionInfo.ps1"
  25. # Step 4: Build arm64 version
  26. - name: Build arm64 version
  27. run: |
  28. pwsh -File "${{ github.workspace }}/Build/Build Avalonia.MacOS.ps1" `
  29. -Platform "arm64" `
  30. -outputPath "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64" `
  31. -appVersion "${{steps.get-version.outputs.version}}"
  32. shell: pwsh
  33. - name: Prepare and Sign arm64 App Bundle
  34. run: |
  35. # Create entitlements file
  36. cat > entitlements.plist << EOF
  37. <?xml version="1.0" encoding="UTF-8"?>
  38. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  39. <plist version="1.0">
  40. <dict>
  41. <key>com.apple.security.cs.allow-jit</key>
  42. <true/>
  43. <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
  44. <true/>
  45. <key>com.apple.security.cs.disable-library-validation</key>
  46. <true/>
  47. </dict>
  48. </plist>
  49. EOF
  50. APP_PATH="${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64/PicView.app"
  51. # Verify bundle structure
  52. if [ ! -f "$APP_PATH/Contents/Info.plist" ]; then
  53. echo "Error: Info.plist not found in the expected location"
  54. exit 1
  55. fi
  56. # Sign all dylibs and binaries
  57. find "$APP_PATH/Contents/MacOS" -type f \( -name "*.dylib" -o -name "PicView.Avalonia.MacOS" \) | while read file; do
  58. codesign --force --options runtime --sign - --entitlements entitlements.plist "$file"
  59. done
  60. # Sign the app bundle
  61. codesign --force --options runtime --sign - --entitlements entitlements.plist "$APP_PATH"
  62. # Step 5: Create DMG for arm64
  63. - name: Create DMG for arm64
  64. run: |
  65. hdiutil create -volname "PicView" -srcfolder "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64/PicView.app" -ov -format UDZO "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64.dmg"
  66. # Step 6: Upload arm64 artifacts
  67. - name: Upload arm64 artifacts
  68. uses: actions/upload-artifact@v4
  69. with:
  70. name: PicView-v${{steps.get-version.outputs.version}}-macOS-arm64
  71. path: |
  72. ${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64/PicView.app
  73. ${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-arm64.dmg
  74. retention-days: 14
  75. # Step 7: Build and create x64 .app bundle
  76. - name: Build x64 version
  77. run: |
  78. pwsh -File "${{ github.workspace }}/Build/Build Avalonia.MacOS.ps1" `
  79. -Platform "x64" `
  80. -outputPath "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64" `
  81. -appVersion "${{steps.get-version.outputs.version}}"
  82. shell: pwsh
  83. - name: Prepare and Sign x64 App Bundle
  84. run: |
  85. find "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64/PicView.app" -type f -name "*.dylib" -o -name "PicView.Avalonia.MacOS" | while read file; do
  86. codesign --force --options runtime --sign - --entitlements entitlements.plist "$file"
  87. done
  88. codesign --force --options runtime --sign - --entitlements entitlements.plist "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64/PicView.app"
  89. # Step 8: Create DMG for x64
  90. - name: Create DMG for x64
  91. run: |
  92. hdiutil create -volname "PicView" -srcfolder "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64/PicView.app" -ov -format UDZO "${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64.dmg"
  93. # Step 9: Upload x64 artifacts
  94. - name: Upload x64 artifacts
  95. uses: actions/upload-artifact@v4
  96. with:
  97. name: PicView-v${{steps.get-version.outputs.version}}-macOS-x64
  98. path: |
  99. ${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64/PicView.app
  100. ${{ github.workspace }}/Build/PicView-v${{steps.get-version.outputs.version}}-osx-x64.dmg
  101. retention-days: 14