refactor build info extraction to new script
This commit is contained in:
parent
5eee2572e2
commit
187fc4d439
3 changed files with 144 additions and 135 deletions
46
.github/workflows/version-check.yml
vendored
46
.github/workflows/version-check.yml
vendored
|
|
@ -44,49 +44,11 @@ jobs:
|
|||
- name: Checkout repository
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Get build type and send to GAS
|
||||
- name: Get build info and send to GAS
|
||||
shell: pwsh
|
||||
env:
|
||||
GOOGLE_APPS_URL: ${{ secrets.GOOGLE_APPS_URL }}
|
||||
versions: ${{ needs.version-search.outputs.versions }}
|
||||
source: ${{ github.event.client_payload.s }}
|
||||
VERSIONS: ${{ needs.version-search.outputs.versions }}
|
||||
SOURCE: ${{ github.event.client_payload.s }}
|
||||
run: |
|
||||
# Получаем build type
|
||||
$versionsJson = $env:versions | ConvertFrom-Json
|
||||
$win64Url = $versionsJson.WIN64
|
||||
|
||||
if ($win64Url) {
|
||||
./get-build-info.ps1 -Url $win64Url
|
||||
$buildType = (Get-Content $env:GITHUB_OUTPUT | Select-String "build_type=(.+)" | ForEach-Object { $_.Matches.Groups[1].Value })
|
||||
} else {
|
||||
$buildType = "false"
|
||||
}
|
||||
|
||||
$versionsObj = $env:versions | ConvertFrom-Json
|
||||
|
||||
if ($buildType -eq "false") {
|
||||
$versionsObj | Add-Member -NotePropertyName "buildType" -NotePropertyValue $false -Force
|
||||
} else {
|
||||
$versionsObj | Add-Member -NotePropertyName "buildType" -NotePropertyValue $buildType -Force
|
||||
}
|
||||
|
||||
$versionsObj | Add-Member -NotePropertyName "source" -NotePropertyValue $env:source -Force
|
||||
|
||||
$finalJson = $versionsObj | ConvertTo-Json -Compress
|
||||
|
||||
Write-Host "Отправка данных на GAS..."
|
||||
Write-Host "Версия: $($versionsObj.version)"
|
||||
|
||||
# Отправляем в GAS через PowerShell
|
||||
try {
|
||||
$response = Invoke-WebRequest -Uri $env:GOOGLE_APPS_URL `
|
||||
-Method POST `
|
||||
-ContentType "application/json" `
|
||||
-Body $finalJson `
|
||||
-UseBasicParsing
|
||||
|
||||
Write-Host "Ответ от GAS: $($response.Content)"
|
||||
} catch {
|
||||
Write-Host "Ошибка при отправке в GAS: $_"
|
||||
exit 1
|
||||
}
|
||||
./check-build-version.ps1 -versions "$env:VERSIONS" -source "$env:SOURCE" -googleAppsUrl "$env:GOOGLE_APPS_URL"
|
||||
140
check-build-version.ps1
Normal file
140
check-build-version.ps1
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
param (
|
||||
[string]$versions,
|
||||
[string]$source,
|
||||
[string]$googleAppsUrl
|
||||
)
|
||||
|
||||
function Find-BuildInfo {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
|
||||
[string]$Path
|
||||
)
|
||||
|
||||
process {
|
||||
try {
|
||||
$fileContent = Get-Content -Path $Path -ErrorAction Stop
|
||||
$found = $false
|
||||
|
||||
$regex = '(Master|Release|PR|Local) Build.+(?:cef_)?(\d+\.\d+\.\d+\+g[0-9a-f]+\+chromium-\d+\.\d+\.\d+\.\d+)'
|
||||
|
||||
foreach ($line in $fileContent) {
|
||||
$match = [regex]::Match($line, $regex)
|
||||
if ($match.Success) {
|
||||
$buildType = $match.Groups[1].Value
|
||||
Write-Output "build type: $buildType"
|
||||
return $buildType
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $found) {
|
||||
Write-Output "Билд не найден"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error "Ошибка при чтении файла: $_"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Get-BuildTypeFromUrl {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$Url
|
||||
)
|
||||
|
||||
$tempPath = Join-Path ([System.IO.Path]::GetTempPath()) "spotify"
|
||||
$destinationPath = Join-Path $tempPath "unpacked"
|
||||
$exePath = Join-Path $tempPath "SpotifySetup.exe"
|
||||
|
||||
if (-not (Test-Path -Path $tempPath)) {
|
||||
New-Item -ItemType Directory -Path $tempPath | Out-Null
|
||||
}
|
||||
if (-not (Test-Path -Path $destinationPath)) {
|
||||
New-Item -ItemType Directory -Path $destinationPath | Out-Null
|
||||
}
|
||||
|
||||
try {
|
||||
Write-Output "Скачивание файла из $Url..."
|
||||
Invoke-WebRequest -Uri $Url -OutFile $exePath
|
||||
Write-Output "Файл сохранен в $exePath"
|
||||
|
||||
Write-Output "Распаковка файла в $destinationPath..."
|
||||
Start-Process -Wait -FilePath $exePath -ArgumentList "/extract `"$destinationPath`""
|
||||
Write-Output "Распаковка завершена"
|
||||
|
||||
$dllPath = Join-Path $destinationPath "Spotify.dll"
|
||||
$exePathForAnalysis = Join-Path $destinationPath "Spotify.exe"
|
||||
|
||||
if (Test-Path $dllPath) {
|
||||
return Find-BuildInfo -Path $dllPath
|
||||
} elseif (Test-Path $exePathForAnalysis) {
|
||||
return Find-BuildInfo -Path $exePathForAnalysis
|
||||
}
|
||||
else {
|
||||
Write-Error "Файлы Spotify.dll и Spotify.exe не найдены в $destinationPath"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error "Произошла ошибка при скачивании или распаковке: $_"
|
||||
return $false
|
||||
}
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrEmpty($versions) -or [string]::IsNullOrEmpty($source) -or [string]::IsNullOrEmpty($googleAppsUrl)) {
|
||||
Write-Error "Один или несколько обязательных параметров (versions, source, googleAppsUrl) не предоставлены."
|
||||
exit 1
|
||||
}
|
||||
|
||||
$versionsObj = $versions | ConvertFrom-Json
|
||||
$win64Url = $versionsObj.WIN64
|
||||
$buildType = $false
|
||||
|
||||
if ($win64Url) {
|
||||
$buildType = Get-BuildTypeFromUrl -Url $win64Url
|
||||
}
|
||||
|
||||
if ($buildType -eq $false) {
|
||||
$versionsObj | Add-Member -NotePropertyName "buildType" -NotePropertyValue $false -Force
|
||||
} else {
|
||||
$versionsObj | Add-Member -NotePropertyName "buildType" -NotePropertyValue $buildType -Force
|
||||
}
|
||||
|
||||
$versionsObj | Add-Member -NotePropertyName "source" -NotePropertyValue $source -Force
|
||||
|
||||
$finalJson = $versionsObj | ConvertTo-Json -Compress
|
||||
|
||||
Write-Host "Отправка данных на GAS..."
|
||||
Write-Host "JSON: $finalJson"
|
||||
|
||||
$maxRetries = 3
|
||||
$retryDelay = 5
|
||||
$attempt = 0
|
||||
$success = $false
|
||||
|
||||
while ($attempt -lt $maxRetries -and -not $success) {
|
||||
$attempt++
|
||||
try {
|
||||
Write-Host "Попытка отправки #$attempt..."
|
||||
$response = Invoke-WebRequest -Uri $googleAppsUrl `
|
||||
-Method POST `
|
||||
-ContentType "application/json" `
|
||||
-Body $finalJson `
|
||||
-UseBasicParsing -ErrorAction Stop
|
||||
|
||||
Write-Host "Ответ от GAS: $($response.Content)"
|
||||
$success = $true
|
||||
} catch {
|
||||
Write-Error "Ошибка при отправке в GAS: $_"
|
||||
if ($attempt -lt $maxRetries) {
|
||||
Write-Host "Ожидание $retryDelay секунд перед следующей попыткой..."
|
||||
Start-Sleep -Seconds $retryDelay
|
||||
} else {
|
||||
Write-Error "Не удалось отправить данные в GAS после $maxRetries попыток."
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
param (
|
||||
[string]$Url
|
||||
)
|
||||
|
||||
function Find-BuildInfo {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
|
||||
[string]$Path
|
||||
)
|
||||
|
||||
process {
|
||||
try {
|
||||
$fileContent = Get-Content -Path $Path -ErrorAction Stop
|
||||
$found = $false
|
||||
|
||||
$regex = '(Master|Release|PR|Local) Build.+(?:cef_)?(\d+\.\d+\.\d+\+g[0-9a-f]+\+chromium-\d+\.\d+\.\d+\.\d+)'
|
||||
|
||||
foreach ($line in $fileContent) {
|
||||
$match = [regex]::Match($line, $regex)
|
||||
if ($match.Success) {
|
||||
$buildType = $match.Groups[1].Value
|
||||
Write-Output "Тип билда: $buildType"
|
||||
$found = $true
|
||||
# Записываем вывод в файл окружения
|
||||
"build_type=$buildType" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
|
||||
# Прерываем цикл после первого найденного совпадения
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $found) {
|
||||
Write-Output "Билд не найден"
|
||||
"build_type=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error "Ошибка при чтении файла: $_"
|
||||
"build_type=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Download-And-Unpack-Spotify {
|
||||
[CmdletBinding()]
|
||||
# Параметр $Url теперь передается из области видимости скрипта
|
||||
|
||||
$tempPath = Join-Path ([System.IO.Path]::GetTempPath()) "spotify"
|
||||
$destinationPath = Join-Path $tempPath "unpacked"
|
||||
$exePath = Join-Path $tempPath "SpotifySetup.exe"
|
||||
|
||||
if (-not (Test-Path -Path $tempPath)) {
|
||||
New-Item -ItemType Directory -Path $tempPath | Out-Null
|
||||
}
|
||||
if (-not (Test-Path -Path $destinationPath)) {
|
||||
New-Item -ItemType Directory -Path $destinationPath | Out-Null
|
||||
}
|
||||
|
||||
try {
|
||||
Write-Output "Скачивание файла из $Url..."
|
||||
Invoke-WebRequest -Uri $Url -OutFile $exePath
|
||||
Write-Output "Файл сохранен в $exePath"
|
||||
|
||||
Write-Output "Распаковка файла в $destinationPath..."
|
||||
Start-Process -Wait -FilePath $exePath -ArgumentList "/extract `"$destinationPath`""
|
||||
Write-Output "Распаковка завершена"
|
||||
|
||||
$dllPath = Join-Path $destinationPath "Spotify.dll"
|
||||
$exePathForAnalysis = Join-Path $destinationPath "Spotify.exe"
|
||||
|
||||
if (Test-Path $dllPath) {
|
||||
Find-BuildInfo -Path $dllPath
|
||||
} elseif (Test-Path $exePathForAnalysis) {
|
||||
Find-BuildInfo -Path $exePathForAnalysis
|
||||
}
|
||||
else {
|
||||
Write-Error "Файлы Spotify.dll и Spotify.exe не найдены в $destinationPath"
|
||||
"build_type=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error "Произошла ошибка: $_"
|
||||
"build_type=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (-not [string]::IsNullOrEmpty($Url)) {
|
||||
Download-And-Unpack-Spotify
|
||||
} else {
|
||||
Write-Error "URL не был предоставлен."
|
||||
"build_type=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
|
||||
}
|
||||
Loading…
Reference in a new issue