Skip to content

Build SilentNotes binaries #59

Build SilentNotes binaries

Build SilentNotes binaries #59

# Builds the binaries which can be uploaded to the Microsoft/Google store
name: Build SilentNotes binaries
on:
workflow_dispatch:
inputs:
build-android:
type: boolean
default: true
description: Build the Android binaries
build-windows:
type: boolean
default: true
description: Build the Windows binaries
publish-release:
type: boolean
default: true
description: Publish new release on GitHub
env:
Project_Path: src\SilentNotes.Blazor\SilentNotes.csproj
Dotnet_Version: 8.0.x
Target_Framework_Android: net8.0-android
Target_Framework_Windows: net8.0-windows10.0.19041.0
jobs:
##############################################################################
# Extract version from csproj.
##############################################################################
job_version:
runs-on: windows-latest
outputs:
formatted_version: ${{ steps.output_formatted_version.outputs.version }}
integer_version: ${{ steps.output_integer_version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
# Read version from csproj
- name: Read version from csproj
id: formatted_version
uses: mavrosxristoforos/[email protected]
with:
xml-file: "${{ env.Project_Path }}"
xpath: //PropertyGroup/ApplicationDisplayVersion
- id: output_formatted_version
run: echo "version=${{ steps.formatted_version.outputs.info }}" >> $Env:GITHUB_OUTPUT
# Read increasing android version
- name: Read version for android
id: integer_version
uses: mavrosxristoforos/[email protected]
with:
xml-file: "${{ env.Project_Path }}"
xpath: //PropertyGroup/ApplicationVersion
- id: output_integer_version
run: echo "version=${{ steps.integer_version.outputs.info }}" >> $Env:GITHUB_OUTPUT
##############################################################################
# Android multi platform apk (armeabi-v7;arm64-v8a)
# Platforms are taken from the csproj, to build one apk with multiple platforms
##############################################################################
job_build_android:
if: ${{ inputs.build-android }}
runs-on: windows-latest
env:
Keystore_Path: src\SilentNotes.Blazor\silentnotes.keystore # Same directory as csproj
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.Dotnet_Version }}
#- name: Install Java
# uses: actions/setup-java@v2
# with:
# distribution: 'microsoft'
# java-version: '11'
- name: Install MAUI
run: dotnet workload install maui-android --ignore-failed-sources
# Decode the base 64 encoded pfx and save the Signing_Certificate
- name: Decode the keystore file
run: |
echo "${{ secrets.SILENTNOTESANDROIDKEYSTORE }}" > "${{ env.Keystore_Path }}.asc"
gpg -d --quiet --batch --yes --passphrase="${{ env.KeystoreGpgPassword }}" --output "${{ env.Keystore_Path }}" "${{ env.Keystore_Path }}.asc"
env:
KeystoreGpgPassword: ${{ secrets.SILENTNOTESANDROIDKEYSTOREGPGPASSWORD }}
# Build application
# The keystore location seems to be relative to the csproj file, so we placed it in the same directory and pass only the filename
- name: Restore NuGet packages
run: dotnet restore
- name: Build application
run: dotnet publish "${{ env.Project_Path }}" -c Release -f ${{ env.Target_Framework_Android }} -o ".\bin" -p:AndroidPackageFormats=apk -p:PublishTrimmed=true -p:AndroidKeyStore=True -p:AndroidSigningKeyStore=silentnotes.keystore -p:AndroidSigningKeyAlias=androidmartinstoeckli -p:AndroidSigningKeyPass=${{ env.KeystorePassword }} -p:AndroidSigningStorePass=${{ env.KeystorePassword }}
env:
KeystorePassword: ${{ secrets.SILENTNOTESANDROIDKEYSTOREPASSWORD }}
- name: Remove the keystore
run: Remove-Item -path "${{ env.Keystore_Path }}"
- name: Remove encoded keystore
run: Remove-Item -path "${{ env.Keystore_Path }}.asc"
- name: Collect apk files
run: |
$apks = Get-ChildItem -Path .\bin\* -Filter *Signed.apk -Recurse -File
New-Item -Path ".\artifacts" -ItemType "directory"
Move-Item -Path $apks[0].FullName -Destination ".\artifacts\silentnotes_arm.apk"
# Upload artifacts
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: silentnotes_android_arm_binaries
path: .\artifacts
##############################################################################
# Android additional platforms
##############################################################################
job_build_android_additional_platform:
if: ${{ inputs.build-android }}
strategy:
matrix:
platform: [x64]
runs-on: windows-latest
env:
Keystore_Path: src\SilentNotes.Blazor\silentnotes.keystore # Same directory as csproj
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.Dotnet_Version }}
#- name: Install Java
# uses: actions/setup-java@v2
# with:
# distribution: 'microsoft'
# java-version: '11'
- name: Install MAUI
run: dotnet workload install maui-android --ignore-failed-sources
# Decode the base 64 encoded pfx and save the Signing_Certificate
- name: Decode the keystore file
run: |
echo "${{ secrets.SILENTNOTESANDROIDKEYSTORE }}" > "${{ env.Keystore_Path }}.asc"
gpg -d --quiet --batch --yes --passphrase="${{ env.KeystoreGpgPassword }}" --output "${{ env.Keystore_Path }}" "${{ env.Keystore_Path }}.asc"
env:
KeystoreGpgPassword: ${{ secrets.SILENTNOTESANDROIDKEYSTOREGPGPASSWORD }}
# Build application
# The keystore location seems to be relative to the csproj file, so we placed it in the same directory and pass only the filename
- name: Restore NuGet packages
run: dotnet restore
- name: Build application
run: dotnet publish "${{ env.Project_Path }}" -c Release -f ${{ env.Target_Framework_Android }} -r android-${{ env.Platform }} -o ".\bin" -p:AndroidKeyStore=True -p:AndroidSigningKeyStore=silentnotes.keystore -p:AndroidSigningKeyAlias=androidmartinstoeckli -p:AndroidSigningKeyPass=${{ env.KeystorePassword }} -p:AndroidSigningStorePass=${{ env.KeystorePassword }}
env:
Platform: ${{ matrix.platform }}
KeystorePassword: ${{ secrets.SILENTNOTESANDROIDKEYSTOREPASSWORD }}
- name: Remove the keystore
run: Remove-Item -path "${{ env.Keystore_Path }}"
- name: Remove encoded keystore
run: Remove-Item -path "${{ env.Keystore_Path }}.asc"
- name: Collect apk files
run: |
$apks = Get-ChildItem -Path .\bin\* -Filter *Signed.apk -Recurse -File
New-Item -Path ".\artifacts" -ItemType "directory"
Move-Item -Path $apks[0].FullName -Destination ".\artifacts\silentnotes_${{ env.Platform }}.apk"
env:
Platform: ${{ matrix.platform }}
# Upload artifacts
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: silentnotes_android_x64_binaries
path: .\artifacts
##############################################################################
# Windows
##############################################################################
job_build_windows:
if: ${{ inputs.build-windows }}
strategy:
matrix:
platform: [x86,x64]
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.Dotnet_Version }}
# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2
- name: Install MAUI
run: dotnet workload install maui-windows maui-android
# Decode the base 64 encoded pfx and save the Signing_Certificate
- name: Decode the pfx
run: |
echo "${{ secrets.SILENTNOTESPFX }}" > SilentNotes.pfx.asc
certutil -decode SilentNotes.pfx.asc SilentNotes.pfx
- name: Remove decoded pfx
run: Remove-Item -path SilentNotes.pfx.asc
- name: Add cert to store
run: certutil -user -q -p ${{ secrets.SILENTNOTESPFXPASSWORD }} -importpfx SilentNotes.pfx NoRoot
# Restore the application to populate the obj folder with RuntimeIdentifiers
- name: Restore Dependencies
run: dotnet restore "${{ env.Project_Path }}" -r ${{ env.RuntimeIdentifier }}
env:
RuntimeIdentifier: win-${{ matrix.platform }}
# Build application
# declare the -r parameter and also the -p:Platform paramter to mitigate error: The platform 'AnyCPU' is not supported for Self Contained mode
- name: Build application
run: dotnet publish -c Release -p:PublishProfile=${{ env.Profile }} -f ${{ env.Target_Framework_Windows }} -r ${{ env.RuntimeIdentifier }} -p:Platform=${{ env.Platform }} -p:AppxPackageSigningEnabled=true -p:PackageCertificateThumbprint="${{ secrets.SILENTNOTESPFXTHUMBPRINT }}"
env:
Platform: ${{ matrix.platform }}
RuntimeIdentifier: win10-${{ matrix.platform }}
Profile: MSIX-win10-${{ matrix.platform }}
# Remove the pfx
- name: Remove the pfx
run: Remove-Item -path SilentNotes.pfx
# Collect files for upload
- name: Collect msix files
run: |
$files = Get-ChildItem -Path "${{ env.Project_Dir }}" -Filter SilentNotes*.msix -Recurse -File
New-Item -Path ".\windows" -ItemType "directory"
Move-Item -Path $files[0].FullName -Destination ".\windows\silentnotes_${{ env.Platform }}.msix"
env:
Platform: ${{ matrix.platform }}
# Upload artifacts
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: silentnotes_windows_binaries
path: .\windows
##############################################################################
# Windows packaging
# Package all msix to a single msixbundle for uploading to the Microsoft store
##############################################################################
job_package:
needs: [job_version, job_build_windows]
if: ${{ inputs.build-windows }}
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download msix files
uses: actions/download-artifact@v3
with:
name: silentnotes_windows_binaries
path: downloaddirectory
- name: Collect msix files
run: |
New-Item -Path ".\msixdirectory" -ItemType "directory"
Move-Item -Path .\downloaddirectory\*.msix -Destination .\msixdirectory
- name: Make msixbundle
id: bundler
uses: LanceMcCarthy/[email protected]
with:
msix-folder: "msixdirectory"
msixbundle-filepath: "silentnotes.msixbundle"
msixbundle-version: "${{needs.job_version.outputs.formatted_version}}.0"
# Upload artifacts
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: silentnotes_windows_binaries
path: .\**\*.msixbundle
retention-days: 1
##############################################################################
# Publish release on Github
##############################################################################
job_publish_release:
needs: [job_version, job_build_android, job_build_android_additional_platform]
if: ${{ inputs.publish-release }}
runs-on: windows-latest
env:
Solution_Name: SilentNotes.sln
Project_Path: src\SilentNotes.Blazor\SilentNotes.csproj
Android_Manifest: src\SilentNotes.Blazor\Platforms\Android\AndroidManifest.xml
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download files for publishing
uses: actions/download-artifact@v4
with:
path: downloaddirectory
pattern: silentnotes_android*
merge-multiple: true
- name: Collect files for publishing
run: |
New-Item -Path ".\publish" -ItemType "directory"
Move-Item -Path .\downloaddirectory\*.apk -Destination .\publish
- name: release
uses: softprops/action-gh-release@v1
id: create_release
with:
draft: false
prerelease: false
name: ${{ env.Version_Title }}
tag_name: ${{ env.Tag }}
body_path: ${{ env.Change_Log }}
files: |
./publish/*.apk
env:
GITHUB_TOKEN: ${{ github.token }}
Version_Title: "Version ${{needs.job_version.outputs.formatted_version}}"
Tag: "v${{needs.job_version.outputs.formatted_version}}"
Change_Log: "./fastlane/metadata/android/en-US/changelogs/${{needs.job_version.outputs.integer_version}}.txt"