Skip to content

Build release

Build release #84

Workflow file for this run

name: Build release
on:
workflow_dispatch:
inputs:
productionApiKeys:
description: 'Use production API keys'
type: boolean
default: true
required: true
buildWindows:
description: 'Windows: Build'
type: boolean
default: true
buildAndroid:
description: 'Android: Build'
type: boolean
default: true
androidKeepAab:
description: 'Android: Keep AAB-files'
type: boolean
default: false
env:
SECRETS_FILE: ./Source/Pekspro.RadioStorm.Settings.SynchronizedSettings.FileProvider.Secrets/Secrets-Protected.cs
BUILD_INFO_FILE: ./Source/Pekspro.RadioStorm/Utilities/BuildInformation-Build.cs
jobs:
publish:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 7.0.x
- name: Install MAUI Workload
run: dotnet workload install maui --ignore-failed-sources
- name: Get build information
run: |
echo "CURRENT_TIME=$(date +'%Y%m%d_%H%M%S')" >> $env:GITHUB_ENV
echo "CURRENT_TIME_UTC_STRING=$(date +'%Y-%m-%dT%H:%M:%SZ')" >> $env:GITHUB_ENV
echo "NET_VERSION_STRING=$(dotnet --version)" >> $env:GITHUB_ENV
echo "SHORT_SHA=$("${{ github.sha }}".SubString(0, 8))" >> $env:GITHUB_ENV
echo "WORKLOAD_ANDROID_VERSION_STRING=$((dotnet workload list | Select-String maui)[0].ToString().Split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)[1])" >> $env:GITHUB_ENV
echo "WORKLOAD_WINDOWS_VERSION_STRING=$((dotnet workload list | Select-String maui)[0].ToString().Split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)[1])" >> $env:GITHUB_ENV
echo "WORKLOAD_IOS_VERSION_STRING=$((dotnet workload list | Select-String maui)[0].ToString().Split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)[1])" >> $env:GITHUB_ENV
echo "WORKLOAD_MACCATALYST_VERSION_STRING=$((dotnet workload list | Select-String maui)[0].ToString().Split(" ",[System.StringSplitOptions]::RemoveEmptyEntries)[1])" >> $env:GITHUB_ENV
- name: Create build time file
run: |
echo "namespace Pekspro.RadioStorm.Utilities;" > $env:BUILD_INFO_FILE
echo "public static partial class BuildInformation" >> $env:BUILD_INFO_FILE
echo "{" >> $env:BUILD_INFO_FILE
echo " static partial void Initialize()" >> $env:BUILD_INFO_FILE
echo " {" >> $env:BUILD_INFO_FILE
echo " Branch = ""${{ github.ref_name }}"";" >> $env:BUILD_INFO_FILE
echo " BuildTimeString = ""${{ env.CURRENT_TIME_UTC_STRING }}"";" >> $env:BUILD_INFO_FILE
echo " CommitId = ""${{ github.sha }}"";" >> $env:BUILD_INFO_FILE
echo " DotNetVersionString = ""${{ env.NET_VERSION_STRING }}"";" >> $env:BUILD_INFO_FILE
echo " MauiWorkloadAndroidVersionString = ""${{ env.WORKLOAD_ANDROID_VERSION_STRING }}"";" >> $env:BUILD_INFO_FILE
echo " MauiWorkloadWindowsVersionString = ""${{ env.WORKLOAD_WINDOWS_VERSION_STRING }}"";" >> $env:BUILD_INFO_FILE
echo " MauiWorkloadIosVersionString = ""${{ env.WORKLOAD_IOS_VERSION_STRING }}"";" >> $env:BUILD_INFO_FILE
echo " MauiWorkloadMacCatalysVersionString = ""${{ env.WORKLOAD_MACCATALYST_VERSION_STRING }}"";" >> $env:BUILD_INFO_FILE
echo " }" >> $env:BUILD_INFO_FILE
echo "}" >> $env:BUILD_INFO_FILE
- name: Upload source
uses: actions/[email protected]
with:
name: source-${{ env.CURRENT_TIME }}-${{ env.SHORT_SHA }}
retention-days: 5
path: |
./**/*.*
!./.git
# Doesn't work :-( !/.git
# Doesn't work :-( !/.git/**/*.*
- name: "Sets production API keys"
if: github.event.inputs.productionApiKeys == 'true'
run: |
echo "Set production API keys"
echo "BUILD_TYPE=production" >> $env:GITHUB_ENV
echo "GRAPH_CLIENT_ID=${{ secrets.GRAPH_CLIENT_ID_PRODUCTION }}" >> $env:GITHUB_ENV
echo "IS_TEST_ENVIRONMENT=false" >> $env:GITHUB_ENV
- name: "Sets test API keys"
if: github.event.inputs.productionApiKeys != 'true'
run: |
echo "Set test API keys"
echo "BUILD_TYPE=test" >> $env:GITHUB_ENV
echo "GRAPH_CLIENT_ID=${{ secrets.GRAPH_CLIENT_ID_TEST }}" >> $env:GITHUB_ENV
echo "IS_TEST_ENVIRONMENT=true" >> $env:GITHUB_ENV
- name: "Creating secrets file"
run: |
echo "namespace Pekspro.RadioStorm.Settings.SynchronizedSettings.FileProvider.Secrets;" >> $env:SECRETS_FILE
echo "public static partial class Secrets" >> $env:SECRETS_FILE
echo "{" >> $env:SECRETS_FILE
echo " static partial void Initialize()" >> $env:SECRETS_FILE
echo " {" >> $env:SECRETS_FILE
echo " GraphClientId = ""${{ env.GRAPH_CLIENT_ID }}"";" >> $env:SECRETS_FILE
echo " IsTestEnvironment = ${{ env.IS_TEST_ENVIRONMENT }};" >> $env:SECRETS_FILE
echo " }" >> $env:SECRETS_FILE
echo "}" >> $env:SECRETS_FILE
- name: Output settings
run: |
echo "Is test: ${{ env.IS_TEST_ENVIRONMENT }}"
echo "Build type: ${{ env.BUILD_TYPE }}"
echo "Build setting: ${{ github.event.inputs.productionApiKeys }}"
echo "Build time string: ${{ env.CURRENT_TIME_UTC_STRING }}"
- name: Get Windows version
if: github.event.inputs.buildWindows == 'true'
id: windows_version
uses: mavrosxristoforos/[email protected]
with:
xml-file: Source/Pekspro.RadioStorm.MAUI/Platforms/Windows/Package.appxmanifest
xpath: /*[local-name()='Package']/*[local-name()='Identity']/@Version
- name: Print Windows version
if: github.event.inputs.buildWindows == 'true'
run: |
echo "Windows version ${{ steps.windows_version.outputs.info }} will be built."
- name: Create Windows certificate file
if: github.event.inputs.buildWindows == 'true'
uses: timheuer/[email protected]
id: create_windows_certificate_file
with:
fileName: radiostorm.pfx
encodedString: ${{ secrets.WINDOWS_KEY_FILE }}
- name: Add certificate to Store
if: github.event.inputs.buildWindows == 'true'
run: certutil -user -q -p ${{ secrets.WINDOWS_KEY_PASSWORD }} -importpfx ${{ steps.create_windows_certificate_file.outputs.filePath }} NoRoot
- name: Build MAUI for Windows
if: github.event.inputs.buildWindows == 'true'
run: dotnet publish ./Source/Pekspro.RadioStorm.MAUI/Pekspro.RadioStorm.MAUI.csproj --framework:net7.0-windows10.0.19041.0 --configuration:Release /p:GenerateAppxPackageOnBuild=true /p:AppxPackageSigningEnabled=true /p:PackageCertificateThumbprint=${{ secrets.WINDOWS_KEY_THUMBPRINT }} --output ./publish
- name: Move to root folder
if: github.event.inputs.buildWindows == 'true'
run: |
mv ./Source/Pekspro.RadioStorm.MAUI/bin/Release/net7.0-windows*/win10*/AppPackages/*/*.msix ./
mv ./Source/Pekspro.RadioStorm.MAUI/bin/Release/net7.0-windows*/win10*/AppPackages/*/*.cer ./
- name: Upload Windows Artifact
if: github.event.inputs.buildWindows == 'true'
uses: actions/[email protected]
with:
name: windows-${{ env.BUILD_TYPE }}-${{ env.CURRENT_TIME }}-${{ env.SHORT_SHA }}-${{ steps.windows_version.outputs.info }}
retention-days: 5
path: |
./*.msix
./*.cer
- name: Get Android display version
id: android_display_version
if: github.event.inputs.buildAndroid == 'true'
uses: mavrosxristoforos/[email protected]
with:
xml-file: Source/Pekspro.RadioStorm.MAUI/Pekspro.RadioStorm.MAUI.csproj
xpath: /Project/PropertyGroup/ApplicationDisplayVersion
- name: Get Android version
id: android_version
if: github.event.inputs.buildAndroid == 'true'
uses: mavrosxristoforos/[email protected]
with:
xml-file: Source/Pekspro.RadioStorm.MAUI/Pekspro.RadioStorm.MAUI.csproj
xpath: /Project/PropertyGroup/ApplicationVersion
- name: Print Android version
if: github.event.inputs.buildAndroid == 'true'
run: |
echo "Android version ${{ steps.android_display_version.outputs.info }} (${{ steps.android_version.outputs.info }}) will be built."
- name: Create Android key file
if: github.event.inputs.buildAndroid == 'true'
uses: timheuer/[email protected]
id: create_android_key_file
with:
fileName: androidkeyfile
encodedString: ${{ secrets.ANDROID_KEY_FILE }}
- name: Build MAUI for Android
if: github.event.inputs.buildAndroid == 'true'
run: dotnet publish ./Source/Pekspro.RadioStorm.MAUI/Pekspro.RadioStorm.MAUI.csproj --framework:net7.0-android --configuration:Release /p:AndroidSigningKeyStore=${{ steps.create_android_key_file.outputs.filePath }} /p:AndroidKeyStore=True /p:AndroidSigningKeyAlias=${{ secrets.ANDROID_KEY_ALIAS }} /p:AndroidSigningKeyPass=${{ secrets.ANDROID_KEY_PASSWORD }} /p:AndroidSigningStorePass=${{ secrets.ANDROID_KEY_PASSWORD }} /p:PublishTrimmed=false /p:RunAOTCompilation=false --output ./Android
- name: Delete AAB-files
if: github.event.inputs.buildAndroid == 'true' && github.event.inputs.androidKeepAab == 'false'
run: |
del ./Android/*.aab
- name: Move Android outputs to root folder
if: github.event.inputs.buildAndroid == 'true'
run: |
mv ./Android/*.* ./
- name: Add version to file name
if: github.event.inputs.buildAndroid == 'true'
shell: powershell
run: |
Get-ChildItem -Filter *.aab | Rename-Item -NewName { $_.BaseName + '-${{ env.SHORT_SHA }}-${{ steps.android_display_version.outputs.info }} [${{ steps.android_version.outputs.info }}]' + $_.Extension }
Get-ChildItem -Filter *.apk | Rename-Item -NewName { $_.BaseName + '-${{ env.SHORT_SHA }}-${{ steps.android_display_version.outputs.info }} [${{ steps.android_version.outputs.info }}]' + $_.Extension }
- name: Upload a Android Artifact
if: github.event.inputs.buildAndroid == 'true'
uses: actions/[email protected]
with:
name: android-${{ env.BUILD_TYPE }}-${{ env.CURRENT_TIME }}-${{ env.SHORT_SHA }}-${{ steps.android_display_version.outputs.info }} [${{ steps.android_version.outputs.info }}]
retention-days: 5
path: |
./*.aab
./*.apk