Build and Publish WinUI3 App #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Upload | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version number (e.g., 1.0.0.1)' | |
| required: true | |
| type: string | |
| prerelease: | |
| description: 'If pre_release' | |
| required: true | |
| type: boolean | |
| env: | |
| DOTNET_VERSION: '8.0.x' | |
| jobs: | |
| build-and-package: | |
| name: Build and Package | |
| runs-on: windows-2022 | |
| env: | |
| Solution_Name: RailGo.sln | |
| SigningKey_Path: SigningKey.pfx | |
| APPLICATION_ID: 9NTRZ0DMCKGZ | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install .NET Core | |
| uses: actions/setup-dotnet@v3 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Setup MSBuild.exe | |
| uses: microsoft/setup-msbuild@v1 | |
| - name: Install StoreBroker | |
| shell: pwsh | |
| run: | | |
| Write-Output "Installing StoreBroker module..." | |
| Install-Module -Name StoreBroker -Force -AllowClobber -Scope CurrentUser | |
| Import-Module StoreBroker | |
| Write-Output "StoreBroker installed successfully" | |
| - name: Restore the application | |
| run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration | |
| env: | |
| Configuration: Release | |
| - name: Update Manifest Version | |
| shell: pwsh | |
| run: | | |
| $AppxManifestPath = "RailGo/Package.appxmanifest" | |
| $newVersion = "${{ github.event.inputs.version }}" | |
| Write-Output "Setting new version: $newVersion" | |
| [xml]$xmlMSIX = Get-Content $AppxManifestPath | |
| $identityNode = $xmlMSIX.Package.Identity | |
| $identityNode.Version = $newVersion | |
| $xmlMSIX.Save($AppxManifestPath) | |
| - name: Create the MSIX Package | |
| run: msbuild $env:Solution_Name /p:AppxBundlePlatforms="$env:Appx_Bundle_Platforms" /p:Configuration=$env:Configuration /p:UapAppxPackageBuildMode=$env:Appx_Package_Build_Mode /p:AppxBundle=$env:Appx_Bundle /p:AppxPackageDir="$env:Appx_Package_Dir" /p:GenerateAppxPackageOnBuild=true /p:AppxPackageSigningEnabled=false | |
| env: | |
| Appx_Bundle: Always | |
| Appx_Bundle_Platforms: x86|x64|ARM64 | |
| Appx_Package_Build_Mode: SideloadOnly | |
| Appx_Package_Dir: AppxPackages\ | |
| Configuration: Release | |
| - name: Sign .msix | |
| shell: pwsh | |
| run: | | |
| # Get signtool.exe | |
| $signtool = Get-ChildItem -Path "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\signtool.exe" | Select-Object -First 1 | |
| # Get File | |
| $msixFile = Get-ChildItem -Path "RailGo/AppxPackages" -Recurse -Filter "*.msix" | Sort-Object LastWriteTime -Descending | Select-Object -First 1 | |
| if (-not $msixFile) { | |
| throw "No MSIX file found" | |
| } | |
| Write-Output "Signing file: $($msixFile.FullName)" | |
| # Sign .msix | |
| $pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.SIGNING_CERT }}") | |
| [IO.File]::WriteAllBytes("${{ env.SigningKey_Path }}", $pfx_cert_byte) | |
| & $signtool sign /f "${{ env.SigningKey_Path }}" /fd SHA256 /td SHA256 "$($msixFile.FullName)" | |
| Remove-Item "${{ env.SigningKey_Path }}" | |
| Write-Output "File signed successfully" | |
| - name: Find signed MSIX file | |
| id: find-msix | |
| shell: pwsh | |
| run: | | |
| $msixFile = Get-ChildItem -Path "RailGo/AppxPackages" -Recurse -Filter "*.msix" | Sort-Object LastWriteTime -Descending | Select-Object -First 1 | |
| if (-not $msixFile) { | |
| throw "No signed MSIX file found" | |
| } | |
| Write-Output "Found MSIX file: $($msixFile.FullName)" | |
| echo "msix_path=$($msixFile.FullName)" >> $env:GITHUB_OUTPUT | |
| echo "msix_name=$($msixFile.Name)" >> $env:GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ github.event.inputs.version }} | |
| name: RailGo v${{ github.event.inputs.version }} | |
| body: | | |
| Automated build version ${{ github.event.inputs.version }} | |
| prerelease: ${{ github.event.inputs.prerelease }} | |
| files: | | |
| ${{ steps.find-msix.outputs.msix_path }} | |
| draft: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| upload-to-msstore: | |
| name: Upload to Microsoft Store | |
| needs: build-and-package | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Configure Store Credentials | |
| uses: microsoft/store-submission@v1 | |
| with: | |
| command: configure | |
| type: packaged | |
| seller-id: ${{ secrets.SELLER_ID }} | |
| product-id: ${{ secrets.PRODUCT_ID }} | |
| tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
| client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
| client-secret: ${{ secrets.AZURE_CLIENT_SECRET }} | |
| - name: Update Store Submission | |
| uses: microsoft/store-submission@v1 | |
| with: | |
| command: update | |
| product-update: '{"packages": [{"packageUrl": "https://github.com/${{ github.repository }}/releases/download/v${{ github.event.inputs.version }}/${{ needs.build-and-package.outputs.msix_name }}","languages": ["zh-CN"],"architectures": ["x64"]}]}' |