-
Notifications
You must be signed in to change notification settings - Fork 36
368 lines (312 loc) · 13.2 KB
/
build-silentnotes.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# 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/get-xml-info@1.2.1
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/get-xml-info@1.2.1
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/Action-MsixBundler@v1.0.0
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"