Skip to content

Commit

Permalink
dotnet workload install maui android
Browse files Browse the repository at this point in the history
  • Loading branch information
danzuep committed Dec 6, 2023
1 parent 164dc51 commit 18c89cb
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 106 deletions.
103 changes: 74 additions & 29 deletions .github/workflows/_publish.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 🚀 Publish Android package
run-name: Publish ${{ inputs.projectName }} Android package
run-name: Publish Android package

on:
workflow_call:
Expand All @@ -25,38 +25,83 @@ on:
default: Release
type: string

env:
DotNetVersion: 8.0.x
DotNetTarget: net8.0
# https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json
SourceLink: https://aka.ms/dotnet8/nuget/index.json
# https://maui.blob.core.windows.net/metadata/rollbacks/net8.0.json
RollbackLink: https://aka.ms/dotnet/maui/net8.0.json
NuGetLink: https://api.nuget.org/v3/index.json

jobs:
deploy:
name: Android
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}

steps:
# https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
- name: Checkout the source repository from Git
uses: actions/checkout@v4

# https://github.com/actions/setup-dotnet
- name: Get .NET externals
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-quality: 'ga'

- name: Publish Android package
run: |
echo "Project Name: ${{ inputs.projectName }}";
echo "Project File: $projectFile";
echo "Project Version: $buildVersion";
dotnet workload restore;
dotnet publish $projectFile -c $configuration -f $targetFramework /p:Version=$buildVersion /p:AndroidPackageFormats=$androidPackageFormats -o $publishOutputFolder --nologo;
env:
projectFile: '${{ inputs.projectFile }}'
buildVersion: '${{ inputs.version }}'
configuration: ${{ inputs.configuration }}
targetFramework: "net8.0-android"
androidPackageFormats: "apk" # "aab;apk"
publishOutputFolder: "publish"

- name: Markdown workflow job summary
run: echo "### ${{ inputs.projectName }} ${{ inputs.version }} apk published" >> $GITHUB_STEP_SUMMARY
# https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
- name: Checkout the source repository from Git
uses: actions/checkout@v4

# https://github.com/actions/setup-dotnet
- name: Get .NET externals
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DotNetVersion }}
dotnet-quality: 'ga'

- name: Install .NET MAUI
shell: pwsh
run: |
echo "Project Name: ${{ inputs.projectName }}";
dotnet --version;
dotnet workload install maui android ${{ env.PackageLinks }}
# dotnet nuget locals all --clear
# dotnet workload install maui android ios maccatalyst tvos macos wasm-tools ${{ env.PackageLinks }}
env:
PackageLinks: "--from-rollback-file ${{env.RollbackLink}} --source ${{env.SourceLink}} --source ${{env.NuGetLink}}"

# - name: Create signing pfx file from secrets
# shell: pwsh
# id: secret-file
# env:
# SECRET_DATA1: ${{ secrets.WIN_SIGN_CERT }}
# run: |
# $secretFile = "XamCATFidCert.pfx";
# $encodedBytes = [System.Convert]::FromBase64String($env:SECRET_DATA1);
# Set-Content $secretFile -Value $encodedBytes -AsByteStream;
# Write-Output "SECRET_FILE=${secretFile}" | Out-File -FilePath $env:GITHUB_ENV -Append
# if (-Not (Test-Path -Path "${kestorePath}" -PathType Leaf)) {
# throw "The file '${kestorePath}' was not found."
# }

# - name: Pack Windows App
# shell: pwsh
# run: |
# & "C:\Program Files (x86)\Windows Kits\10\App Certification Kit\MakeAppx" pack /v /h SHA256 /d "<OUTPUT_FOLDER_PATH>" /p <PATH TO MSIX>.msix
# & ls

# - name: Sign Windows App
# shell: pwsh
# env:
# CERT_PASSWORD: ${{ secrets.WIN_CERT_PASSWORD }}
# run: |
# & "C:\Program Files (x86)\Windows Kits\10\App Certification Kit\SignTool" sign /a /fd SHA256 /f XamCATFidCert.pfx /p $WIN_CERT_PASSWORD <PATH TO MSIX>.msix

