Skip to content

Автосборка Music M #192

Автосборка Music M

Автосборка Music M #192

# 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}"