main.yml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. name: WinUI 3 MSIX app
  2. on:
  3. # Triggers the workflow on push or pull request events but only for the master branch
  4. push:
  5. branches: [ master ]
  6. pull_request:
  7. branches: [ master ]
  8. # Allows you to run this workflow manually from the Actions tab
  9. workflow_dispatch:
  10. env:
  11. Unsigned_Artifact_Name: MSIX Package
  12. jobs:
  13. build:
  14. strategy:
  15. matrix:
  16. configuration: [Release]
  17. platform: [x64, x86, ARM64]
  18. runs-on: windows-latest
  19. env:
  20. Solution_Name: MyPhone
  21. steps:
  22. - uses: actions/checkout@v3
  23. # Install the .NET Core workload
  24. - name: Install .NET Core
  25. uses: actions/setup-dotnet@v1
  26. with:
  27. dotnet-version: 6.0.x
  28. # Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
  29. - name: Setup MSBuild
  30. uses: microsoft/setup-msbuild@v1.0.2
  31. # Restore the application to populate the obj folder with RuntimeIdentifiers
  32. - name: Restore the application
  33. run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
  34. env:
  35. Configuration: ${{ matrix.configuration }}
  36. # Create the app package by building and packaging the project
  37. - name: Create the app package
  38. run: |
  39. msbuild $env:Solution_Name `
  40. /p:Configuration=$env:Configuration `
  41. /p:Platform=$env:Platform `
  42. /p:UapAppxPackageBuildMode=$env:Appx_Package_Build_Mode `
  43. /p:AppxBundle=$env:Appx_Bundle `
  44. /p:AppxPackageDir="$env:Appx_Package_Dir" `
  45. /p:GenerateAppxPackageOnBuild=true
  46. env:
  47. Appx_Bundle: Never
  48. Appx_Package_Build_Mode: SideloadOnly
  49. Appx_Package_Dir: Packages\
  50. Configuration: ${{ matrix.configuration }}
  51. Platform: ${{ matrix.platform }}
  52. # Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact
  53. - name: Upload MSIX package
  54. uses: actions/upload-artifact@v2
  55. with:
  56. name: ${{ env.Unsigned_Artifact_Name }}
  57. path: ${{ env.Solution_Name }}\\Packages
  58. bundle:
  59. name: Bundle and sign the MSIX package
  60. runs-on: windows-latest
  61. needs: build
  62. env:
  63. Bundling_Workspace_Path: BundlingWorkspace
  64. Bundle_Install_Path: BundlePackage
  65. Unsigned_Packages_Path: Packages
  66. steps:
  67. - name: Setup VS Dev Environment
  68. uses: seanmiddleditch/gha-setup-vsdevenv@v4
  69. - name: Download build artifacts
  70. uses: actions/download-artifact@v3.0.0
  71. with:
  72. name: ${{ env.Unsigned_Artifact_Name }}
  73. path: ${{ env.Unsigned_Packages_Path }}
  74. - name: Prepare workspace
  75. run: |
  76. mkdir $env:Bundle_Install_Path
  77. mkdir $env:Bundling_Workspace_Path
  78. Write-Output "Current worksapce structure:"
  79. ls
  80. - name: Bundle package
  81. run: |
  82. cp "${env:Unsigned_Packages_Path}\*\*.msix" $env:Bundling_Workspace_Path -Verbose
  83. $files = ls $env:Bundling_Workspace_Path | Sort-Object -Property Name -Descending
  84. $bundleName = $files[0].Name
  85. $bundleName = $bundleName.Substring(0, $bundleName.LastIndexOf('_'))
  86. foreach ($f in $files) {
  87. $beginIndex = $f.Name.LastIndexOf('_')
  88. $endIndex = $f.Name.LastIndexOf('.')
  89. $bundleName += $f.Name.Substring($beginIndex, $endIndex - $beginIndex)
  90. }
  91. $bundleName += ".msixbundle"
  92. Write-Output "Making MSIX bundle ${bundleName}"
  93. MakeAppx bundle /d $env:Bundling_Workspace_Path /p "${env:Bundle_Install_Path}\${bundleName}"
  94. "MSIX_Bunde_FileName=$bundleName" >> $env:GITHUB_ENV
  95. # Decode the base 64 encoded pfx and save the Signing_Certificate
  96. - name: Decode the pfx
  97. id: decode-pfx
  98. run: |
  99. $pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.TESTING_PFX_BASE64_ENCODED }}")
  100. $certificatePath = "GitHubActionsWorkflow.pfx"
  101. [IO.File]::WriteAllBytes($certificatePath, $pfx_cert_byte)
  102. - name: Sign the bundle
  103. run: |
  104. SignTool sign /fd SHA256 /a /f GitHubActionsWorkflow.pfx /p "${{ secrets.TESTING_PFX_PASSPHRASE }}" "${env:Bundle_Install_Path}\${{ env.MSIX_Bunde_FileName }}"
  105. # Remove the pfx
  106. - name: Post Decode the pfx
  107. if: ${{ steps.decode-pfx.outcome == 'success' || steps.decode-pfx.outcome == 'failure' }}
  108. run: Remove-Item -path GitHubActionsWorkflow.pfx
  109. - name: Prepare for upload
  110. run: |
  111. $files = ls $env:Unsigned_Packages_Path | Sort-Object -Property Name -Descending
  112. $contentPath = $files[0].Name
  113. $contentPath = "${env:Unsigned_Packages_Path}\$contentPath"
  114. Write-Output "Content source path: $contentPath"
  115. Write-Output "Copying install scripts"
  116. cp "$contentPath\*.ps1" $env:Bundle_Install_Path -Verbose
  117. Write-Output "Copying debug symbols"
  118. cp "${env:Unsigned_Packages_Path}\*\*.msixsym" $env:Bundle_Install_Path -Verbose
  119. Write-Output "Copying dependencies and resources"
  120. ls $contentPath | Where-Object -Property Attributes -eq Directory | cp -Recurse -Destination $env:Bundle_Install_Path -Verbose
  121. Write-Output "Downloading public certificate"
  122. $public_cert_byte = [System.Convert]::FromBase64String("${{ secrets.TESTING_PUBLIC_CERT_BASE64_ENCODED }}")
  123. $public_cert_path = "${env:Bundle_Install_Path}\MyPhoneTestingCert_GithubAction.cer"
  124. [IO.File]::WriteAllBytes("$public_cert_path", $public_cert_byte)
  125. Write-Output "Downloaded public certificate at $public_cert_path"
  126. $artifactName = $env:MSIX_Bunde_FileName.Substring(0, $env:MSIX_Bunde_FileName.LastIndexOf('.'))
  127. "Bundle_Artifact_Name=$artifactName" >> $env:GITHUB_ENV
  128. - name: Delete old unsigned artifact
  129. uses: GeekyEggo/delete-artifact@v1.0.0
  130. with:
  131. name: ${{ env.Unsigned_Artifact_Name }}
  132. - name: Upload signed MSIX package bundle
  133. uses: actions/upload-artifact@v2
  134. with:
  135. name: ${{ env.Bundle_Artifact_Name }}
  136. path: ${{ env.Bundle_Install_Path }}