- name: Publish Android package
run: |
echo "Project File: $projectFile";
echo "Project Version: $buildVersion";
dotnet publish $projectFile -c $configuration -f $targetFramework /p:Version=$buildVersion /p:AndroidPackageFormats=$androidPackageFormats -o $publishOutputFolder --nologo;
env:
projectFile: '${{ inputs.projectFile }}'
buildVersion: '${{ inputs.version }}'
configuration: ${{ inputs.configuration }}
targetFramework: "${{ env.DotNetTarget }}-android"
androidPackageFormats: "apk" # "aab;apk"
publishOutputFolder: "publish"

- name: Markdown workflow job summary
run: echo "### ${{ inputs.projectName }} ${{ inputs.version }} apk published" >> $GITHUB_STEP_SUMMARY
142 changes: 71 additions & 71 deletions .github/workflows/_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,82 +30,82 @@ jobs:
projectFile: ${{ steps.metadata.outputs.projectFile }}

steps:
# https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
- name: Fetch all tags and branches for GitVersion
uses: actions/checkout@v4
with:
fetch-depth: 0
# https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches
- name: Fetch all tags and branches for GitVersion
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get Git repository project name and list all project files in the directory
id: metadata
shell: bash
run: |
repositoryName=$(basename '${{ github.repository }}')
echo "Project name: $repositoryName"
shopt -s globstar
for project in ./**/*.csproj; do
echo "Project file: $project"
projectFile=${project}
done
echo "projectName=${repositoryName}" >> $GITHUB_ENV
echo "projectName=${repositoryName}" >> $GITHUB_OUTPUT
echo "projectFile=${projectFile}" >> $GITHUB_ENV
echo "projectFile=${projectFile}" >> $GITHUB_OUTPUT
- name: Get Git repository project name and list all project files in the directory
id: metadata
shell: bash
run: |
repositoryName=$(basename '${{ github.repository }}')
echo "Project name: $repositoryName"
shopt -s globstar
for project in ./**/*.csproj; do
echo "Project file: $project"
projectFile=${project}
done
echo "projectName=${repositoryName}" >> $GITHUB_ENV
echo "projectName=${repositoryName}" >> $GITHUB_OUTPUT
echo "projectFile=${projectFile}" >> $GITHUB_ENV
echo "projectFile=${projectFile}" >> $GITHUB_OUTPUT
- run: |
echo "Generate release notes from the Git commit log."
echo "## $projectName" > release-notes.txt
git log --pretty=format:"- %s" >> release-notes.txt
- run: |
echo "Generate release notes from the Git commit log."
echo "## $projectName" > release-notes.txt
git log --pretty=format:"- %s" >> release-notes.txt
# # TODO: fix this
# - run: |
# echo "Generate release notes from the Git commit log."
# last_tag=$(git describe --abbrev=0 --tags 2>/dev/null)
# if [[ -z "$last_tag" ]]; then
# echo "## $projectName" > release-notes.txt
# git log --pretty=format:"- %s" >> release-notes.txt
# else
# echo "## $projectName changes since $last_tag" > release-notes.txt
# git log --pretty=format:"- %s" --since="$last_tag" >> release-notes.txt
# fi
# # TODO: fix this
# - run: |
# echo "Generate release notes from the Git commit log."
# last_tag=$(git describe --abbrev=0 --tags 2>/dev/null)
# if [[ -z "$last_tag" ]]; then
# echo "## $projectName" > release-notes.txt
# git log --pretty=format:"- %s" >> release-notes.txt
# else
# echo "## $projectName changes since $last_tag" > release-notes.txt
# git log --pretty=format:"- %s" --since="$last_tag" >> release-notes.txt
# fi

# https://github.com/GitTools/actions/blob/main/docs/examples/github/gitversion/setup/usage-examples.md#example-1
- name: Set up GitVersion
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: '5.x'
# https://github.com/GitTools/actions/blob/main/docs/examples/github/gitversion/setup/usage-examples.md#example-1
- name: Set up GitVersion
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: '5.x'

# https://github.com/GitTools/actions/blob/main/docs/examples/github/gitversion/execute/usage-examples.md#example-5
# For a list of all GitVersion Version Variables, see https://gitversion.net/docs/reference/variables
# pwsh> dotnet-gitversion | ConvertFrom-Json
- name: Use GitVersion to determine version
id: gitversion # e.g. steps.gitversion.outputs.<outputName>
uses: gittools/actions/gitversion/execute@v0
# https://github.com/GitTools/actions/blob/main/docs/examples/github/gitversion/execute/usage-examples.md#example-5
# For a list of all GitVersion Version Variables, see https://gitversion.net/docs/reference/variables
# pwsh> dotnet-gitversion | ConvertFrom-Json
- name: Use GitVersion to determine version
id: gitversion # e.g. steps.gitversion.outputs.<outputName>
uses: gittools/actions/gitversion/execute@v0

