Skip to content

Commit

Permalink
RCAT-376 : push branch changed wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mayur-sose committed Dec 11, 2024
1 parent 33dc828 commit 464532f
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions .github/update_packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ function get_latest_version($packageName) {
}

return NULL;
} catch (RequestException $e) {
echo "Package {$packageName} not found on Packagist. Trying Drupal.org...\n";
}
catch (RequestException $e) {
// echo "Package {$packageName} not found on Packagist. Trying Drupal.org...\n";
return get_latest_version_from_drupal_org($packageName);
}
}
Expand All @@ -57,7 +58,8 @@ function get_latest_version($packageName) {
*/
function get_latest_version_from_drupal_org($packageName) {
$client = new Client();
$packageName = str_replace('drupal/', '', $packageName); // Remove "drupal/" prefix
// Remove "drupal/" prefix
$packageName = str_replace('drupal/', '', $packageName);
$drupalApiUrl = "https://www.drupal.org/api-d7/node.json?field_project_machine_name={$packageName}";

try {
Expand All @@ -70,14 +72,15 @@ function get_latest_version_from_drupal_org($packageName) {

echo "No releases found for {$packageName} on Drupal.org.\n";
return NULL;
} catch (RequestException $e) {
}
catch (RequestException $e) {
echo "Error fetching data for {$packageName} on Drupal.org: " . $e->getMessage() . PHP_EOL;
return NULL;
}
}

/**
* Determines if the latest version is a major update compared to the current version.
* Determines if latest version is a major update compared to current version.
*
* @param string|null $currentVersion
* The current version.
Expand Down Expand Up @@ -108,7 +111,7 @@ function update_packages_yaml($filePath) {
$fileLines = file($filePath);
$comments = [];

// Extract comments
// Extract comments.
foreach ($fileLines as $line) {
if (preg_match('/^\s*#/', $line)) {
$comments[] = $line;
Expand All @@ -128,11 +131,13 @@ function update_packages_yaml($filePath) {
$details['core_matrix']['*']['version'] = $latestVersion;
echo "Updated $package for '*' to version $latestVersion.\n";
}
} else {
}
else {
echo "Skipping $package as '*' is not defined in core_matrix.\n";
}
} else {
// Update non-core_matrix packages
}
else {
// Update non-core_matrix packages.
$currentVersion = $details['version'] ?? NULL;
$latestVersion = get_latest_version($package);

Expand All @@ -143,11 +148,11 @@ function update_packages_yaml($filePath) {
}
}

// Write back the YAML, appending the comments
// Write back the YAML, appending the comments.
file_put_contents($filePath, implode('', $comments) . "\n" . Yaml::dump($packages, 2));
}

// File path to the YAML configuration
// File path to the YAML configuration.
$filePath = '../config/packages.yml';

update_packages_yaml($filePath);

0 comments on commit 464532f

Please sign in to comment.