Skip to content

Commit

Permalink
Merge pull request #668 from PrestaShop/dev
Browse files Browse the repository at this point in the history
Release version 5.0.1
  • Loading branch information
Hlavtox committed Feb 27, 2024
2 parents 5b59ba4 + 6f57bd0 commit 1e2754a
Show file tree
Hide file tree
Showing 29 changed files with 338 additions and 136 deletions.
5 changes: 2 additions & 3 deletions .github/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ runs:
- name: Build docker compose stack
env:
VERSION: ${{ matrix.from }}
BASE_VERSION: ${{ startsWith(matrix.from, '1.6') && '7.1-apache' || startsWith(matrix.from, '8.1') && '8.1-apache' || startsWith(matrix.from, '8.0') && '8.1-apache' || '7.2-apache' }}
shell: bash
run: |
bash -c 'if [[ "${VERSION}" == 1.6* ]]; then export BASE_VERSION=7.1-apache; \
elif [[ "${VERSION}" == 8.* ]]; then export BASE_VERSION=8.1-apache; \
else export BASE_VERSION=7.2-apache; fi && docker compose up -d'
docker compose up -d
bash -c 'while [[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/index.php)" != "200" ]]; do sleep 5; done'
- name: Copy autoupgrade module
shell: bash
Expand Down
183 changes: 107 additions & 76 deletions .github/get_results.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,58 +11,75 @@
$results[] = getTestResultFromFile($file);
}
$globalResults = getGlobalResults($results, $psBranch);
$totalDuration = getTotalDuration($globalResults);
$totalDuration = getTotalDuration($globalResults, $results[0]['branch']);

$data = [
'stats' => [
'start' => getDateStart($globalResults)->format('Y-m-d H:i:s'),
'end' => getDateEnd($globalResults)->format('Y-m-d H:i:s'),
'duration' => $totalDuration,
'skipped' => 0,
'pending' => 0,
'passes' => getPasses($globalResults),
'failures' => getFailures($globalResults),
'suites' => 1,
'tests' => count($results),
],
'suites' => [
'uuid' => uniqid(),
'title' => 'Upgrade to branch ' . $psBranch,
'file' => '',
'passes' => getPasses($globalResults),
'pending' => 0,
'failures' => getFailures($globalResults),
'testsRegistered' => count($results),
//passPercent
//pendingPercent
'other' => 0,
'hasOther' => 0,
'skipped' => 0,
'hasSkipped' => 0,
'start' => getDateStart($results)->format(\DateTime::RFC3339_EXTENDED),
'end' => getDateEnd($globalResults)->format(\DateTime::RFC3339_EXTENDED),
'duration' => $totalDuration,
'hasSkipped' => false,
'hasPending' => false,
'hasPasses' => getPasses($globalResults) > 0,
'hasFailures' => getFailures($globalResults) > 0,
'totalSkipped' => 0,
'totalPending' => 0,
'totalPasses' => getPasses($globalResults),
'totalFailures' => getFailures($globalResults),
'hasSuites' => true,
'hasTests' => false,
'tests' => [],
'suites' => [],
],
'results' => [],
];

foreach ($globalResults as $globalResult) {
$data['suites']['suites'][] = [
'uuid' => uniqid(),
'title' => $globalResult['title'],
$suiteTestsPasses = $suiteTestsFailures = $suiteTestsPending = $suiteTestsSkipped = [];
foreach($globalResult['tests'] as $test) {
if ($test['pass']) {
$suiteTestsPasses[] = $test['uuid'];
continue;
}
if ($test['fail']) {
$suiteTestsFailures[] = $test['uuid'];
continue;
}
if ($test['pending']) {
$suiteTestsPending[] = $test['uuid'];
continue;
}
}

$data['results'][] = [
'uuid' => $globalResult['uuid'],
'title' => 'Upgrade to branch ' . $psBranch,
'fullFile' => '',
'file' => '',
'duration' => $globalResult['duration'],
'hasSkipped' => false,
'hasPending' => false,
'hasPasses' => $globalResult['passes'] > 0,
'hasFailures' => $globalResult['failures'] > 0,
'totalSkipped' => 0,
'totalPending' => 0,
'totalPasses' => $globalResult['passes'],
'totalFailures' => $globalResult['failures'],
'hasSuites' => false,
'hasTests' => true,
'suites' => [],
'tests' => $globalResult['tests'],
'tests' => [],
'suites' => [
[
'uuid' => $globalResult['uuid'],
'title' => $globalResult['title'],
'file' => '',
'tests' => $globalResult['tests'],
'suites' => [],
'passes' => $suiteTestsPasses,
'failures' => $suiteTestsFailures,
'pending' => $suiteTestsPending,
'skipped' => $suiteTestsSkipped,
'duration' => $globalResult['duration'],
'root' => false,
'rootEmpty' => false,
],
],
'passes' => [],
'failures' => [],
'pending' => [],
'skipped' => [],
'duration' => $data['stats']['duration'],
'root' => true,
'rootEmpty' => true,
];
}

Expand Down Expand Up @@ -105,17 +122,19 @@ function getTestResultFromFile(string $file): array
}