- run: |
echo 'Save the GitVersion environment variables to a file.'
echo "projectName=${projectName}" > version.txt
echo "projectFile=${projectFile}" >> version.txt
for var in $(env | grep '^GitVersion_' | cut -d= -f1); do
echo "$var=${!var}" >> version.txt
done
- run: |
echo 'Save the GitVersion environment variables to a file.'
echo "projectName=${projectName}" > version.txt
echo "projectFile=${projectFile}" >> version.txt
for var in $(env | grep '^GitVersion_' | cut -d= -f1); do
echo "$var=${!var}" >> version.txt
done
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary
- name: Markdown workflow job summary
run: |
echo '### ${{ env.workflowVersion }} build summary' >> $GITHUB_STEP_SUMMARY
echo "Repository: ${{ github.repository }}" >> $GITHUB_STEP_SUMMARY
echo "Branch: ${{ github.ref }}" >> $GITHUB_STEP_SUMMARY
echo 'Commit Date: ${{ steps.gitversion.outputs.commitDate }}' >> $GITHUB_STEP_SUMMARY
echo 'Full Semantic Version: ${{ steps.gitversion.outputs.fullSemVer }}' >> $GITHUB_STEP_SUMMARY
echo 'Pre-release Label: ${{ steps.gitversion.outputs.preReleaseLabel }}' >> $GITHUB_STEP_SUMMARY
env:
workflowVersion: '${{ steps.metadata.outputs.projectName }} version ${{ steps.gitversion.outputs.semVer }}'
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary
- name: Markdown workflow job summary
run: |
echo '### ${{ env.workflowVersion }} build summary' >> $GITHUB_STEP_SUMMARY
echo "Repository: ${{ github.repository }}" >> $GITHUB_STEP_SUMMARY
echo "Branch: ${{ github.ref }}" >> $GITHUB_STEP_SUMMARY
echo 'Commit Date: ${{ steps.gitversion.outputs.commitDate }}' >> $GITHUB_STEP_SUMMARY
echo 'Full Semantic Version: ${{ steps.gitversion.outputs.fullSemVer }}' >> $GITHUB_STEP_SUMMARY
echo 'Pre-release Label: ${{ steps.gitversion.outputs.preReleaseLabel }}' >> $GITHUB_STEP_SUMMARY
env:
workflowVersion: '${{ steps.metadata.outputs.projectName }} version ${{ steps.gitversion.outputs.semVer }}'

# https://github.com/actions/upload-artifact
- name: Upload version artifacts
uses: actions/upload-artifact@v3
with:
path: |
version.txt
release-notes.txt
# https://github.com/actions/upload-artifact
- name: Upload version artifacts
uses: actions/upload-artifact@v3
with:
path: |
version.txt
release-notes.txt
3 changes: 0 additions & 3 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ run-name: Get version and build release notes

on:
workflow_dispatch:
push:
branches:
- main

