Skip to content

Commit

Permalink
Merge pull request #276 from doofinder/pedro/763-fix-magento-github-a…
Browse files Browse the repository at this point in the history
…ctions

Modified MagentoReleaseClient to retry the release when malware analysis is still in progress
  • Loading branch information
pedromcp90 committed Jun 2, 2023
2 parents d00fede + f7e49e7 commit fa41040
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/scripts/magento-release.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
class MagentoReleaseClient
{
const API_PATH = 'https://developer-api.magento.com/rest/v1';
const MAX_RETRIES = 3;
const RETRY_AFTER = 30;
private $version;
private $release_notes;
private $ust;
private $app_id;
private $app_secret;
private $files;
private $retries = 0;

/**
* Create a MagentoReleaseClient
Expand All @@ -27,8 +31,8 @@ public function __construct($version, $release_notes, $app_id, $app_secret)
$this->app_secret = $app_secret;
$this->version = $version;
$this->release_notes = $this->process_release_notes($release_notes);

$this->obtain_ust();
$this->files = $this->upload_files();
}

/**
Expand Down Expand Up @@ -161,9 +165,12 @@ public function create_release()
"Authorization: Bearer " . $this->ust,
"Content-Type: application/json"
];
$files = $this->upload_files();
//Sleep 20S to allow time for files to be verified by malware scanner
sleep(20);

echo "Create Release\n";

//Sleep a few seconds to allow time for files to be verified by malware scanner
sleep(self::RETRY_AFTER);

$payload = [
[
"sku" => "doofinder/doofinder-magento2",
Expand All @@ -187,17 +194,16 @@ public function create_release()
"release_notes" => $this->release_notes,
"version" => $this->version,
"artifact" => [
"file_upload_id" => $files[0]
"file_upload_id" => $this->files[0]
],
"documentation_artifacts" => [
"user" => [
"file_upload_id" => $files[1]
"file_upload_id" => $this->files[1]
]
]
]
];

echo "Create Release\n";
$result = $this->post("/products/packages", json_encode($payload), $headers);
if (!empty($result)) {
$result = reset($result);
Expand All @@ -206,11 +212,15 @@ public function create_release()
if (property_exists($result, 'code')) {
file_put_contents("release_result.txt", $result->code);
if ($result->code === 200) {
file_put_contents("release_result.txt", $result->code);
echo "-------------------------------\n";
echo " Release finished successfully. \n";
echo " - Submission id: {$result->submission_id}\n";
echo "-------------------------------\n";
} elseif ($result->code === 1321 && $this->retries < self::MAX_RETRIES) {
$this->retries++;
echo " Retry {$this->retries}: Malware scan is still in progress, retrying in " . self::RETRY_AFTER ." seconds. \n";
//Retry creating the release to give the API more time to analyse the uploaded file
$this->create_release();
} elseif (property_exists($result, 'message')) {
echo "---------------------------------------------\n";
echo " An error ocurred while creating the release \n";
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "doofinder/doofinder-magento2",
"version": "0.11.0",
"version": "0.11.1",
"description": "Doofinder module for Magento 2",
"type": "magento2-module",
"require": {
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Doofinder_Feed" setup_version="0.11.0">
<module name="Doofinder_Feed" setup_version="0.11.1">
<sequence>
<module name="Magento_Integration" />
</sequence>
Expand Down

0 comments on commit fa41040

Please sign in to comment.