From 187fc4d4396b294e06b9c5d2fd0082f4ed84f8f1 Mon Sep 17 00:00:00 2001 From: amd64fox <62529699+amd64fox@users.noreply.github.com> Date: Fri, 14 Nov 2025 05:24:03 +0300 Subject: [PATCH] refactor build info extraction to new script --- .github/workflows/version-check.yml | 46 +-------- check-build-version.ps1 | 140 ++++++++++++++++++++++++++++ get-build-info.ps1 | 93 ------------------ 3 files changed, 144 insertions(+), 135 deletions(-) create mode 100644 check-build-version.ps1 delete mode 100644 get-build-info.ps1 diff --git a/.github/workflows/version-check.yml b/.github/workflows/version-check.yml index 4be4dfe..7d6a140 100644 --- a/.github/workflows/version-check.yml +++ b/.github/workflows/version-check.yml @@ -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 - } \ No newline at end of file + ./check-build-version.ps1 -versions "$env:VERSIONS" -source "$env:SOURCE" -googleAppsUrl "$env:GOOGLE_APPS_URL" \ No newline at end of file diff --git a/check-build-version.ps1 b/check-build-version.ps1 new file mode 100644 index 0000000..08c84dd --- /dev/null +++ b/check-build-version.ps1 @@ -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 + } + } +} \ No newline at end of file diff --git a/get-build-info.ps1 b/get-build-info.ps1 deleted file mode 100644 index 16acf78..0000000 --- a/get-build-info.ps1 +++ /dev/null @@ -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 -} \ No newline at end of file