Release [.NET MAUI] #4
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: Release [.NET MAUI] | |
| ############################################################### | |
| ########################### WARNING ########################### | |
| ############################################################### | |
| # Manual trigger only, this workflow publishes to nuget.org! | |
| on: | |
| workflow_dispatch: | |
| env: | |
| DOTNET_SDK_VERSION: '9.0.x' | |
| jobs: | |
| publish_commonhelpers: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install .NET Core | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{env.DOTNET_SDK_VERSION}} | |
| - name: Setup MSBuild.exe | |
| uses: microsoft/setup-msbuild@v2 | |
| # ****** CommonHelpers Tasks ***** # | |
| - name: Restore & Build CommonHelpers | |
| working-directory: src/CommonHelpers | |
| run: | | |
| dotnet restore --runtime any --ignore-failed-sources | |
| dotnet build --configuration Release | |
| - name: Add CommonHelpers Bin to NuGet Package Sources | |
| run: dotnet nuget add source "${{github.workspace}}\src\CommonHelpers\bin" --name "CommonHelpers_Bin" | |
| - name: Get Version From Project | |
| uses: kzrnm/get-net-sdk-project-versions-action@v2 | |
| id: get-version | |
| with: | |
| proj-path: src/CommonHelpers/CommonHelpers.csproj | |
| - name: Get Package File Path | |
| id: get-package-path | |
| run : | | |
| $currentDirectory = Get-Location | |
| $outputFolder = Join-Path -Path $currentDirectory -ChildPath "src/CommonHelpers/bin/Release/" | |
| $match = Get-ChildItem $outputFolder -Recurse -Force -Include *.nupkg | |
| Write-Output "Setting output variable 'nuget-package-path' to $match" | |
| echo "nuget-package-path=$match" >> $env:GITHUB_OUTPUT | |
| # ****** CommonHelpers.Maui Tasks ***** # | |
| - name: Install MAUI workloads (required for GitHub-hosted runners) | |
| shell: pwsh | |
| run: dotnet workload install maui --source https://api.nuget.org/v3/index.json | |
| - name: Restore & Build CommonHelpers.Maui | |
| working-directory: src/CommonHelpers.Maui | |
| run: | | |
| dotnet install "CommonHelpers" --version "${{steps.get-version.outputs.package-version}}" | |
| dotnet restore --runtime any --ignore-failed-sources | |
| dotnet build --configuration Release | |
| - name: Add CommonHelpers.Maui Bin to NuGet Package Sources | |
| run: dotnet nuget add source "${{github.workspace}}\src\CommonHelpers.Maui\bin" --name "CommonHelpers.Maui_Release" | |
| - name: Get Maui Version From Project | |
| uses: kzrnm/get-net-sdk-project-versions-action@v2 | |
| id: get-version-maui | |
| with: | |
| proj-path: src/CommonHelpers.Maui/CommonHelpers.Maui.csproj | |
| - name: Get Maui Package File Path | |
| id: get-package-path-maui | |
| run : | | |
| $currentDirectory = Get-Location | |
| $outputFolder = Join-Path -Path $currentDirectory -ChildPath "src/CommonHelpers.Maui/bin/Release/" | |
| $match = Get-ChildItem $outputFolder -Recurse -Force -Include *.nupkg | |
| Write-Output "Setting output variable 'nuget-package-path-maui' to $match" | |
| echo "nuget-package-path-maui=$match" >> $env:GITHUB_OUTPUT | |
| # CommonHelpers.Tests project | |
| - name: Restore & Build CommonHelpers.Tests | |
| working-directory: src/CommonHelpers.Tests | |
| run: | | |
| dotnet restore --runtime any --ignore-failed-sources | |
| dotnet build --configuration Release | |
| - name: Run Tests | |
| working-directory: src/CommonHelpers.Tests | |
| run: dotnet test --runtime any -c Release --logger GitHubActions --blame-crash --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover | |
| # ***** NuGet Package Signing ***** # | |
| - name: Decode Base64 and save PFX file | |
| id: download-cert | |
| run: | | |
| $pfx_cert_byte = [System.Convert]::FromBase64String("${{secrets.LANCELOTSOFTWARECERT_BASE64}}") | |
| $currentDirectory = Get-Location | |
| $certificatePath = Join-Path -Path $currentDirectory -ChildPath "LancelotSoftware.pfx" | |
| [IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte) | |
| Write-Output "Setting output variable 'certificate-path'..." | |
| echo "certificate-path=$certificatePath" >> $env:GITHUB_OUTPUT | |
| - name: Sign CommonHelpers.Maui NuGet package | |
| run: dotnet nuget sign ${{steps.get-package-path-maui.outputs.nuget-package-path-maui}} --certificate-path ${{steps.download-cert.outputs.certificate-path}} --certificate-password "${{secrets.LANCELOTSOFTWARECERT_PASSWORD}}" --timestamper "http://timestamp.digicert.com" | |
| # ***** NuGet.org Release ***** # | |
| - name: Publish CommonHelpers.Maui to NuGet.org | |
| run: dotnet nuget push ${{steps.get-package-path-maui.outputs.nuget-package-path-maui}} --source https://api.nuget.org/v3/index.json --api-key ${{secrets.NUGET_API_KEY}} | |
| # ***** Upload Artifacts ***** # | |
| - name: Upload CommonHelpers.Maui NuGet package artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: "CommonHelpers.Maui.${{steps.get-version-maui.outputs.package-version}}.nupkg" | |
| path: ${{steps.get-package-path-maui.outputs.nuget-package-path-maui}} | |
| # ***** GitHub Release ***** # | |
| - name: Generate version number with date and workflow Run Number | |
| id: version-creator | |
| run: | | |
| $buildDay = Get-Date -Format "yyyy.Mdd" | |
| $runNumber = "$env:GITHUB_RUN_NUMBER" | |
| $ver = $buildDay + "." + $runNumber + ".0" | |
| echo "DATED_VERSION_NUM=$ver" >> $env:GITHUB_OUTPUT | |
| - name: Create GitHub Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
| with: | |
| tag_name: "${{steps.version-creator.outputs.DATED_VERSION_NUM}}" | |
| release_name: "CommonHelpers.Maui ${{steps.version-creator.outputs.DATED_VERSION_NUM}}" | |
| draft: false | |
| prerelease: false | |
| - name: Attach CommonHelpers.Maui Release Asset | |
| id: upload-maui-asset | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
| with: | |
| upload_url: ${{steps.create_release.outputs.upload_url}} | |
| asset_path: ${{steps.get-package-path-maui.outputs.nuget-package-path-maui}} | |
| asset_name: "CommonHelpers.Maui.${{steps.get-version-maui.outputs.package-version}}.nupkg" | |
| asset_content_type: application/zip |