# Cancel any other running workflows with the same ID
concurrency:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- 'v[0-9]+.[0-9]+.*'
branches:
- release/**
- devops

# Cancel any other running workflows with the same ID
concurrency:
Expand Down
Binary file removed Assets/Videos/Android.mp4
Binary file not shown.
Binary file removed Assets/Videos/PC.mp4
Binary file not shown.
24 changes: 23 additions & 1 deletion LocalGuideAI/LocalGuideAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Nullable>enable</Nullable>

<!-- Display name -->
<ApplicationTitle>LocalGuideAI</ApplicationTitle>
<ApplicationTitle>AI Local Guide</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.danzuep.localguideai</ApplicationId>
Expand All @@ -30,6 +30,9 @@
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<!-- C# Hot Reload -->
<UseInterpreter Condition="'$(Configuration)' == 'Debug'">True</UseInterpreter>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
Expand All @@ -39,6 +42,25 @@
<UserSecretsId>LocalGuideAI-69b33f45-de4c-4083-9a70-939952647ea2</UserSecretsId>
</PropertyGroup>

<!-- https://learn.microsoft.com/en-us/dotnet/maui/android/deployment/publish-cli?view=net-maui-8.0#define-build-properties-in-your-project-file -->
<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
<OutputType>WinExe</OutputType>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>

<!--<PropertyGroup Condition="$(TargetFramework.Contains('-android')) and '$(Configuration)' == 'Release'">
<AndroidKeyStore>True</AndroidKeyStore>
<AndroidPackageFormats>apk</AndroidPackageFormats>
<AndroidSigningKeyStore>../release/android.keystore</AndroidSigningKeyStore>
<AndroidSigningKeyAlias>android-key</AndroidSigningKeyAlias>
<AndroidSigningKeyPass>env:AndroidSigningPassword</AndroidSigningKeyPass>
<AndroidSigningStorePass>env:AndroidSigningPassword</AndroidSigningStorePass>
</PropertyGroup>-->

<!--<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
</PropertyGroup>-->

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LocalGuideAI

A local guide in the form of an app that uses ChatGPT AI. A project for Microsoft Hack Together: The Great .NET 8 Hack.
A local guide in the form of a C# .NET MAUI app that uses ChatGPT AI. A project for Microsoft Hack Together: The Great .NET 8 Hack.

![PC](https://raw.githubusercontent.com/danzuep/LocalGuideAI/main/Assets/Animations/PC.gif)

Expand Down
16 changes: 15 additions & 1 deletion Scripts/publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ $projectName = $projectDirectory.BaseName;
$projectAppName = "${projectName}";
$projectFile="${projectFolder}/${projectAppName}/${projectAppName}.csproj";

# #$dotnetVersion="8.0.x";
# $NuGetLink="https://api.nuget.org/v3/index.json"
# # https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json
# $SourceLink="https://aka.ms/dotnet8/nuget/index.json"
# # https://maui.blob.core.windows.net/metadata/rollbacks/net8.0.json
# $RollbackLink="https://aka.ms/dotnet/maui/net8.0.json"
# $PackageLinks="--from-rollback-file ${RollbackLink} --source ${SourceLink} --source ${NuGetLink}"
# dotnet workload install maui android ${PackageLinks}

# restore the base project dependencies
Set-Location -Path "${projectFolder}";
dotnet restore "${projectFile}";
Expand All @@ -27,7 +36,7 @@ $androidPackageFormats="apk"; # "aab;apk"
$targetFramework="${dotnetTarget}-android";
$publishOutputFolder="publish";
$publishPath = [IO.Path]::Combine($projectFolder, $publishOutputFolder);
$kestoreFolder = [IO.Path]::Combine($Env:LOCALAPPDATA, "Android");
$kestoreFolder = [IO.Path]::Combine($Env:LOCALAPPDATA, "Android"); # %LocalAppData%
if (-Not (Test-Path -Path "${kestoreFolder}" -PathType Container))
{
New-Item -ItemType Directory -Path "${kestoreFolder}";
Expand All @@ -40,6 +49,11 @@ if (-Not (Test-Path -Path "${kestorePath}" -PathType Leaf))
keytool -list -keystore "${kestorePath}";
}

Write-Host "Local .NET Version: "; dotnet --version;
Write-Host "Target Framework: ${targetFramework}";
Write-Host "Project File: ${projectFile} (version ${buildVersion})";

# dotnet publish "${projectFile}" -c $configuration --framework $targetFramework /p:Version=$buildVersion /p:AndroidPackageFormats=$androidPackageFormats -o "${publishOutputFolder}" --no-restore --nologo;
dotnet publish "${projectFile}" -c $configuration --framework $targetFramework /p:Version=$buildVersion /p:AndroidPackageFormats=$androidPackageFormats /p:AndroidKeyStore=true /p:AndroidSigningKeyStore="${kestorePath}" /p:AndroidSigningKeyAlias="${androidSigningAlias}" /p:AndroidSigningKeyPass="${Env:AndroidSigningPassword}" /p:AndroidSigningStorePass="${Env:AndroidSigningPassword}" -o "${publishOutputFolder}" --no-restore --nologo;
if (-not $?) {
Write-Host "Project failed to publish.";
Expand Down

0 comments on commit 18c89cb

Please sign in to comment.