Build Android app #5
This file contains 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 Android app | |
on: | |
workflow_dispatch: | |
inputs: | |
input_app_version: | |
description: 'Application version' | |
required: true | |
type: string | |
default: '1.0.0' | |
jobs: | |
build: | |
runs-on: windows-latest | |
env: | |
Solution_Name: RacingCarsController.sln | |
Project_Path: RacingCarsControllerAndroid/RacingCarsControllerAndroid.csproj | |
Publish_Directory: RacingCarsControllerAndroid/bin/Release/net8.0-android/publish | |
Project_Directory: RacingCarsControllerAndroid | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
# Update the appxmanifest before build by setting the per-channel values set in the matrix. | |
- name: Change Version | |
run: | | |
# Get current version code and increment | |
$manifestPath = "$env:Project_Directory/AndroidManifest.xml" | |
$csprojPath = $env:Project_Path | |
$newVersionCode = git rev-list HEAD --count | |
$newVersionName = ${{ inputs.input_app_version }} | |
# Update manifest | |
(Get-Content $manifestPath) -Replace 'android:versionCode="\d+"', "android:versionCode=`"${newVersionCode}`"" | Set-Content $manifestPath | |
(Get-Content $manifestPath) -Replace 'android:versionName="[\w\d.-]+"', "android:versionName=`"$newVersionName`"" | Set-Content $manifestPath | |
# Update project | |
(Get-Content $csprojPath) -Replace '<ApplicationVersion>\d+</ApplicationVersion>', "<ApplicationVersion>$newVersionCode</ApplicationVersion>" | Set-Content $csprojPath | |
(Get-Content $csprojPath) -Replace '<ApplicationDisplayVersion>[\w\d.-]+</ApplicationDisplayVersion>', "<ApplicationDisplayVersion>$newVersionName</ApplicationDisplayVersion>" | Set-Content $csprojPath | |
- name: Setup .NET 8 | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 8.0.x | |
- name: Install MAUI Android Workload | |
run: dotnet workload install maui-android --ignore-failed-sources | |
- name: Restore Dependencies | |
run: dotnet restore $env:Project_Path | |
- name: Build Android | |
run: dotnet publish $env:Project_Path -c Release -f net8.0-android /p:AndroidSigningKeyPass=${{ secrets.SIGNING_KEY_PASS }} /p:AndroidSigningStorePass=${{ secrets.SIGNING_KEY_PASS }} | |
# Move package | |
- name: Move package | |
run: | | |
$appName = 'RacingCarsController' | |
$package = 'com.tmk907.RacingCarsControllerAndroid' | |
$architectures = @('arm64-v8a','armeabi-v7a','x86_64') | |
foreach($arch in $architectures){ | |
$apkName = "$package-$arch-Signed.apk" | |
$publishedApkName = "$appName-v${{ inputs.input_app_version }}-$arch.apk" | |
Move-Item -Path "$env:Publish_Directory\$apkName" -Destination ./ | |
Write-Host "$publishedApkName moved" | |
} | |
# Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact | |
- name: Upload MSIX package | |
uses: actions/upload-artifact@v3 | |
with: | |
name: RacingCarsControllerAndroid | |
path: | | |
./*.apk | |
- name: Create a GitHub release | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: android-v${{ inputs.input_app_version }} | |
name: Release Android ${{ inputs.input_app_version }} | |
artifacts: "./*.apk" | |
generateReleaseNotes: true | |
allowUpdates: true | |
token: ${{ secrets.GITHUB_TOKEN }} | |