-
Notifications
You must be signed in to change notification settings - Fork 15
385 lines (328 loc) · 13.6 KB
/
build.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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
name: Build
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
types: [opened, synchronize, reopened]
workflow_dispatch:
inputs:
flag:
description: 'Publish?'
required: true
default: false
type: boolean
tag1:
description: 'Pre/Release?'
required: true
default: 'beta'
type: choice
options:
- beta
- v
tag2:
description: 'Version?(e.g 2.0.0.6)'
required: true
type: string
jobs:
build:
# Ignore draft PRs
if: github.event_name != 'pull_request' || (github.event_name == 'pull_request' && github.event.pull_request.draft == false)
runs-on: windows-latest
strategy:
matrix:
architecture: [x64, arm64]
env:
Solution_Name: Natsurainko.FluentLauncher
Project_Directory: Natsurainko.FluentLauncher
Configuration: Release
Packages_DirectoryName: AppPackages
Packages_Directory: Natsurainko.FluentLauncher\AppPackages
SigningKey_Path: SigningKey.pfx
name: Build (${{ matrix.architecture }})
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1.3
- name: Get NuGet Dependencies
run: .\.github\write-nuget-cache-file.ps1
# - name: Cache NuGet packages
# id: cache
# uses: actions/cache@v3
# with:
# path: |
# ~\.nuget\packages
# ~\AppData\Roaming\NuGet\NuGet.Config
# key: ${{ runner.os }}-nuget-${{ hashFiles('.package-references.xml') }}
# restore-keys: |
# ${{ runner.os }}-nuget-
- name: Add nuget source
# if: steps.cache.outputs.cache-hit != 'true'
run: dotnet nuget add source "https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-Labs/nuget/v3/index.json"
- name: Init SubModules
run: git submodule update --init --recursive
# Restore the application to populate the obj folder with RuntimeIdentifiers
- name: Restore NuGet packages
# must run
run: dotnet restore # msbuild $env:Solution_Name /t:Restore /p:Configuration=Release
# Prepare FluentLauncher.LocalizationPoroject
- name: Prepare FluentLauncher.LocalizationPoroject
run: .\update-localization.ps1
# Create the app package by building and packaging the Windows Application Packaging project
- name: Create app package
run: |
msbuild $env:Solution_Name /p:Platform=$env:Platform /p:AppxBundlePlatforms="$env:Appx_Bundle_Platforms" /p:Configuration=$env:Configuration /p:UapAppxPackageBuildMode=$env:Appx_Package_Build_Mode /p:AppxBundle=$env:Appx_Bundle /p:AppxPackageDir="$env:Appx_Package_Dir" /p:GenerateAppxPackageOnBuild=true
env:
Appx_Bundle: Never
Platform: ${{ matrix.architecture }}
Appx_Bundle_Platforms: ${{ matrix.architecture }}
Appx_Package_Build_Mode: SideloadOnly
Appx_Package_Dir: ${{ env.Packages_DirectoryName }}\ # DO NOT REMOVE THE TRAILING SLASH
- name: Prepare for bundling
id: preparation
run: |
# Get package name
$msixFile = Get-Item -Path "${{ env.Packages_Directory }}\*\*.msix"
$packageName = [System.IO.Path]::GetFileNameWithoutExtension($msixFile.FullName)
echo "::set-output name=packageName::$packageName"
# Get version number
$version = $packageName -replace '^(.*?Natsurainko\.FluentLauncher)_(\d+\.\d+\.\d+\.\d+)(_x64|_arm64)$', '$2'
echo "::set-output name=version::$version"
# Get package directory
$directory = $msixFile.DirectoryName
echo "::set-output name=packageDirectory::$directory"
# Rename .msixsym to .appxsym to pass Partner Center validation
# Move .appx to root directory for making .msixupload
mv "$directory\$packageName.msixsym" ".\$packageName.appxsym"
# Move .msix for upload to artifacts
mv ${{ env.Packages_Directory }}\*\*.msix "$packageName.msix"
# Decode the base 64 encoded pfx and sign the package
- name: Sign .msix
run: |
# Get signtool.exe
$signtool = Get-Item -Path "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\signtool.exe"
if ($signtool -is [array]) {
$signtool = $signtool[0]
}
# Sign .msix
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.PFX_BASE64_ENCODED }}")
[IO.File]::WriteAllBytes("${{ env.SigningKey_Path }}", $pfx_cert_byte)
& $signtool sign /f "${{ env.SigningKey_Path }}" /fd SHA256 /td SHA256 "${{ steps.preparation.outputs.packageName }}.msix"
rm "${{ env.SigningKey_Path }}"
- name: Upload .msix to artifacts
uses: actions/upload-artifact@v2
with:
name: .msix
path: ${{ steps.preparation.outputs.packageName }}.msix
- name: Create .msixupload
id: create_msixupload
env:
PackageName: ${{ steps.preparation.outputs.packageName }}
PackageDirectory: ${{ steps.preparation.outputs.packageDirectory }}
Version: ${{ steps.preparation.outputs.version }}
TmpDirectory: .\tmp
run: |
# Get makeappx.exe
$makeappx = Get-Item -Path "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\makeappx.exe"
if ($makeappx -is [array]) {
$makeappx = $makeappx[0]
}
# Convert .msix to .msixbundle
mkdir "$env:TmpDirectory"
mv "$env:PackageName.msix" "$env:TmpDirectory\$env:PackageName.msix"
& $makeappx.FullName bundle /d "$env:TmpDirectory" /p "$env:PackageName.msixbundle" /bv $env:Version
# Create .msixupload
$msixbundlePath = $env:PackageName + '.msixbundle'
$appxsymPath = $env:PackageName + '.appxsym'
Compress-Archive -Path $msixbundlePath, $appxsymPath -DestinationPath "$env:PackageName.zip"
mv "$env:PackageName.zip" "$env:PackageName.msixupload"
- name: Upload .msixupload to artifacts
uses: actions/upload-artifact@v2
with:
name: .msixupload
path: ${{ steps.preparation.outputs.packageName }}.msixupload
release:
name: Release
needs: build
runs-on: windows-latest
env:
SigningKey_Path: SigningKey.pfx
Artifacts_Path: .artifacts
steps:
- name: CheckOut
uses: actions/checkout@v3
- name: Download .msix from artifacts
uses: actions/download-artifact@v3
with:
name: .msix
path: ${{ env.Artifacts_Path }}
- name: Get Package Information
id: get_package_info
run: |
# Get the name of the .msix file
$file = Get-Item -Path "${{ env.Artifacts_Path }}\*.msix"
if ($file -is [array]) {
$file = $file[0]
}
# Extract the package name with version number
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($file.FullName)
$bundleFileName = $fileName -replace '^(.*?Natsurainko\.FluentLauncher)_(\d+\.\d+\.\d+\.\d+)(_x64|_arm64)$', '$1_$2.msixbundle'
$version = $fileName -replace '^(.*?Natsurainko\.FluentLauncher)_(\d+\.\d+\.\d+\.\d+)(_x64|_arm64)$', '$2'
echo "::set-output name=bundleFileName::$bundleFileName"
echo "::set-output name=version::$version"
- name: Create .msixbundle
run: |
# Get makeappx.exe
$makeappx = Get-Item -Path "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\makeappx.exe"
if ($makeappx -is [array]) {
$makeappx = $makeappx[0]
}
# Create the .msixbundle using makeappx.exe
& $makeappx.FullName bundle /d "${{ env.Artifacts_Path }}" /p "${{ steps.get_package_info.outputs.bundleFileName }}" /bv "${{ steps.get_package_info.outputs.version }}"
# Decode the base 64 encoded pfx and sign the package
- name: Sign .msixbundle
run: |
# Get signtool.exe
$signtool = Get-Item -Path "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\signtool.exe"
if ($signtool -is [array]) {
$signtool = $signtool[0]
}
# Sign .msixbundle
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.PFX_BASE64_ENCODED }}")
[IO.File]::WriteAllBytes("${{ env.SigningKey_Path }}", $pfx_cert_byte)
& $signtool sign /f "${{ env.SigningKey_Path }}" /fd SHA256 /td SHA256 "${{ steps.get_package_info.outputs.bundleFileName }}"
rm "${{ env.SigningKey_Path }}"
- name: Upload .msixbundle to artifacts
uses: actions/upload-artifact@v2
with:
name: .msixbundle
path: ${{ steps.get_package_info.outputs.bundleFileName }}
Create-Tag:
runs-on: ubuntu-latest
name: Create-Tag
needs: [build]
if: ${{inputs.flag}}
outputs:
tag: 'refs/tags/${{inputs.tag1}}${{inputs.tag2}}'
steps:
- name: CheckOut
uses: actions/checkout@v3
- name: config Git
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub-actions[bot]"
- name: Create Tag
run: |
git tag -a ${{inputs.tag1}}${{inputs.tag2}} -m "${{inputs.tag1}}${{inputs.tag2}}"
git push origin ${{inputs.tag1}}${{inputs.tag2}}
Pre-Publish:
runs-on: ubuntu-latest
name: Pre-Publish
needs: [build,release,Create-Tag]
if: ${{ (contains(github.ref,'refs/tags/beta')||(inputs.flag&&contains(needs.Create-Tag.outputs.tag,'beta'))||(inputs.flag&&contains(needs.Create-Tag.outputs.tag,'v')))&&!failure() }}
env:
Artifacts_Path: .artifacts
steps:
- name: CheckOut
uses: actions/checkout@v3
- name: CheckTag
id: CheckTag
run: |
if [ "${{inputs.flag}}" ]; then
echo "tag=${{needs.Create-Tag.outputs.tag}}" >> "$GITHUB_OUTPUT"
echo exit 0
else
echo "tag=${{github.ref}}" >> "$GITHUB_OUTPUT"
echo exit 0
fi
- name: Download .msixupload from artifacts
uses: actions/download-artifact@v3
with:
name: .msixupload
path: "${{ github.workspace }}/${{env.Artifacts_Path}}"
- name: Delete arm Pkg
run: find "${{ github.workspace }}/${{env.Artifacts_Path}}" -name '*arm*' -exec rm {} \;
- name: Pre-Publish MSStore
uses: trympet/microsoft-store-flight-action@v1
with:
tenant-id: ${{ secrets.PARTNER_CENTER_TENANT_ID }}
client-id: ${{ secrets.PARTNER_CENTER_CLIENT_ID }}
client-secret: ${{ secrets.PARTNER_CENTER_CLIENT_SECRET }}
app-id: ${{ secrets.PARTNER_CENTER_APP_ID }}
flight-id: ${{ secrets.PARTNER_CENTER_BETA_APP_ID }}
package-path: "${{ github.workspace }}/${{env.Artifacts_Path}}/"
delete-pending: true
delete-packages: true
skip-polling: true
packages-keep: 9
- name: Download .msixbundle from artifacts
if: ${{ !contains(needs.Create-Tag.outputs.tag,'v') }}
uses: actions/download-artifact@v3
with:
name: .msixbundle
path: "${{ github.workspace }}/${{env.Artifacts_Path}}"
- name: Create Pre-Release
if: ${{ !contains(needs.Create-Tag.outputs.tag,'v') }}
uses: ncipollo/release-action@v1.12.0
with:
artifacts: "${{ github.workspace }}/${{env.Artifacts_Path}}/*.msixbundle"
prerelease: true
allowUpdates: true
generateReleaseNotes: true
tag: ${{steps.CheckTag.outputs.tag}}
Publish:
runs-on: ubuntu-latest
name: Publish
needs: [build,release,Create-Tag]
if: ${{ (contains(github.ref,'v2')||(inputs.flag&&contains(needs.Create-Tag.outputs.tag,'v2')))&&!failure() }}
env:
Artifacts_Path: .artifacts
steps:
- name: CheckOut
uses: actions/checkout@v3
- name: CheckTag
id: CheckTag
run: |
if [ "${{inputs.flag}}" ]; then
echo "tag=${{needs.Create-Tag.outputs.tag}}" >> "$GITHUB_OUTPUT"
echo exit 0
else
echo "tag=${{github.ref}}" >> "$GITHUB_OUTPUT"
echo exit 0
fi
- name: Download .msixupload from artifacts
uses: actions/download-artifact@v3
with:
name: .msixupload
path: "${{ github.workspace }}/${{env.Artifacts_Path}}"
- name: Delete arm Pkg
run: find "${{ github.workspace }}/${{env.Artifacts_Path}}" -name '*arm*' -exec rm {} \;
- name: Publish MSStore
uses: isaacrlevin/windows-store-action@1.0
with:
tenant-id: ${{ secrets.PARTNER_CENTER_TENANT_ID }}
client-id: ${{ secrets.PARTNER_CENTER_CLIENT_ID }}
client-secret: ${{ secrets.PARTNER_CENTER_CLIENT_SECRET }}
app-id: ${{ secrets.PARTNER_CENTER_APP_ID }}
package-path: "${{ github.workspace }}/${{env.Artifacts_Path}}/"
delete-pending: true
delete-packages: true
skip-polling: true
packages-keep: 9
- name: Download .msixbundle from artifacts
uses: actions/download-artifact@v3
with:
name: .msixbundle
path: "${{ github.workspace }}/${{env.Artifacts_Path}}"
- name: Create Release
uses: ncipollo/release-action@v1.12.0
with:
artifacts: "${{ github.workspace }}/${{env.Artifacts_Path}}/*.msixbundle"
allowUpdates: true
generateReleaseNotes: true
tag: ${{steps.CheckTag.outputs.tag}}