added build type processing

This commit is contained in:
amd64fox 2025-11-14 00:17:15 +03:00
parent 31eeb1d86d
commit 86d02dde3c
3 changed files with 176 additions and 94 deletions

View file

@ -8,9 +8,10 @@ concurrency:
cancel-in-progress: false
jobs:
build:
version-search:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.search.outputs.versions }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
@ -23,9 +24,72 @@ jobs:
chmod +x loaderspot_cli
- name: Version search
id: search
if: github.event.client_payload.v && github.event.client_payload.s
env:
v: ${{ github.event.client_payload.v }}
s: ${{ github.event.client_payload.s }}
run: |
json_output=$(./loaderspot_cli --version "$v" --connections 300 --ladder-search)
echo "versions=$json_output" >> $GITHUB_OUTPUT
get-build-type:
runs-on: windows-latest
needs: version-search
if: success() && needs.version-search.outputs.versions
continue-on-error: true
outputs:
build_type: ${{ steps.get_build_type.outputs.build_type }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Get Win64 URL and determine build type
id: get_build_type
shell: pwsh
run: |
$versionsJson = '${{ needs.version-search.outputs.versions }}' | ConvertFrom-Json
$win64Url = $versionsJson.WIN64
if ($win64Url) {
./get-build-info.ps1 -Url $win64Url
} else {
echo "::set-output name=build_type::false"
}
send-to-gas:
runs-on: ubuntu-latest
needs: [version-search, get-build-type]
if: success() && needs.version-search.outputs.versions
steps:
- name: Send data to Google Apps Script
env:
g: ${{ secrets.GOOGLE_APPS_URL }}
run: ./loaderspot_cli --version "$v" --source "$s" --gas-url "$g" --connections 300
versions: ${{ needs.version-search.outputs.versions }}
build_type: ${{ needs.get-build-type.outputs.build_type }}
source: ${{ github.event.client_payload.s }}
run: |
if [ -z "$versions" ]; then
echo "Versions data is empty. Skipping."
exit 0
fi
if [ "$build_type" = "false" ]; then
final_json=$(echo "$versions" | jq \
--argjson buildType false \
--arg source "$source" \
'. + {buildType: $buildType, source: $source}')
else
final_json=$(echo "$versions" | jq \
--arg buildType "$build_type" \
--arg source "$source" \
'. + {buildType: $buildType, source: $source}')
fi
response=$(curl -s -L -X POST "$g" -H "Content-Type: application/json" --data-raw "$final_json")
if echo "$response" | grep -q "text-align:center"; then
clean_response=$(echo "$response" | grep "text-align:center" | sed 's/<[^>]*>//g' | xargs)
echo "Ответ от GAS: $clean_response"
else
echo "Ответ от GAS: $response"
fi

View file

@ -7,7 +7,6 @@ use std::sync::Arc;
use std::time::Duration;
use tokio::sync::Semaphore;
use regex::Regex;
use scraper::{Html, Selector};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
enum PlatformArch {
@ -149,13 +148,9 @@ struct Cli {
#[clap(long, default_value_t = 100)]
connections: usize,
/// URL to send the found versions to (Google Apps Script)
/// Use ladder search algorithm
#[clap(long)]
gas_url: Option<String>,
/// Source of the version
#[clap(long)]
source: Option<String>,
ladder_search: bool,
}
fn parse_range(range_str: &str) -> (i32, i32) {
@ -233,8 +228,7 @@ async fn main() {
let version_clone = cli.version.clone();
let client_clone = client.clone();
let gas_url_clone = cli.gas_url.clone();
let source_clone = cli.source.clone();
let ladder_search = cli.ladder_search;
let search_task = tokio::spawn(async move {
let mut all_found_urls = Vec::new();
@ -249,7 +243,7 @@ async fn main() {
arches_to_search.retain(|&p| p != PlatformArch::WinX86);
}
if gas_url_clone.is_some() && source_clone.is_some() {
if ladder_search {
// "Лесенка"
let mut start_number = 0;
let mut before_enter = 1000;
@ -264,10 +258,10 @@ async fn main() {
// Дополнительные поиски
for _ in 0..additional_searches {
let latest_urls = get_latest_urls(&all_found_urls, &[version.to_string()], source_clone.as_deref().unwrap_or(""));
let latest_urls = get_latest_urls(&all_found_urls);
let target_len = arches_to_search.iter().filter(|&&p| p != PlatformArch::WinX86 || should_use_win_x86(version)).count();
if latest_urls.len() >= target_len + 2 { // +2 for version and source
if latest_urls.len() >= target_len {
break;
}
@ -302,33 +296,16 @@ async fn main() {
pb.finish_and_clear();
match (&cli.gas_url, &cli.source) {
(Some(gas_url), Some(source)) => {
let latest_urls = get_latest_urls(&all_found_urls, &cli.version, source);
send_to_gas(client, gas_url, latest_urls).await;
}
(Some(_), None) => {
eprintln!("Warning: --gas-url is provided, but --source is missing. Skipping sending to GAS.");
let json_output = serde_json::to_string_pretty(&all_found_urls).unwrap();
println!("{}", json_output);
}
(None, Some(_)) => {
eprintln!("Warning: --source is provided, but --gas-url is missing. Skipping sending to GAS.");
let json_output = serde_json::to_string_pretty(&all_found_urls).unwrap();
println!("{}", json_output);
}
(None, None) => {
let json_output = serde_json::to_string_pretty(&all_found_urls).unwrap();
println!("{}", json_output);
}
let mut latest_urls = get_latest_urls(&all_found_urls);
if !cli.version.is_empty() {
latest_urls.insert("version".to_string(), cli.version.join(", "));
}
let json_output = serde_json::to_string_pretty(&latest_urls).unwrap();
println!("{}", json_output);
}
fn get_latest_urls(
found_urls: &[(String, PlatformArch)],
versions: &[String],
source: &str,
) -> HashMap<String, String> {
fn get_latest_urls(found_urls: &[(String, PlatformArch)]) -> HashMap<String, String> {
let mut platform_urls = HashMap::new();
let version_pattern = Regex::new(r"-(\d+)\.(exe|tbz)$").unwrap();
@ -347,70 +324,16 @@ fn get_latest_urls(
}
}
let mut latest_urls: HashMap<String, String> = platform_urls
let latest_urls: HashMap<String, String> = platform_urls
.into_iter()
.map(|(k, (v, _))| (k, v))
.collect();
if !versions.is_empty() {
latest_urls.insert("version".to_string(), versions.join(", "));
}
latest_urls.insert("source".to_string(), source.to_string());
if latest_urls.is_empty() {
let mut empty_map = HashMap::new();
empty_map.insert("unknown".to_string(), "unknown".to_string());
if !versions.is_empty() {
empty_map.insert("version".to_string(), versions.join(", "));
}
empty_map.insert("source".to_string(), source.to_string());
return empty_map;
}
latest_urls
}
async fn send_to_gas(
client: Client,
gas_url: &str,
data: HashMap<String, String>,
) {
const GAS_ERROR_PREFIX: &str = "Ошибка при отправке в GAS:";
let cleaned_gas_url = gas_url.trim_matches('"');
match client.post(cleaned_gas_url).json(&data).send().await {
Ok(response) => {
if response.status().is_success() {
match response.text().await {
Ok(text) => {
if text.contains("<div") {
let soup = Html::parse_document(&text);
let selector = Selector::parse("div[style*='text-align:center']").unwrap();
if let Some(div) = soup.select(&selector).next() {
println!("Ответ от GAS: {}", div.text().collect::<String>().trim());
} else {
eprintln!("Не удалось извлечь ответ из HTML. Полный ответ:");
eprintln!("{}", text);
}
} else {
println!("Ответ от GAS: {}", text.trim());
}
}
Err(e) => eprintln!("Ошибка чтения ответа от GAS: {}", e),
}
} else {
eprintln!("{} {}", GAS_ERROR_PREFIX, response.status());
}
}
Err(e) => {
let error_message = e.to_string();
if let Some(index) = error_message.find(" for url (") {
eprintln!("{} {}", GAS_ERROR_PREFIX, &error_message[..index]);
} else {
eprintln!("{} {}", GAS_ERROR_PREFIX, error_message);
}
}
}
}

95
get-build-info.ps1 Normal file
View file

@ -0,0 +1,95 @@
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
# Выводим тип билда в специальном формате для GitHub Actions
echo "::set-output name=build_type::$buildType"
# Прерываем цикл после первого найденного совпадения
break
}
}
if (-not $found) {
Write-Output "Билд не найден"
echo "::set-output name=build_type::false"
}
}
catch {
Write-Error "Ошибка при чтении файла: $_"
echo "::set-output name=build_type::false"
}
}
}
function Download-And-Unpack-Spotify {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[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) {
Find-BuildInfo -Path $dllPath
} elseif (Test-Path $exePathForAnalysis) {
Find-BuildInfo -Path $exePathForAnalysis
}
else {
Write-Error "Файлы Spotify.dll и Spotify.exe не найдены в $destinationPath"
echo "::set-output name=build_type::false"
}
}
catch {
Write-Error "Произошла ошибка: $_"
echo "::set-output name=build_type::false"
}
}
param (
[string]$Url
)
if (-not [string]::IsNullOrEmpty($Url)) {
Download-And-Unpack-Spotify -Url $Url
} else {
Write-Error "URL не был предоставлен."
echo "::set-output name=build_type::false"
}