-
Notifications
You must be signed in to change notification settings - Fork 1
256 lines (205 loc) · 9.81 KB
/
dotnet-desktop.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
# This workflow will build, sign, and package a WinUI 3 MSIX desktop application
# built on .NET.
name: Автосборка Music M
on:
workflow_dispatch:
inputs:
namevers:
description: 'Название релиза'
required: true
default: '🤖 Автосборка'
descr:
description: 'Описание релиза'
required: true
default: '❌ Описание сборки отсутствует'
release:
description: 'Выкинуть в релиз?'
required: true
default: false
type: boolean
prerelease:
description: 'Пререлиз?'
required: true
default: true
type: boolean
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
strategy:
matrix:
configuration: [Release]
platform: [x64]
runs-on: windows-latest # For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
env:
Solution_Name: "VK UI3 (Package)" # Replace with your solution name, i.e. App1.sln.
steps:
- name: Checkout
uses: actions/checkout@v2
with:
node-version: 16
fetch-depth: 0
# Decode the base 64 encoded pfx and save the Signing_Certificate
- name: Decode the pfx
run: |
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.BASE64_ENCODED_PFX }}")
$certificatePath = "${{ github.workspace }}\GitHubActionsWorkflow.pfx"
[IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte)
# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2
# Restore the application to populate the obj folder with RuntimeIdentifiers
- name: Restore the application
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
env:
Configuration: ${{ matrix.configuration }}
- name: Print working directory
run: |
Write-Host "Current working directory: $(Get-Location)"
- name: Get Certificate Thumbprint and Replace in Project File
run: |
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.BASE64_ENCODED_PFX }}")
$certificatePath = "${{ github.workspace }}\GitHubActionsWorkflow.pfx"
[IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte)
$pfxPassword = ConvertTo-SecureString -String "${{ secrets.PFX_PASSWORD }}" -AsPlainText -Force
$pfxCert = Get-PfxCertificate -FilePath $certificatePath -Password $pfxPassword
Write-Host "Certificate Thumbprint: $($pfxCert.Thumbprint)"
$projectFile = "VK UI3 (Package)/VK UI3 (Package).wapproj"
$content = Get-Content -Path $projectFile -Raw
$content = $content -replace '(?<=<PackageCertificateThumbprint>).+?(?=</PackageCertificateThumbprint>)', $pfxCert.Thumbprint
Set-Content -Path $projectFile -Value $content
- name: Install PFX certificate
run: |
$certificatePath = "${{ github.workspace }}\GitHubActionsWorkflow.pfx"
$password = ConvertTo-SecureString -String "${{ secrets.PFX_PASSWORD }}" -Force -AsPlainText
Import-PfxCertificate -FilePath $certificatePath -CertStoreLocation Cert:\LocalMachine\My -Password $password
# Create the app package by building and packaging the project
- name: Create the app package
run: |
$platforms = "x64", "x86", "ARM64"
foreach ($platform in $platforms) {
$certificatePath = "${{ github.workspace }}\GitHubActionsWorkflow.pfx"
msbuild $env:Solution_Name /p:Configuration=$env:Configuration /p:Platform=$platform /p:UapAppxPackageBuildMode=$env:Appx_Package_Build_Mode /p:AppxBundle=$env:Appx_Bundle /p:PackageCertificateKeyFile="$certificatePath" /p:PackageCertificatePassword="${{ secrets.PFX_PASSWORD }}" /p:AppxPackageDir="$env:Appx_Package_Dir" /p:GenerateAppxPackageOnBuild=true
}
env:
Appx_Bundle: Never
Appx_Package_Build_Mode: SideloadOnly
Appx_Package_Dir: Packages\
Configuration: ${{ matrix.configuration }}
# Remove the pfx
- name: Remove the pfx
run: |
$certificatePath = "${{ github.workspace }}\GitHubActionsWorkflow.pfx"
Remove-Item -path "$certificatePath"
# Rename the .cer file
- name: Rename the .cer file
run: |
Get-ChildItem -Path "${{ env.Solution_Name }}\\Packages" -Filter *.cer -Recurse -Depth 1 | ForEach-Object {
Rename-Item -Path $_.FullName -NewName "Certificate.cer"
}
# Move .msix, .cer, and .msixbundle files from subfolders to the Packages folder
- name: Move files to the Packages folder
run: |
$fileTypes = "*.msix", "*.cer", "*.msixbundle"
foreach ($fileType in $fileTypes) {
Get-ChildItem -Path "${{ env.Solution_Name }}\\Packages" -Filter $fileType -Recurse -Depth 1 | ForEach-Object {
$destinationFile = "${{ env.Solution_Name }}\\Packages\\" + $_.Name
if (-Not (Test-Path -Path $destinationFile)) {
Move-Item -Path $_.FullName -Destination $destinationFile
}
}
}
- name: Display disk tree
run: |
Get-ChildItem -Recurse | Sort-Object Length -Descending
# Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload MSIX package
uses: actions/upload-artifact@v2
with:
name: MSIX Package
path: |
${{ env.Solution_Name }}\\Packages\*.cer
${{ env.Solution_Name }}\\Packages\*.msixbundle
${{ env.Solution_Name }}\\Packages\*.msix
- name: Извлечь версию
id: get_version
run: |
$repoName = "${{ github.repository }}".Split('/')[1]
$doc = New-Object xml
$doc.Load((Convert-Path "D:\a\$repoName\$repoName\VK UI3 (Package)\Package.appxmanifest"))
$nsManager = New-Object System.Xml.XmlNamespaceManager($doc.NameTable)
$nsManager.AddNamespace('default', 'http://schemas.microsoft.com/appx/manifest/foundation/windows10')
$version = $doc.SelectSingleNode('//default:Identity', $nsManager).Version
echo "::set-output name=VERSION::$version"
echo "Версия: $version"
continue-on-error: true
if: github.event.inputs.release == 'true'
- name: Вывести версию
run: |
echo "Извлеченная версия: ${{ steps.get_version.outputs.VERSION }}"
- name: Получить релизы
id: get_releases
run: |
$headers = @{
"Authorization" = "token ${{ secrets.TOKEN }}"
}
$releases = Invoke-RestMethod -Uri "https://api.github.com/repos/${{ github.repository }}/releases" -Headers $headers
echo "::set-output name=releases::$releases"
shell: pwsh
if: github.event.inputs.release == 'true'
- name: Проверить существование релиза
id: check_release
run: |
$version = "${{ steps.get_version.outputs.VERSION }}"
$headers = @{
"Authorization" = "token ${{ secrets.TOKEN }}"
}
$releases = Invoke-RestMethod -Uri "https://api.github.com/repos/${{ github.repository }}/releases" -Headers $headers
$release = $releases | Where-Object { $_.tag_name -eq $version -and $_.draft -eq $false -and $_.prerelease -eq $false }
if ($release) {
Write-Host "Релиз с тегом $version уже существует"
echo "::set-output name=exists::true"
} else {
Write-Host "Релиз с тегом $version не найден"
echo "::set-output name=exists::false"
}
shell: pwsh
if: github.event.inputs.release == 'true'
- name: Создать релиз
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.VERSION }}
release_name: ${{ github.event.inputs.namevers }}
body: ${{ github.event.inputs.descr }}
draft: false
prerelease: ${{ github.event.inputs.prerelease }}
if: steps.check_release.outputs.exists == 'false' && github.event.inputs.release == 'true'
- name: Загрузить файлы в релиз
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.TOKEN }}
file: ${{ env.Solution_Name }}/Packages/*
asset_name: ${{ env.Solution_Name }}-release-files
tag: ${{ steps.get_version.outputs.VERSION }}
overwrite: true
file_glob: true
if: steps.check_release.outputs.exists == 'false' && github.event.inputs.release == 'true'
- name: Отправить сообщение в Telegram
if: steps.check_release.outputs.exists == 'false' && github.event.inputs.release == 'true'
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
RELEASE_URL: https://github.com/${{ github.repository }}/releases/tag/${{ steps.get_version.outputs.VERSION }}
run: |
curl -s -X POST https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage -d chat_id=${TELEGRAM_CHAT_ID} -d text="Новый релиз: ${{ github.event.inputs.namevers }}\nВерсия: ${{ steps.get_version.outputs.VERSION }}\nОписание: ${{ github.event.inputs.descr }}\nSolution Name: ${{ env.Solution_Name }}\nСсылка на релиз: ${RELEASE_URL}"