return [
'uuid' => uniqid(),
'title' => '[' . $branch . '] Upgrade from ' . $data[1] . ' to ' . $data[2],
'context' => '{"value": "[' . $branch . '] Upgrade from ' . $data[1] . ' to ' . $data[2] . '"}',
'skipped' => [],
'pending' => [],
'duration' => $duration,
'state' => $state,
'pass' => $state === 'passed',
'fail' => $state === 'failed',
'pending' => false,
'context' => '{"title": "testIdentifier","value": "[' . $branch . '] Upgrade from ' . $data[1] . ' to ' . $data[2] . '"}',
'err' => $error,
'uuid' => uniqid(),
'skipped' => false,
'branch' => $branch,
'date_start' => $dateStart,
'date_end' => $dateEnd,
'branch' => $branch
];
}

Expand All @@ -129,25 +148,43 @@ function getGlobalResults(array $results, string $psBranch): array
$globalResults = [];

foreach ($results as $result) {
if (!isset($globalResults[$result['branch']])) {
$globalResults[$result['branch']] = [
'title' => '[' . $result['branch'] . '] Upgrade to branch ' . $psBranch,
$resultBranch = $result['branch'];
if (!isset($globalResults[$resultBranch])) {
$globalResults[$resultBranch] = [
'uuid' => uniqid(),
'title' => '[' . $resultBranch . '] Upgrade to branch ' . $psBranch,
'tests' => [],
'date_start' => null,
'date_end' => null,
'duration' => 0,
'passes' => 0,
'failures' => 0,
];
}
if (null === $globalResults[$result['branch']]['date_start'] || $result['date_start'] < $globalResults[$result['branch']]['date_start']) {
$globalResults[$result['branch']]['date_start'] = $result['date_start'];
if (null === $globalResults[$resultBranch]['date_start']
|| $result['date_start'] < $globalResults[$resultBranch]['date_start']) {
$globalResults[$resultBranch]['date_start'] = $result['date_start'];
}
if (null === $globalResults[$result['branch']]['date_end'] || $result['date_end'] > $globalResults[$result['branch']]['date_end']) {
$globalResults[$result['branch']]['date_end'] = $result['date_end'];
if (null === $globalResults[$resultBranch]['date_end']
|| $result['date_end'] > $globalResults[$resultBranch]['date_end']) {
$globalResults[$resultBranch]['date_end'] = $result['date_end'];
}
$globalResults[$result['branch']]['passes'] += $result['state'] === 'passed' ? 1 : 0;
$globalResults[$result['branch']]['failures'] += $result['state'] !== 'passed' ? 1 : 0;
$globalResults[$result['branch']]['tests'][] = $result;
$globalResults[$resultBranch]['passes'] += $result['state'] === 'passed' ? 1 : 0;
$globalResults[$resultBranch]['failures'] += $result['state'] !== 'passed' ? 1 : 0;
$globalResults[$resultBranch]['tests'][] = [
'title' => $result['title'],
'fullTitle' => $result['title'],
'timedOut' => false,
'duration' => $result['duration'],
'state' => $result['state'],
'pass' => $result['state'] === 'passed',
'fail' => $result['state'] === 'failed',
'pending' => $result['state'] === 'pending',
'context' => $result['context'],
'uuid' => $result['uuid'],
'parentUUID' => $globalResults[$resultBranch]['uuid'],
'isHook' => false,
'skipped' => $result['state'] === 'skipped',
];
}

foreach ($globalResults as &$globalResult) {
Expand All @@ -157,24 +194,24 @@ function getGlobalResults(array $results, string $psBranch): array
return $globalResults;
}

function getDateStart(array $globalResults): DateTime {
function getDateStart(array $results): DateTime {
$dateStart = null;

foreach ($globalResults as $globalResult) {
if (null === $dateStart || $globalResult['date_start'] < $dateStart) {
$dateStart = $globalResult['date_start'];
foreach ($results as $result) {
if (null === $dateStart || $result['date_start'] < $dateStart) {
$dateStart = $result['date_start'];
}
}

return $dateStart;
}

function getDateEnd(array $globalResults): DateTime {
function getDateEnd(array $results): DateTime {
$dateEnd = null;

foreach ($globalResults as $globalResult) {
if (null === $dateEnd || $globalResult['date_end'] < $dateEnd) {
$dateEnd = $globalResult['date_end'];
foreach ($results as $result) {
if (null === $dateEnd || $result['date_end'] < $dateEnd) {
$dateEnd = $result['date_end'];
}
}

Expand All @@ -201,18 +238,12 @@ function getFailures(array $globalResults): int {
return $failures;
}

function getTotalDuration(array $results): int {
$dateStart = null;
$dateEnd = null;
function getTotalDuration(array $results, string $branch): int {
$duration = 0;

foreach ($results as $result) {
if (null === $dateStart || $result['date_start'] < $dateStart) {
$dateStart = $result['date_start'];
}
if (null === $dateEnd || $result['date_end'] > $dateEnd) {
$dateEnd = $result['date_end'];
}
foreach ($results[$branch]['tests'] as $result) {
$duration += $result['duration'];
}

return ($dateEnd->getTimestamp() - $dateStart->getTimestamp()) * 1000;
return $duration;
}
2 changes: 1 addition & 1 deletion .github/workflows/nightly_upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ jobs:
export FILENAME=autoupgrade_`date -u +"%Y-%m-%d"`-${{matrix.ps-versions.branch}}.json
./.github/workflows/nightly_scripts/push_results.sh ${{ env.nightly_api_url }} $FILENAME ${{ env.campaign }} ${{ env.platform }} ${{ secrets.QANB_TOKEN }}
env:
nightly_api_url: https://api-nightly.prestashop-project.org/hook/add
nightly_api_url: https://api-nightly.prestashop-project.org/hook/reports/import
campaign: autoupgrade
platform: cli
3 changes: 3 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: PHP tests
on: [push, pull_request]
concurrency:
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
# Check there is no syntax errors in the project
php-linter:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/upgrade.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: Upgrades
on: [push, pull_request]
concurrency:
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
upgrade:
strategy:
matrix:
from: ['1.7.6.9', '1.7.6.1', '1.7.7.0']
from: ['1.7.6.9', '1.7.6.1', '1.7.7.0', '8.0.0', '8.1.0']
ps-versions:
- channel: minor
- channel: major
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ nbproject
/config_*.xml
.php_cs.cache
.idea

## QA Nightly
/artifacts
/autoupgrade*.json
5 changes: 4 additions & 1 deletion AdminSelfUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
use PrestaShop\Module\AutoUpgrade\UpgradeSelfCheck;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\FilesystemAdapter;

require_once _PS_ROOT_DIR_ . '/modules/autoupgrade/vendor/autoload.php';
$autoloadPath = __DIR__ . '/vendor/autoload.php';
if (file_exists($autoloadPath)) {
require_once $autoloadPath;
}

class AdminSelfUpgrade extends AdminController
{
Expand Down
12 changes: 10 additions & 2 deletions autoupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct()
$this->name = 'autoupgrade';
$this->tab = 'administration';
$this->author = 'PrestaShop';
$this->version = '5.0.0';
$this->version = '5.0.1';
$this->need_instance = 1;

$this->bootstrap = true;
Expand Down Expand Up @@ -123,7 +123,15 @@ public function uninstall()
*/
public function registerHookAndSetToTop($hookName)
{
return $this->registerHook($hookName) && $this->updatePosition((int) Hook::getIdByName($hookName), false);
if (!$this->registerHook($hookName)) {
return false;
}

// Updating position is not blocking for installation esepcially since this method returns false when no other
// module is hooked, which doesn't mean the module can't work as expected.
$this->updatePosition((int) Hook::getIdByName($hookName), false);

return true;
}

public function hookDashboardZoneOne($params)
Expand Down
7 changes: 4 additions & 3 deletions classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ protected function getPreUpgradeVersion()

/**
* Add missing levels in version.
* Example: 1.7 will become 1.7.0.0.
* Example: 1.7 will become 1.7.0.0 and 8.1 will become 8.1.0.
*
* @param string $version
*
Expand All @@ -245,8 +245,9 @@ protected function getPreUpgradeVersion()
public function normalizeVersion($version)
{
$arrayVersion = explode('.', $version);
if (count($arrayVersion) < 4) {
$arrayVersion = array_pad($arrayVersion, 4, '0');
$versionLevels = 1 == $arrayVersion[0] ? 4 : 3;
if (count($arrayVersion) < $versionLevels) {
$arrayVersion = array_pad($arrayVersion, $versionLevels, '0');
}

return implode('.', $arrayVersion);
Expand Down
1 change: 1 addition & 0 deletions classes/UpgradeTools/ModuleAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public function upgradeModule($id, $name, $isLocalModule = false)
$filesystem = new Filesystem();
$filesystem->copy($local_module_zip, $zip_fullpath);
$local_module_used = true;
unlink($local_module_zip);
}
} catch (IOException $e) {
// Do nothing, we will try to upgrade module from addons
Expand Down
3 changes: 0 additions & 3 deletions classes/UpgradeTools/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@ public function mergeTranslationFile($orig, $dest, $type)
}
fwrite($fd, "<?php\n\nglobal \$" . $var_name . ";\n\$" . $var_name . " = array();\n");
foreach ($merge as $k => $v) {
if (get_magic_quotes_gpc()) {
$v = stripslashes($v);
}
if ('mail' == $type) {
fwrite($fd, '$' . $var_name . '[\'' . $this->escape($k) . '\'] = \'' . $this->escape($v) . '\';' . "\n");
} else {
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>autoupgrade</name>
<displayName><![CDATA[1-Click Upgrade]]></displayName>
<version><![CDATA[5.0.0]]></version>
<version><![CDATA[5.0.1]]></version>
<description><![CDATA[Upgrade to the latest version of PrestaShop in a few clicks, thanks to this automated method.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[administration]]></tab>
Expand Down

0 comments on commit 1e2754a

Please sign in to comment.